mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-06-21 18:59:27 +08:00
Compare commits
41 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ff21bd2d58 | |||
| 172f1e16bd | |||
| e52890db9e | |||
| dd4bbd13a5 | |||
| ecb488266d | |||
| 756cc0a511 | |||
| dcaec012e2 | |||
| 5782616d03 | |||
| 7dae909398 | |||
| e8a841df59 | |||
| c7b34876bb | |||
| da1e907ad7 | |||
| 8ce7d1dcdd | |||
| b9a9965750 | |||
| 47445fb82f | |||
| c875a14bde | |||
| 58ba3f0665 | |||
| e9693a7cdd | |||
| a6cfc31f7a | |||
| e917b5a666 | |||
| 57d0489e1f | |||
| d64c205796 | |||
| c8f050230d | |||
| a0b037b13e | |||
| 7fd0e52a8b | |||
| 659bbb3802 | |||
| 3c0579b484 | |||
| b11eda66ea | |||
| c117b29f9e | |||
| 01a65512ea | |||
| 531cfdcc3d | |||
| 0b5795551a | |||
| bb0278db72 | |||
| 71e93a71d4 | |||
| 19d66d6bdb | |||
| 72a09f4051 | |||
| a17f35ba63 | |||
| 7b11ddb1d5 | |||
| ecec5912ba | |||
| dcd9bc6b1a | |||
| 976c5c4981 |
@@ -13,20 +13,15 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
# We must fetch at least the immediate parents so that if this is
|
||||
# a pull request then we can checkout the head.
|
||||
fetch-depth: 2
|
||||
|
||||
# If this run was triggered by a pull request event, then checkout
|
||||
# the head of the pull request instead of the merge commit.
|
||||
- run: git checkout HEAD^2
|
||||
if: ${{ github.event_name == 'pull_request' }}
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
uses: github/codeql-action/init@v2
|
||||
# Override language selection by uncommenting this and choosing your languages
|
||||
# with:
|
||||
# languages: go, javascript, csharp, python, cpp, java
|
||||
@@ -34,7 +29,7 @@ jobs:
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v1
|
||||
uses: github/codeql-action/autobuild@v2
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
@@ -48,4 +43,4 @@ jobs:
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
||||
uses: github/codeql-action/analyze@v2
|
||||
|
||||
@@ -11,9 +11,10 @@ on: # rebuild any PRs and main branch changes
|
||||
|
||||
jobs:
|
||||
build: # make sure build/ci works properly
|
||||
name: Run Unit Tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/checkout@v3
|
||||
- run: |
|
||||
npm install
|
||||
npm test
|
||||
|
||||
@@ -128,7 +128,7 @@ Following are the key capabilities of this action:
|
||||
### Basic deployment (without any deployment strategy)
|
||||
|
||||
```yaml
|
||||
- uses: Azure/k8s-deploy@v3.1
|
||||
- uses: Azure/k8s-deploy@v4
|
||||
with:
|
||||
namespace: 'myapp'
|
||||
manifests: |
|
||||
@@ -162,7 +162,7 @@ Following are the key capabilities of this action:
|
||||
### Canary deployment without service mesh
|
||||
|
||||
```yaml
|
||||
- uses: Azure/k8s-deploy@v3.1
|
||||
- uses: Azure/k8s-deploy@v4
|
||||
with:
|
||||
namespace: 'myapp'
|
||||
images: 'contoso.azurecr.io/myapp:${{ event.run_id }}'
|
||||
@@ -181,7 +181,7 @@ Following are the key capabilities of this action:
|
||||
To promote/reject the canary created by the above snippet, the following YAML snippet could be used:
|
||||
|
||||
```yaml
|
||||
- uses: Azure/k8s-deploy@v3.1
|
||||
- uses: Azure/k8s-deploy@v4
|
||||
with:
|
||||
namespace: 'myapp'
|
||||
images: 'contoso.azurecr.io/myapp:${{ event.run_id }}'
|
||||
@@ -199,7 +199,7 @@ To promote/reject the canary created by the above snippet, the following YAML sn
|
||||
### Canary deployment based on Service Mesh Interface
|
||||
|
||||
```yaml
|
||||
- uses: Azure/k8s-deploy@v3.1
|
||||
- uses: Azure/k8s-deploy@v4
|
||||
with:
|
||||
namespace: 'myapp'
|
||||
images: 'contoso.azurecr.io/myapp:${{ event.run_id }}'
|
||||
@@ -220,7 +220,7 @@ To promote/reject the canary created by the above snippet, the following YAML sn
|
||||
To promote/reject the canary created by the above snippet, the following YAML snippet could be used:
|
||||
|
||||
```yaml
|
||||
- uses: Azure/k8s-deploy@v3.1
|
||||
- uses: Azure/k8s-deploy@v4
|
||||
with:
|
||||
namespace: 'myapp'
|
||||
images: 'contoso.azurecr.io/myapp:${{ event.run_id }} '
|
||||
@@ -239,7 +239,7 @@ To promote/reject the canary created by the above snippet, the following YAML sn
|
||||
### Blue-Green deployment with different route methods
|
||||
|
||||
```yaml
|
||||
- uses: Azure/k8s-deploy@v3.1
|
||||
- uses: Azure/k8s-deploy@v4
|
||||
with:
|
||||
namespace: 'myapp'
|
||||
images: 'contoso.azurecr.io/myapp:${{ event.run_id }}'
|
||||
@@ -259,7 +259,7 @@ To promote/reject the canary created by the above snippet, the following YAML sn
|
||||
To promote/reject the green workload created by the above snippet, the following YAML snippet could be used:
|
||||
|
||||
```yaml
|
||||
- uses: Azure/k8s-deploy@v3.1
|
||||
- uses: Azure/k8s-deploy@v4
|
||||
with:
|
||||
namespace: 'myapp'
|
||||
images: 'contoso.azurecr.io/myapp:${{ event.run_id }}'
|
||||
@@ -316,7 +316,7 @@ jobs:
|
||||
container-registry-password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||
secret-name: demo-k8s-secret
|
||||
|
||||
- uses: Azure/k8s-deploy@v3.1
|
||||
- uses: Azure/k8s-deploy@v4
|
||||
with:
|
||||
action: deploy
|
||||
manifests: |
|
||||
@@ -362,7 +362,7 @@ jobs:
|
||||
container-registry-password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||
secret-name: demo-k8s-secret
|
||||
|
||||
- uses: Azure/k8s-deploy@v3.1
|
||||
- uses: Azure/k8s-deploy@v4
|
||||
with:
|
||||
action: deploy
|
||||
manifests: |
|
||||
|
||||
+167
-117
@@ -140,7 +140,6 @@ const file_command_1 = __nccwpck_require__(8466);
|
||||
const utils_1 = __nccwpck_require__(7369);
|
||||
const os = __importStar(__nccwpck_require__(2037));
|
||||
const path = __importStar(__nccwpck_require__(1017));
|
||||
const uuid_1 = __nccwpck_require__(487);
|
||||
const oidc_utils_1 = __nccwpck_require__(7557);
|
||||
/**
|
||||
* The code to exit an action
|
||||
@@ -170,20 +169,9 @@ function exportVariable(name, val) {
|
||||
process.env[name] = convertedVal;
|
||||
const filePath = process.env['GITHUB_ENV'] || '';
|
||||
if (filePath) {
|
||||
const delimiter = `ghadelimiter_${uuid_1.v4()}`;
|
||||
// These should realistically never happen, but just in case someone finds a way to exploit uuid generation let's not allow keys or values that contain the delimiter.
|
||||
if (name.includes(delimiter)) {
|
||||
throw new Error(`Unexpected input: name should not contain the delimiter "${delimiter}"`);
|
||||
}
|
||||
if (convertedVal.includes(delimiter)) {
|
||||
throw new Error(`Unexpected input: value should not contain the delimiter "${delimiter}"`);
|
||||
}
|
||||
const commandValue = `${name}<<${delimiter}${os.EOL}${convertedVal}${os.EOL}${delimiter}`;
|
||||
file_command_1.issueCommand('ENV', commandValue);
|
||||
}
|
||||
else {
|
||||
command_1.issueCommand('set-env', { name }, convertedVal);
|
||||
return file_command_1.issueFileCommand('ENV', file_command_1.prepareKeyValueMessage(name, val));
|
||||
}
|
||||
command_1.issueCommand('set-env', { name }, convertedVal);
|
||||
}
|
||||
exports.exportVariable = exportVariable;
|
||||
/**
|
||||
@@ -201,7 +189,7 @@ exports.setSecret = setSecret;
|
||||
function addPath(inputPath) {
|
||||
const filePath = process.env['GITHUB_PATH'] || '';
|
||||
if (filePath) {
|
||||
file_command_1.issueCommand('PATH', inputPath);
|
||||
file_command_1.issueFileCommand('PATH', inputPath);
|
||||
}
|
||||
else {
|
||||
command_1.issueCommand('add-path', {}, inputPath);
|
||||
@@ -241,7 +229,10 @@ function getMultilineInput(name, options) {
|
||||
const inputs = getInput(name, options)
|
||||
.split('\n')
|
||||
.filter(x => x !== '');
|
||||
return inputs;
|
||||
if (options && options.trimWhitespace === false) {
|
||||
return inputs;
|
||||
}
|
||||
return inputs.map(input => input.trim());
|
||||
}
|
||||
exports.getMultilineInput = getMultilineInput;
|
||||
/**
|
||||
@@ -274,8 +265,12 @@ exports.getBooleanInput = getBooleanInput;
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function setOutput(name, value) {
|
||||
const filePath = process.env['GITHUB_OUTPUT'] || '';
|
||||
if (filePath) {
|
||||
return file_command_1.issueFileCommand('OUTPUT', file_command_1.prepareKeyValueMessage(name, value));
|
||||
}
|
||||
process.stdout.write(os.EOL);
|
||||
command_1.issueCommand('set-output', { name }, value);
|
||||
command_1.issueCommand('set-output', { name }, utils_1.toCommandValue(value));
|
||||
}
|
||||
exports.setOutput = setOutput;
|
||||
/**
|
||||
@@ -404,7 +399,11 @@ exports.group = group;
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function saveState(name, value) {
|
||||
command_1.issueCommand('save-state', { name }, value);
|
||||
const filePath = process.env['GITHUB_STATE'] || '';
|
||||
if (filePath) {
|
||||
return file_command_1.issueFileCommand('STATE', file_command_1.prepareKeyValueMessage(name, value));
|
||||
}
|
||||
command_1.issueCommand('save-state', { name }, utils_1.toCommandValue(value));
|
||||
}
|
||||
exports.saveState = saveState;
|
||||
/**
|
||||
@@ -470,13 +469,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.issueCommand = void 0;
|
||||
exports.prepareKeyValueMessage = exports.issueFileCommand = void 0;
|
||||
// We use any as a valid input type
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
const fs = __importStar(__nccwpck_require__(7147));
|
||||
const os = __importStar(__nccwpck_require__(2037));
|
||||
const uuid_1 = __nccwpck_require__(487);
|
||||
const utils_1 = __nccwpck_require__(7369);
|
||||
function issueCommand(command, message) {
|
||||
function issueFileCommand(command, message) {
|
||||
const filePath = process.env[`GITHUB_${command}`];
|
||||
if (!filePath) {
|
||||
throw new Error(`Unable to find environment variable for file command ${command}`);
|
||||
@@ -488,7 +488,22 @@ function issueCommand(command, message) {
|
||||
encoding: 'utf8'
|
||||
});
|
||||
}
|
||||
exports.issueCommand = issueCommand;
|
||||
exports.issueFileCommand = issueFileCommand;
|
||||
function prepareKeyValueMessage(key, value) {
|
||||
const delimiter = `ghadelimiter_${uuid_1.v4()}`;
|
||||
const convertedValue = utils_1.toCommandValue(value);
|
||||
// These should realistically never happen, but just in case someone finds a
|
||||
// way to exploit uuid generation let's not allow keys or values that contain
|
||||
// the delimiter.
|
||||
if (key.includes(delimiter)) {
|
||||
throw new Error(`Unexpected input: name should not contain the delimiter "${delimiter}"`);
|
||||
}
|
||||
if (convertedValue.includes(delimiter)) {
|
||||
throw new Error(`Unexpected input: value should not contain the delimiter "${delimiter}"`);
|
||||
}
|
||||
return `${key}<<${delimiter}${os.EOL}${convertedValue}${os.EOL}${delimiter}`;
|
||||
}
|
||||
exports.prepareKeyValueMessage = prepareKeyValueMessage;
|
||||
//# sourceMappingURL=file-command.js.map
|
||||
|
||||
/***/ }),
|
||||
@@ -20195,7 +20210,7 @@ function deploy(kubectl, manifestFilePaths, deploymentStrategy) {
|
||||
KubernetesConstants.DiscoveryAndLoadBalancerResource.INGRESS
|
||||
]);
|
||||
for (const ingressResource of ingressResources) {
|
||||
yield kubectl.getResource(KubernetesConstants.DiscoveryAndLoadBalancerResource.INGRESS, ingressResource.name);
|
||||
yield kubectl.getResource(KubernetesConstants.DiscoveryAndLoadBalancerResource.INGRESS, ingressResource.name, false, ingressResource.namespace);
|
||||
}
|
||||
core.endGroup();
|
||||
// annotate resources
|
||||
@@ -20578,7 +20593,8 @@ function deleteGreenObjects(kubectl, toDelete) {
|
||||
const resourcesToDelete = toDelete.map((obj) => {
|
||||
return {
|
||||
name: getBlueGreenResourceName(obj.metadata.name, exports.GREEN_SUFFIX),
|
||||
kind: obj.kind
|
||||
kind: obj.kind,
|
||||
namespace: obj.metadata.namespace
|
||||
};
|
||||
});
|
||||
core.debug(`deleting green objects: ${JSON.stringify(resourcesToDelete)}`);
|
||||
@@ -20605,28 +20621,24 @@ exports.deleteObjects = deleteObjects;
|
||||
// other common functions
|
||||
function getManifestObjects(filePaths) {
|
||||
const deploymentEntityList = [];
|
||||
const serviceEntityList = [];
|
||||
const routedServiceEntityList = [];
|
||||
const unroutedServiceEntityList = [];
|
||||
const ingressEntityList = [];
|
||||
const otherEntitiesList = [];
|
||||
const serviceNameMap = new Map();
|
||||
// Manifest objects per type. All resources should be parsed and
|
||||
// organized before we can check if services are “routed” or not.
|
||||
filePaths.forEach((filePath) => {
|
||||
const fileContents = fs.readFileSync(filePath).toString();
|
||||
yaml.safeLoadAll(fileContents, (inputObject) => {
|
||||
if (!!inputObject) {
|
||||
const kind = inputObject.kind;
|
||||
const name = inputObject.metadata.name;
|
||||
if (kubernetesTypes_1.isDeploymentEntity(kind)) {
|
||||
deploymentEntityList.push(inputObject);
|
||||
}
|
||||
else if (kubernetesTypes_1.isServiceEntity(kind)) {
|
||||
if (isServiceRouted(inputObject, deploymentEntityList)) {
|
||||
routedServiceEntityList.push(inputObject);
|
||||
serviceNameMap.set(name, getBlueGreenResourceName(name, exports.GREEN_SUFFIX));
|
||||
}
|
||||
else {
|
||||
unroutedServiceEntityList.push(inputObject);
|
||||
}
|
||||
serviceEntityList.push(inputObject);
|
||||
}
|
||||
else if (kubernetesTypes_1.isIngressEntity(kind)) {
|
||||
ingressEntityList.push(inputObject);
|
||||
@@ -20637,6 +20649,16 @@ function getManifestObjects(filePaths) {
|
||||
}
|
||||
});
|
||||
});
|
||||
serviceEntityList.forEach((inputObject) => {
|
||||
if (isServiceRouted(inputObject, deploymentEntityList)) {
|
||||
const name = inputObject.metadata.name;
|
||||
routedServiceEntityList.push(inputObject);
|
||||
serviceNameMap.set(name, getBlueGreenResourceName(name, exports.GREEN_SUFFIX));
|
||||
}
|
||||
else {
|
||||
unroutedServiceEntityList.push(inputObject);
|
||||
}
|
||||
});
|
||||
return {
|
||||
serviceEntityList: routedServiceEntityList,
|
||||
serviceNameMap: serviceNameMap,
|
||||
@@ -20731,9 +20753,9 @@ function isServiceSelectorSubsetOfMatchLabel(serviceSelector, matchLabels) {
|
||||
return isMatch;
|
||||
}
|
||||
exports.isServiceSelectorSubsetOfMatchLabel = isServiceSelectorSubsetOfMatchLabel;
|
||||
function fetchResource(kubectl, kind, name) {
|
||||
function fetchResource(kubectl, kind, name, namespace) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const result = yield kubectl.getResource(kind, name);
|
||||
const result = yield kubectl.getResource(kind, name, false, namespace);
|
||||
if (result == null || !!result.stderr) {
|
||||
return null;
|
||||
}
|
||||
@@ -20933,16 +20955,16 @@ function isIngressRouted(ingressObject, serviceNameMap) {
|
||||
}
|
||||
exports.isIngressRouted = isIngressRouted;
|
||||
function validateIngresses(kubectl, ingressEntityList, serviceNameMap) {
|
||||
var _a;
|
||||
var _a, _b;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let areValid = true;
|
||||
const invalidIngresses = [];
|
||||
for (const inputObject of ingressEntityList) {
|
||||
if (isIngressRouted(inputObject, serviceNameMap)) {
|
||||
//querying existing ingress
|
||||
const existingIngress = yield blueGreenHelper_1.fetchResource(kubectl, inputObject.kind, inputObject.metadata.name);
|
||||
const existingIngress = yield blueGreenHelper_1.fetchResource(kubectl, inputObject.kind, inputObject.metadata.name, (_a = inputObject === null || inputObject === void 0 ? void 0 : inputObject.metadata) === null || _a === void 0 ? void 0 : _a.namespace);
|
||||
const isValid = !!existingIngress &&
|
||||
((_a = existingIngress === null || existingIngress === void 0 ? void 0 : existingIngress.metadata) === null || _a === void 0 ? void 0 : _a.labels[blueGreenHelper_1.BLUE_GREEN_VERSION_LABEL]) ===
|
||||
((_b = existingIngress === null || existingIngress === void 0 ? void 0 : existingIngress.metadata) === null || _b === void 0 ? void 0 : _b.labels[blueGreenHelper_1.BLUE_GREEN_VERSION_LABEL]) ===
|
||||
blueGreenHelper_1.GREEN_LABEL_VALUE;
|
||||
if (!isValid) {
|
||||
core.debug(`Invalid ingress detected (must be in green state): ${JSON.stringify(inputObject)}`);
|
||||
@@ -21200,11 +21222,12 @@ function getUpdatedBlueGreenService(inputObject, labelValue) {
|
||||
}
|
||||
exports.getUpdatedBlueGreenService = getUpdatedBlueGreenService;
|
||||
function validateServicesState(kubectl, serviceEntityList) {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let areServicesGreen = true;
|
||||
for (const serviceObject of serviceEntityList) {
|
||||
// finding the existing routed service
|
||||
const existingService = yield blueGreenHelper_1.fetchResource(kubectl, serviceObject.kind, serviceObject.metadata.name);
|
||||
const existingService = yield blueGreenHelper_1.fetchResource(kubectl, serviceObject.kind, serviceObject.metadata.name, (_a = serviceObject === null || serviceObject === void 0 ? void 0 : serviceObject.metadata) === null || _a === void 0 ? void 0 : _a.namespace);
|
||||
let isServiceGreen = !!existingService &&
|
||||
getServiceSpecLabel(existingService) ==
|
||||
blueGreenHelper_1.GREEN_LABEL_VALUE;
|
||||
@@ -21325,11 +21348,12 @@ function getGreenSMIServiceResource(inputObject) {
|
||||
}
|
||||
exports.getGreenSMIServiceResource = getGreenSMIServiceResource;
|
||||
function validateTrafficSplitsState(kubectl, serviceEntityList) {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let trafficSplitsInRightState = true;
|
||||
for (const serviceObject of serviceEntityList) {
|
||||
const name = serviceObject.metadata.name;
|
||||
let trafficSplitObject = yield blueGreenHelper_1.fetchResource(kubectl, exports.TRAFFIC_SPLIT_OBJECT, blueGreenHelper_1.getBlueGreenResourceName(name, exports.TRAFFIC_SPLIT_OBJECT_NAME_SUFFIX));
|
||||
let trafficSplitObject = yield blueGreenHelper_1.fetchResource(kubectl, exports.TRAFFIC_SPLIT_OBJECT, blueGreenHelper_1.getBlueGreenResourceName(name, exports.TRAFFIC_SPLIT_OBJECT_NAME_SUFFIX), (_a = serviceObject === null || serviceObject === void 0 ? void 0 : serviceObject.metadata) === null || _a === void 0 ? void 0 : _a.namespace);
|
||||
core.debug(`ts object extracted was ${JSON.stringify(trafficSplitObject)}`);
|
||||
if (!trafficSplitObject) {
|
||||
core.debug(`no traffic split exits for ${name}`);
|
||||
@@ -21356,9 +21380,11 @@ function cleanupSMI(kubectl, serviceEntityList) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const deleteList = [];
|
||||
serviceEntityList.forEach((serviceObject) => {
|
||||
var _a;
|
||||
deleteList.push({
|
||||
name: blueGreenHelper_1.getBlueGreenResourceName(serviceObject.metadata.name, blueGreenHelper_1.GREEN_SUFFIX),
|
||||
kind: serviceObject.kind
|
||||
kind: serviceObject.kind,
|
||||
namespace: (_a = serviceObject === null || serviceObject === void 0 ? void 0 : serviceObject.metadata) === null || _a === void 0 ? void 0 : _a.namespace
|
||||
});
|
||||
});
|
||||
// delete all objects
|
||||
@@ -21522,11 +21548,12 @@ function addCanaryLabelsAndAnnotations(inputObject, type) {
|
||||
}
|
||||
}
|
||||
function cleanUpCanary(kubectl, files, includeServices) {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const deleteObject = function (kind, name) {
|
||||
const deleteObject = function (kind, name, namespace) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
const result = yield kubectl.delete([kind, name]);
|
||||
const result = yield kubectl.delete([kind, name], namespace);
|
||||
kubectlUtils_1.checkForErrors([result]);
|
||||
}
|
||||
catch (ex) {
|
||||
@@ -21541,13 +21568,14 @@ function cleanUpCanary(kubectl, files, includeServices) {
|
||||
for (const inputObject of parsedYaml) {
|
||||
const name = inputObject.metadata.name;
|
||||
const kind = inputObject.kind;
|
||||
const namespace = (_a = inputObject === null || inputObject === void 0 ? void 0 : inputObject.metadata) === null || _a === void 0 ? void 0 : _a.namespace;
|
||||
if (kubernetesTypes_1.isDeploymentEntity(kind) ||
|
||||
(includeServices && kubernetesTypes_1.isServiceEntity(kind))) {
|
||||
deletedFiles.push(filePath);
|
||||
const canaryObjectName = getCanaryResourceName(name);
|
||||
const baselineObjectName = getBaselineResourceName(name);
|
||||
yield deleteObject(kind, canaryObjectName);
|
||||
yield deleteObject(kind, baselineObjectName);
|
||||
yield deleteObject(kind, canaryObjectName, namespace);
|
||||
yield deleteObject(kind, baselineObjectName, namespace);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22002,12 +22030,20 @@ function checkManifestStability(kubectl, resources) {
|
||||
exports.checkManifestStability = checkManifestStability;
|
||||
function annotateAndLabelResources(files, kubectl, resourceTypes, allPods) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const defaultWorkflowFileName = 'k8s-deploy-failed-workflow-annotation';
|
||||
const githubToken = core.getInput('token');
|
||||
const workflowFilePath = yield githubUtils_1.getWorkflowFilePath(githubToken);
|
||||
let workflowFilePath;
|
||||
try {
|
||||
workflowFilePath = yield githubUtils_1.getWorkflowFilePath(githubToken);
|
||||
}
|
||||
catch (ex) {
|
||||
core.warning(`Failed to extract workflow file name: ${ex}`);
|
||||
workflowFilePath = defaultWorkflowFileName;
|
||||
}
|
||||
const deploymentConfig = yield dockerUtils_1.getDeploymentConfig();
|
||||
const annotationKeyLabel = workflowAnnotationUtils_1.getWorkflowAnnotationKeyLabel();
|
||||
yield annotateResources(files, kubectl, resourceTypes, allPods, annotationKeyLabel, workflowFilePath, deploymentConfig);
|
||||
yield labelResources(files, kubectl, annotationKeyLabel);
|
||||
yield annotateResources(files, kubectl, resourceTypes, allPods, annotationKeyLabel, workflowFilePath, deploymentConfig).catch((err) => core.warning(`Failed to annotate resources: ${err} `));
|
||||
yield labelResources(files, kubectl, annotationKeyLabel).catch((err) => core.warning(`Failed to label resources: ${err}`));
|
||||
});
|
||||
}
|
||||
exports.annotateAndLabelResources = annotateAndLabelResources;
|
||||
@@ -22030,7 +22066,7 @@ function annotateResources(files, kubectl, resourceTypes, allPods, annotationKey
|
||||
const annotationKeyValStr = `${annotationKey}=${workflowAnnotationUtils_1.getWorkflowAnnotations(lastSuccessSha, workflowFilePath, deploymentConfig)}`;
|
||||
const annotateNamespace = !(core.getInput('annotate-namespace').toLowerCase() === 'false');
|
||||
if (annotateNamespace) {
|
||||
annotateResults.push(yield kubectl.annotate('namespace', namespace, annotationKeyValStr));
|
||||
annotateResults.push(yield kubectl.annotate('namespace', namespace, annotationKeyValStr, namespace));
|
||||
}
|
||||
for (const file of files) {
|
||||
try {
|
||||
@@ -22045,7 +22081,7 @@ function annotateResources(files, kubectl, resourceTypes, allPods, annotationKey
|
||||
if (resource.type.toLowerCase() !==
|
||||
models.KubernetesWorkload.POD.toLowerCase()) {
|
||||
;
|
||||
(yield kubectlUtils_1.annotateChildPods(kubectl, resource.type, resource.name, annotationKeyValStr, allPods)).forEach((execResult) => annotateResults.push(execResult));
|
||||
(yield kubectlUtils_1.annotateChildPods(kubectl, resource.type, resource.name, resource.namespace, annotationKeyValStr, allPods)).forEach((execResult) => annotateResults.push(execResult));
|
||||
}
|
||||
}
|
||||
kubectlUtils_1.checkForErrors(annotateResults, true);
|
||||
@@ -22060,7 +22096,7 @@ function labelResources(files, kubectl, label) {
|
||||
const labelResults = [];
|
||||
for (const file of files) {
|
||||
try {
|
||||
const labelResult = yield kubectl.labelFiles(files, labels);
|
||||
const labelResult = yield kubectl.labelFiles(file, labels);
|
||||
labelResults.push(labelResult);
|
||||
}
|
||||
catch (e) {
|
||||
@@ -22308,7 +22344,7 @@ const core = __nccwpck_require__(6024);
|
||||
const toolCache = __nccwpck_require__(3594);
|
||||
const io = __nccwpck_require__(6202);
|
||||
class Kubectl {
|
||||
constructor(kubectlPath, namespace = 'default', ignoreSSLErrors = false, resourceGroup = '', name = '') {
|
||||
constructor(kubectlPath, namespace = '', ignoreSSLErrors = false, resourceGroup = '', name = '') {
|
||||
this.kubectlPath = kubectlPath;
|
||||
this.ignoreSSLErrors = !!ignoreSSLErrors;
|
||||
this.namespace = namespace;
|
||||
@@ -22327,37 +22363,41 @@ class Kubectl {
|
||||
];
|
||||
if (force)
|
||||
applyArgs.push('--force');
|
||||
return yield this.execute(applyArgs);
|
||||
return yield this.execute(applyArgs.concat(this.getFlags()));
|
||||
}
|
||||
catch (err) {
|
||||
core.debug('Kubectl apply failed:' + err);
|
||||
}
|
||||
});
|
||||
}
|
||||
describe(resourceType, resourceName, silent = false) {
|
||||
describe(resourceType, resourceName, silent = false, namespace) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return yield this.execute(['describe', resourceType, resourceName], silent);
|
||||
return yield this.execute(['describe', resourceType, resourceName].concat(this.getFlags(namespace)), silent);
|
||||
});
|
||||
}
|
||||
getNewReplicaSet(deployment) {
|
||||
getNewReplicaSet(deployment, namespace) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const result = yield this.describe('deployment', deployment, true);
|
||||
const result = yield this.describe('deployment', deployment, true, namespace);
|
||||
let newReplicaSet = '';
|
||||
if (result === null || result === void 0 ? void 0 : result.stdout) {
|
||||
const stdout = result.stdout.split('\n');
|
||||
core.debug('stdout from getNewReplicaSet is ' + JSON.stringify(stdout));
|
||||
stdout.forEach((line) => {
|
||||
const newreplicaset = 'newreplicaset';
|
||||
if (line && line.toLowerCase().indexOf(newreplicaset) > -1)
|
||||
if (line && line.toLowerCase().indexOf(newreplicaset) > -1) {
|
||||
core.debug(`found string of interest for replicaset, line is ${line}`);
|
||||
core.debug(`substring is ${line.substring(newreplicaset.length).trim()}`);
|
||||
newReplicaSet = line
|
||||
.substring(newreplicaset.length)
|
||||
.trim()
|
||||
.split(' ')[0];
|
||||
}
|
||||
});
|
||||
}
|
||||
return newReplicaSet;
|
||||
});
|
||||
}
|
||||
annotate(resourceType, resourceName, annotation) {
|
||||
annotate(resourceType, resourceName, annotation, namespace) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const args = [
|
||||
'annotate',
|
||||
@@ -22365,11 +22405,11 @@ class Kubectl {
|
||||
resourceName,
|
||||
annotation,
|
||||
'--overwrite'
|
||||
];
|
||||
].concat(this.getFlags(namespace));
|
||||
return yield this.execute(args);
|
||||
});
|
||||
}
|
||||
annotateFiles(files, annotation) {
|
||||
annotateFiles(files, annotation, namespace) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const filesToAnnotate = arrayUtils_1.createInlineArray(files);
|
||||
core.debug(`annotating ${filesToAnnotate} with annotation ${annotation}`);
|
||||
@@ -22379,12 +22419,11 @@ class Kubectl {
|
||||
filesToAnnotate,
|
||||
annotation,
|
||||
'--overwrite'
|
||||
];
|
||||
core.debug(`sending args from annotate to execute: ${JSON.stringify(args)}`);
|
||||
].concat(this.getFlags(namespace));
|
||||
return yield this.execute(args);
|
||||
});
|
||||
}
|
||||
labelFiles(files, labels) {
|
||||
labelFiles(files, labels, namespace) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const args = [
|
||||
'label',
|
||||
@@ -22392,56 +22431,53 @@ class Kubectl {
|
||||
arrayUtils_1.createInlineArray(files),
|
||||
...labels,
|
||||
'--overwrite'
|
||||
];
|
||||
].concat(this.getFlags(namespace));
|
||||
return yield this.execute(args);
|
||||
});
|
||||
}
|
||||
getAllPods() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return yield this.execute(['get', 'pods', '-o', 'json'], true);
|
||||
return yield this.execute(['get', 'pods', '-o', 'json'].concat(this.getFlags()), true);
|
||||
});
|
||||
}
|
||||
checkRolloutStatus(resourceType, name) {
|
||||
checkRolloutStatus(resourceType, name, namespace) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return yield this.execute([
|
||||
'rollout',
|
||||
'status',
|
||||
`${resourceType}/${name}`
|
||||
]);
|
||||
return yield this.execute(['rollout', 'status', `${resourceType}/${name}`].concat(this.getFlags(namespace)));
|
||||
});
|
||||
}
|
||||
getResource(resourceType, name, silentFailure = false) {
|
||||
getResource(resourceType, name, silentFailure = false, namespace) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
core.debug('fetching resource of type ' + resourceType + ' and name ' + name);
|
||||
return yield this.execute(['get', `${resourceType}/${name}`, '-o', 'json'], silentFailure);
|
||||
return yield this.execute(['get', `${resourceType}/${name}`, '-o', 'json'].concat(this.getFlags(namespace)), silentFailure);
|
||||
});
|
||||
}
|
||||
executeCommand(command, args) {
|
||||
if (!command)
|
||||
throw new Error('Command must be defined');
|
||||
return args ? this.execute([command, args]) : this.execute([command]);
|
||||
const a = args ? [args] : [];
|
||||
return this.execute([command, ...a.concat(this.getFlags())]);
|
||||
}
|
||||
delete(args) {
|
||||
delete(args, namespace) {
|
||||
if (typeof args === 'string')
|
||||
return this.execute(['delete', args]);
|
||||
return this.execute(['delete', ...args]);
|
||||
return this.execute(['delete', args].concat(this.getFlags(namespace)));
|
||||
return this.execute(['delete', ...args.concat(this.getFlags(namespace))]);
|
||||
}
|
||||
execute(args, silent = false) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
args = args.concat(this.getExecuteFlags());
|
||||
core.debug(`Kubectl run with command: ${this.kubectlPath} ${args}`);
|
||||
return yield exec_1.getExecOutput(this.kubectlPath, args, {
|
||||
silent
|
||||
});
|
||||
});
|
||||
}
|
||||
getExecuteFlags() {
|
||||
getFlags(namespaceOverride) {
|
||||
const flags = [];
|
||||
if (this.ignoreSSLErrors) {
|
||||
flags.push('--insecure-skip-tls-verify');
|
||||
}
|
||||
if (this.namespace) {
|
||||
flags.push('--namespace', this.namespace);
|
||||
const ns = namespaceOverride || this.namespace;
|
||||
if (ns) {
|
||||
flags.push('--namespace', ns);
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
@@ -22572,7 +22608,6 @@ const path = __nccwpck_require__(1017);
|
||||
class PrivateKubectl extends kubectl_1.Kubectl {
|
||||
execute(args, silent = false) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
args = args.concat(this.getExecuteFlags());
|
||||
args.unshift('kubectl');
|
||||
let kubectlCmd = args.join(' ');
|
||||
let addFileFlag = false;
|
||||
@@ -22622,10 +22657,13 @@ class PrivateKubectl extends kubectl_1.Kubectl {
|
||||
core.debug(`full form of az command: az ${allArgs.join(' ')}`);
|
||||
const runOutput = yield exec_1.getExecOutput('az', allArgs, eo);
|
||||
core.debug(`from kubectl private cluster command got run output ${JSON.stringify(runOutput)}`);
|
||||
if (runOutput.exitCode !== 0) {
|
||||
throw Error(`Call to private cluster failed. Command: '${kubectlCmd}', errormessage: ${runOutput.stderr}`);
|
||||
}
|
||||
const runObj = JSON.parse(runOutput.stdout);
|
||||
if (!silent)
|
||||
core.info(runObj.logs);
|
||||
if (runOutput.exitCode !== 0 && runObj.exitCode !== 0) {
|
||||
if (runObj.exitCode !== 0) {
|
||||
throw Error(`failed private cluster Kubectl command: ${kubectlCmd}`);
|
||||
}
|
||||
return {
|
||||
@@ -23133,6 +23171,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.annotateChildPods = exports.getLastSuccessfulRunSha = exports.checkForErrors = void 0;
|
||||
const core = __nccwpck_require__(6024);
|
||||
const NAMESPACE = 'namespace';
|
||||
function checkForErrors(execResults, warnIfError) {
|
||||
let stderr = '';
|
||||
execResults.forEach((result) => {
|
||||
@@ -23156,7 +23195,7 @@ exports.checkForErrors = checkForErrors;
|
||||
function getLastSuccessfulRunSha(kubectl, namespaceName, annotationKey) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
const result = yield kubectl.getResource('namespace', namespaceName);
|
||||
const result = yield kubectl.getResource(NAMESPACE, namespaceName, false, namespaceName);
|
||||
if (result === null || result === void 0 ? void 0 : result.stderr) {
|
||||
core.warning(result.stderr);
|
||||
return process.env.GITHUB_SHA;
|
||||
@@ -23179,12 +23218,12 @@ function getLastSuccessfulRunSha(kubectl, namespaceName, annotationKey) {
|
||||
});
|
||||
}
|
||||
exports.getLastSuccessfulRunSha = getLastSuccessfulRunSha;
|
||||
function annotateChildPods(kubectl, resourceType, resourceName, annotationKeyValStr, allPods) {
|
||||
function annotateChildPods(kubectl, resourceType, resourceName, namespace, annotationKeyValStr, allPods) {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let owner = resourceName;
|
||||
if (resourceType.toLowerCase().indexOf('deployment') > -1) {
|
||||
owner = yield kubectl.getNewReplicaSet(resourceName);
|
||||
owner = yield kubectl.getNewReplicaSet(resourceName, namespace);
|
||||
}
|
||||
const commandExecutionResults = [];
|
||||
if ((allPods === null || allPods === void 0 ? void 0 : allPods.items) && ((_a = allPods.items) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
||||
@@ -23194,7 +23233,7 @@ function annotateChildPods(kubectl, resourceType, resourceName, annotationKeyVal
|
||||
if (owners) {
|
||||
for (const ownerRef of owners) {
|
||||
if (ownerRef.name === owner) {
|
||||
commandExecutionResults.push(kubectl.annotate('pod', pod.metadata.name, annotationKeyValStr));
|
||||
commandExecutionResults.push(kubectl.annotate('pod', pod.metadata.name, annotationKeyValStr, namespace));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -23349,6 +23388,8 @@ const core = __nccwpck_require__(6024);
|
||||
const KubernetesConstants = __nccwpck_require__(6583);
|
||||
const kubectlUtils_1 = __nccwpck_require__(5474);
|
||||
const timeUtils_1 = __nccwpck_require__(4046);
|
||||
const IS_SILENT = false;
|
||||
const POD = 'pod';
|
||||
function checkManifestStability(kubectl, resources) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let rolloutStatusHasErrors = false;
|
||||
@@ -23356,32 +23397,32 @@ function checkManifestStability(kubectl, resources) {
|
||||
const resource = resources[i];
|
||||
if (KubernetesConstants.WORKLOAD_TYPES_WITH_ROLLOUT_STATUS.indexOf(resource.type.toLowerCase()) >= 0) {
|
||||
try {
|
||||
const result = yield kubectl.checkRolloutStatus(resource.type, resource.name);
|
||||
const result = yield kubectl.checkRolloutStatus(resource.type, resource.name, resource.namespace);
|
||||
kubectlUtils_1.checkForErrors([result]);
|
||||
}
|
||||
catch (ex) {
|
||||
core.error(ex);
|
||||
yield kubectl.describe(resource.type, resource.name);
|
||||
yield kubectl.describe(resource.type, resource.name, IS_SILENT, resource.namespace);
|
||||
rolloutStatusHasErrors = true;
|
||||
}
|
||||
}
|
||||
if (resource.type == KubernetesConstants.KubernetesWorkload.POD) {
|
||||
try {
|
||||
yield checkPodStatus(kubectl, resource.name);
|
||||
yield checkPodStatus(kubectl, resource);
|
||||
}
|
||||
catch (ex) {
|
||||
core.warning(`Could not determine pod status: ${JSON.stringify(ex)}`);
|
||||
yield kubectl.describe(resource.type, resource.name);
|
||||
yield kubectl.describe(resource.type, resource.name, IS_SILENT, resource.namespace);
|
||||
}
|
||||
}
|
||||
if (resource.type ==
|
||||
KubernetesConstants.DiscoveryAndLoadBalancerResource.SERVICE) {
|
||||
try {
|
||||
const service = yield getService(kubectl, resource.name);
|
||||
const service = yield getService(kubectl, resource);
|
||||
const { spec, status } = service;
|
||||
if (spec.type === KubernetesConstants.ServiceTypes.LOAD_BALANCER) {
|
||||
if (!isLoadBalancerIPAssigned(status)) {
|
||||
yield waitForServiceExternalIPAssignment(kubectl, resource.name);
|
||||
yield waitForServiceExternalIPAssignment(kubectl, resource);
|
||||
}
|
||||
else {
|
||||
core.info(`ServiceExternalIP ${resource.name} ${status.loadBalancer.ingress[0].ip}`);
|
||||
@@ -23390,7 +23431,7 @@ function checkManifestStability(kubectl, resources) {
|
||||
}
|
||||
catch (ex) {
|
||||
core.warning(`Could not determine service status of: ${resource.name} Error: ${ex}`);
|
||||
yield kubectl.describe(resource.type, resource.name);
|
||||
yield kubectl.describe(resource.type, resource.name, IS_SILENT, resource.namespace);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23400,7 +23441,7 @@ function checkManifestStability(kubectl, resources) {
|
||||
});
|
||||
}
|
||||
exports.checkManifestStability = checkManifestStability;
|
||||
function checkPodStatus(kubectl, podName) {
|
||||
function checkPodStatus(kubectl, pod) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const sleepTimeout = 10 * 1000; // 10 seconds
|
||||
const iterations = 60; // 60 * 10 seconds timeout = 10 minutes max timeout
|
||||
@@ -23408,20 +23449,20 @@ function checkPodStatus(kubectl, podName) {
|
||||
let kubectlDescribeNeeded = false;
|
||||
for (let i = 0; i < iterations; i++) {
|
||||
yield timeUtils_1.sleep(sleepTimeout);
|
||||
core.debug(`Polling for pod status: ${podName}`);
|
||||
podStatus = yield getPodStatus(kubectl, podName);
|
||||
core.debug(`Polling for pod status: ${pod.name}`);
|
||||
podStatus = yield getPodStatus(kubectl, pod);
|
||||
if (podStatus &&
|
||||
(podStatus === null || podStatus === void 0 ? void 0 : podStatus.phase) !== 'Pending' &&
|
||||
(podStatus === null || podStatus === void 0 ? void 0 : podStatus.phase) !== 'Unknown') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
podStatus = yield getPodStatus(kubectl, podName);
|
||||
podStatus = yield getPodStatus(kubectl, pod);
|
||||
switch (podStatus.phase) {
|
||||
case 'Succeeded':
|
||||
case 'Running':
|
||||
if (isPodReady(podStatus)) {
|
||||
console.log(`pod/${podName} is successfully rolled out`);
|
||||
console.log(`pod/${pod.name} is successfully rolled out`);
|
||||
}
|
||||
else {
|
||||
kubectlDescribeNeeded = true;
|
||||
@@ -23429,26 +23470,26 @@ function checkPodStatus(kubectl, podName) {
|
||||
break;
|
||||
case 'Pending':
|
||||
if (!isPodReady(podStatus)) {
|
||||
core.warning(`pod/${podName} rollout status check timed out`);
|
||||
core.warning(`pod/${pod.name} rollout status check timed out`);
|
||||
kubectlDescribeNeeded = true;
|
||||
}
|
||||
break;
|
||||
case 'Failed':
|
||||
core.error(`pod/${podName} rollout failed`);
|
||||
core.error(`pod/${pod.name} rollout failed`);
|
||||
kubectlDescribeNeeded = true;
|
||||
break;
|
||||
default:
|
||||
core.warning(`pod/${podName} rollout status: ${podStatus.phase}`);
|
||||
core.warning(`pod/${pod.name} rollout status: ${podStatus.phase}`);
|
||||
}
|
||||
if (kubectlDescribeNeeded) {
|
||||
yield kubectl.describe('pod', podName);
|
||||
yield kubectl.describe(POD, pod.name, IS_SILENT, pod.namespace);
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.checkPodStatus = checkPodStatus;
|
||||
function getPodStatus(kubectl, podName) {
|
||||
function getPodStatus(kubectl, pod) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const podResult = yield kubectl.getResource('pod', podName);
|
||||
const podResult = yield kubectl.getResource(POD, pod.name, IS_SILENT, pod.namespace);
|
||||
kubectlUtils_1.checkForErrors([podResult]);
|
||||
return JSON.parse(podResult.stdout).status;
|
||||
});
|
||||
@@ -23466,27 +23507,27 @@ function isPodReady(podStatus) {
|
||||
}
|
||||
return allContainersAreReady;
|
||||
}
|
||||
function getService(kubectl, serviceName) {
|
||||
function getService(kubectl, service) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const serviceResult = yield kubectl.getResource(KubernetesConstants.DiscoveryAndLoadBalancerResource.SERVICE, serviceName);
|
||||
const serviceResult = yield kubectl.getResource(KubernetesConstants.DiscoveryAndLoadBalancerResource.SERVICE, service.name, IS_SILENT, service.namespace);
|
||||
kubectlUtils_1.checkForErrors([serviceResult]);
|
||||
return JSON.parse(serviceResult.stdout);
|
||||
});
|
||||
}
|
||||
function waitForServiceExternalIPAssignment(kubectl, serviceName) {
|
||||
function waitForServiceExternalIPAssignment(kubectl, service) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const sleepTimeout = 10 * 1000; // 10 seconds
|
||||
const iterations = 18; // 18 * 10 seconds timeout = 3 minutes max timeout
|
||||
for (let i = 0; i < iterations; i++) {
|
||||
core.info(`Wait for service ip assignment : ${serviceName}`);
|
||||
core.info(`Wait for service ip assignment : ${service.name}`);
|
||||
yield timeUtils_1.sleep(sleepTimeout);
|
||||
const status = (yield getService(kubectl, serviceName)).status;
|
||||
const status = (yield getService(kubectl, service)).status;
|
||||
if (isLoadBalancerIPAssigned(status)) {
|
||||
core.info(`ServiceExternalIP ${serviceName} ${status.loadBalancer.ingress[0].ip}`);
|
||||
core.info(`ServiceExternalIP ${service.name} ${status.loadBalancer.ingress[0].ip}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
core.warning(`Wait for service ip assignment timed out${serviceName}`);
|
||||
core.warning(`Wait for service ip assignment timed out ${service.name}`);
|
||||
});
|
||||
}
|
||||
function isLoadBalancerIPAssigned(status) {
|
||||
@@ -23695,11 +23736,13 @@ function getResources(filePaths, filterResourceTypes) {
|
||||
filePaths.forEach((filePath) => {
|
||||
const fileContents = fs.readFileSync(filePath).toString();
|
||||
yaml.safeLoadAll(fileContents, (inputObject) => {
|
||||
var _a;
|
||||
const inputObjectKind = (inputObject === null || inputObject === void 0 ? void 0 : inputObject.kind) || '';
|
||||
if (filterResourceTypes.filter((type) => inputObjectKind.toLowerCase() === type.toLowerCase()).length > 0) {
|
||||
resources.push({
|
||||
type: inputObject.kind,
|
||||
name: inputObject.metadata.name
|
||||
name: inputObject.metadata.name,
|
||||
namespace: (_a = inputObject === null || inputObject === void 0 ? void 0 : inputObject.metadata) === null || _a === void 0 ? void 0 : _a.namespace
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -23788,8 +23831,9 @@ exports.getTrafficSplitAPIVersion = getTrafficSplitAPIVersion;
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.cleanLabel = exports.getWorkflowAnnotationKeyLabel = exports.getWorkflowAnnotations = void 0;
|
||||
exports.removeInvalidLabelCharacters = exports.cleanLabel = exports.getWorkflowAnnotationKeyLabel = exports.getWorkflowAnnotations = exports.VALID_LABEL_REGEX = void 0;
|
||||
const ANNOTATION_PREFIX = 'actions.github.com';
|
||||
exports.VALID_LABEL_REGEX = /([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]/;
|
||||
function getWorkflowAnnotations(lastSuccessRunSha, workflowFilePath, deploymentConfig) {
|
||||
const annotationObject = {
|
||||
run: process.env.GITHUB_RUN_ID,
|
||||
@@ -23821,14 +23865,20 @@ exports.getWorkflowAnnotationKeyLabel = getWorkflowAnnotationKeyLabel;
|
||||
* @returns cleaned label
|
||||
*/
|
||||
function cleanLabel(label) {
|
||||
let removedInvalidChars = label
|
||||
let removedInvalidChars = removeInvalidLabelCharacters(label);
|
||||
const regexResult = exports.VALID_LABEL_REGEX.exec(removedInvalidChars) || [
|
||||
'github-workflow-file'
|
||||
];
|
||||
return regexResult[0];
|
||||
}
|
||||
exports.cleanLabel = cleanLabel;
|
||||
function removeInvalidLabelCharacters(label) {
|
||||
return label
|
||||
.replace(/\s/gi, '_')
|
||||
.replace(/[\/\\\|]/gi, '-')
|
||||
.replace(/[^-A-Za-z0-9_.]/gi, '');
|
||||
const regex = /([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]/;
|
||||
return regex.exec(removedInvalidChars)[0] || '';
|
||||
}
|
||||
exports.cleanLabel = cleanLabel;
|
||||
exports.removeInvalidLabelCharacters = removeInvalidLabelCharacters;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
Generated
+23
-215
@@ -9,7 +9,7 @@
|
||||
"version": "0.0.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.9.1",
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/exec": "^1.0.0",
|
||||
"@actions/io": "^1.0.0",
|
||||
"@actions/tool-cache": "1.1.2",
|
||||
@@ -22,17 +22,17 @@
|
||||
"@types/jest": "^26.0.0",
|
||||
"@types/js-yaml": "^3.12.7",
|
||||
"@types/node": "^12.20.41",
|
||||
"@vercel/ncc": "^0.36.1",
|
||||
"jest": "^26.0.0",
|
||||
"ncc": "^0.3.6",
|
||||
"prettier": "^2.7.1",
|
||||
"ts-jest": "^26.0.0",
|
||||
"typescript": "3.9.5"
|
||||
}
|
||||
},
|
||||
"node_modules/@actions/core": {
|
||||
"version": "1.9.1",
|
||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.9.1.tgz",
|
||||
"integrity": "sha512-5ad+U2YGrmmiw6du20AQW5XuWo7UKN2052FjSV7MX+Wfjf8sCqcsZe62NfgHys4QI4/Y+vQvLKYL8jWtA1ZBTA==",
|
||||
"version": "1.10.0",
|
||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz",
|
||||
"integrity": "sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==",
|
||||
"dependencies": {
|
||||
"@actions/http-client": "^2.0.1",
|
||||
"uuid": "^8.3.2"
|
||||
@@ -1183,6 +1183,15 @@
|
||||
"integrity": "sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@vercel/ncc": {
|
||||
"version": "0.36.1",
|
||||
"resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.36.1.tgz",
|
||||
"integrity": "sha512-S4cL7Taa9yb5qbv+6wLgiKVZ03Qfkc4jGRuiUQMQ8HGBD5pcNRnHeYM33zBvJE4/zJGjJJ8GScB+WmTsn9mORw==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"ncc": "dist/ncc/cli.js"
|
||||
}
|
||||
},
|
||||
"node_modules/abab": {
|
||||
"version": "2.0.6",
|
||||
"resolved": "https://registry.npmjs.org/abab/-/abab-2.0.6.tgz",
|
||||
@@ -1875,15 +1884,6 @@
|
||||
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/colors": {
|
||||
"version": "1.2.3",
|
||||
"resolved": "https://registry.npmjs.org/colors/-/colors-1.2.3.tgz",
|
||||
"integrity": "sha512-qTfM2pNFeMZcLvf/RbrVAzDEVttZjFhaApfx9dplNjvHSX88Ui66zBRb/4YGob/xUWxDceirgoC1lT676asfCQ==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=0.1.90"
|
||||
}
|
||||
},
|
||||
"node_modules/combined-stream": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
@@ -1978,15 +1978,6 @@
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/dateformat": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/dateformat/-/dateformat-3.0.3.tgz",
|
||||
"integrity": "sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/debug": {
|
||||
"version": "4.3.4",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||
@@ -4091,58 +4082,6 @@
|
||||
"integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/ncc": {
|
||||
"version": "0.3.6",
|
||||
"resolved": "https://registry.npmjs.org/ncc/-/ncc-0.3.6.tgz",
|
||||
"integrity": "sha512-OXudTB2Ebt/FnOuDoPQbaa17+tdVqSOWA+gLfPxccWwsNED1uA2zEhpoB1hwdFC9yYbio/mdV5cvOtQI3Zrx1w==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"mkdirp": "^0.5.1",
|
||||
"rimraf": "^2.6.1",
|
||||
"tracer": "^0.8.7",
|
||||
"ws": "^2.3.1"
|
||||
}
|
||||
},
|
||||
"node_modules/ncc/node_modules/mkdirp": {
|
||||
"version": "0.5.6",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz",
|
||||
"integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"minimist": "^1.2.6"
|
||||
},
|
||||
"bin": {
|
||||
"mkdirp": "bin/cmd.js"
|
||||
}
|
||||
},
|
||||
"node_modules/ncc/node_modules/rimraf": {
|
||||
"version": "2.7.1",
|
||||
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz",
|
||||
"integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"glob": "^7.1.3"
|
||||
},
|
||||
"bin": {
|
||||
"rimraf": "bin.js"
|
||||
}
|
||||
},
|
||||
"node_modules/ncc/node_modules/safe-buffer": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.0.1.tgz",
|
||||
"integrity": "sha512-cr7dZWLwOeaFBLTIuZeYdkfO7UzGIKhjYENJFAxUOMKWGaWDm2nJM2rzxNRm5Owu0DH3ApwNo6kx5idXZfb/Iw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/ncc/node_modules/ws": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-2.3.1.tgz",
|
||||
"integrity": "sha512-61a+9LgtYZxTq1hAonhX8Xwpo2riK4IOR/BIVxioFbCfc3QFKmpE4x9dLExfLHKtUfVZigYa36tThVhO57erEw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"safe-buffer": "~5.0.1",
|
||||
"ultron": "~1.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/nice-try": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz",
|
||||
@@ -5883,15 +5822,6 @@
|
||||
"integrity": "sha512-fcwX4mndzpLQKBS1DVYhGAcYaYt7vsHNIvQV+WXMvnow5cgjPphq5CaayLaGsjRdSCKZFNGt7/GYAuXaNOiYCA==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/tinytim": {
|
||||
"version": "0.1.1",
|
||||
"resolved": "https://registry.npmjs.org/tinytim/-/tinytim-0.1.1.tgz",
|
||||
"integrity": "sha512-NIpsp9lBIxPNzB++HnMmUd4byzJSVbbO4F+As1Gb1IG/YQT5QvmBDjpx8SpDS8fhGC+t+Qw8ldQgbcAIaU+2cA==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">= 0.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/tmpl": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz",
|
||||
@@ -5984,33 +5914,6 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/tracer": {
|
||||
"version": "0.8.15",
|
||||
"resolved": "https://registry.npmjs.org/tracer/-/tracer-0.8.15.tgz",
|
||||
"integrity": "sha512-ZQzlhd6zZFIpAhACiZkxLjl65XqVwi8t8UEBVGRIHAQN6nj55ftJWiFell+WSqWCP/vEycrIbUSuiyMwul+TFw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"colors": "1.2.3",
|
||||
"dateformat": "3.0.3",
|
||||
"mkdirp": "^0.5.1",
|
||||
"tinytim": "0.1.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/tracer/node_modules/mkdirp": {
|
||||
"version": "0.5.6",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz",
|
||||
"integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"minimist": "^1.2.6"
|
||||
},
|
||||
"bin": {
|
||||
"mkdirp": "bin/cmd.js"
|
||||
}
|
||||
},
|
||||
"node_modules/ts-jest": {
|
||||
"version": "26.5.6",
|
||||
"resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-26.5.6.tgz",
|
||||
@@ -6127,12 +6030,6 @@
|
||||
"node": ">=4.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/ultron": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.1.tgz",
|
||||
"integrity": "sha512-UIEXBNeYmKptWH6z8ZnqTeS8fV74zG0/eRU9VGkpzz+LIJNs8W/zM/L+7ctCkRrgbNnnR0xxw4bKOr0cW0N0Og==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/underscore": {
|
||||
"version": "1.13.4",
|
||||
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.4.tgz",
|
||||
@@ -6529,9 +6426,9 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": {
|
||||
"version": "1.9.1",
|
||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.9.1.tgz",
|
||||
"integrity": "sha512-5ad+U2YGrmmiw6du20AQW5XuWo7UKN2052FjSV7MX+Wfjf8sCqcsZe62NfgHys4QI4/Y+vQvLKYL8jWtA1ZBTA==",
|
||||
"version": "1.10.0",
|
||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz",
|
||||
"integrity": "sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==",
|
||||
"requires": {
|
||||
"@actions/http-client": "^2.0.1",
|
||||
"uuid": "^8.3.2"
|
||||
@@ -7493,6 +7390,12 @@
|
||||
"integrity": "sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==",
|
||||
"dev": true
|
||||
},
|
||||
"@vercel/ncc": {
|
||||
"version": "0.36.1",
|
||||
"resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.36.1.tgz",
|
||||
"integrity": "sha512-S4cL7Taa9yb5qbv+6wLgiKVZ03Qfkc4jGRuiUQMQ8HGBD5pcNRnHeYM33zBvJE4/zJGjJJ8GScB+WmTsn9mORw==",
|
||||
"dev": true
|
||||
},
|
||||
"abab": {
|
||||
"version": "2.0.6",
|
||||
"resolved": "https://registry.npmjs.org/abab/-/abab-2.0.6.tgz",
|
||||
@@ -8020,12 +7923,6 @@
|
||||
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
|
||||
"dev": true
|
||||
},
|
||||
"colors": {
|
||||
"version": "1.2.3",
|
||||
"resolved": "https://registry.npmjs.org/colors/-/colors-1.2.3.tgz",
|
||||
"integrity": "sha512-qTfM2pNFeMZcLvf/RbrVAzDEVttZjFhaApfx9dplNjvHSX88Ui66zBRb/4YGob/xUWxDceirgoC1lT676asfCQ==",
|
||||
"dev": true
|
||||
},
|
||||
"combined-stream": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
@@ -8107,12 +8004,6 @@
|
||||
"whatwg-url": "^8.0.0"
|
||||
}
|
||||
},
|
||||
"dateformat": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/dateformat/-/dateformat-3.0.3.tgz",
|
||||
"integrity": "sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q==",
|
||||
"dev": true
|
||||
},
|
||||
"debug": {
|
||||
"version": "4.3.4",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||
@@ -9728,54 +9619,6 @@
|
||||
"integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==",
|
||||
"dev": true
|
||||
},
|
||||
"ncc": {
|
||||
"version": "0.3.6",
|
||||
"resolved": "https://registry.npmjs.org/ncc/-/ncc-0.3.6.tgz",
|
||||
"integrity": "sha512-OXudTB2Ebt/FnOuDoPQbaa17+tdVqSOWA+gLfPxccWwsNED1uA2zEhpoB1hwdFC9yYbio/mdV5cvOtQI3Zrx1w==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"mkdirp": "^0.5.1",
|
||||
"rimraf": "^2.6.1",
|
||||
"tracer": "^0.8.7",
|
||||
"ws": "^2.3.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"mkdirp": {
|
||||
"version": "0.5.6",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz",
|
||||
"integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"minimist": "^1.2.6"
|
||||
}
|
||||
},
|
||||
"rimraf": {
|
||||
"version": "2.7.1",
|
||||
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz",
|
||||
"integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"glob": "^7.1.3"
|
||||
}
|
||||
},
|
||||
"safe-buffer": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.0.1.tgz",
|
||||
"integrity": "sha512-cr7dZWLwOeaFBLTIuZeYdkfO7UzGIKhjYENJFAxUOMKWGaWDm2nJM2rzxNRm5Owu0DH3ApwNo6kx5idXZfb/Iw==",
|
||||
"dev": true
|
||||
},
|
||||
"ws": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-2.3.1.tgz",
|
||||
"integrity": "sha512-61a+9LgtYZxTq1hAonhX8Xwpo2riK4IOR/BIVxioFbCfc3QFKmpE4x9dLExfLHKtUfVZigYa36tThVhO57erEw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"safe-buffer": "~5.0.1",
|
||||
"ultron": "~1.1.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"nice-try": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz",
|
||||
@@ -11139,12 +10982,6 @@
|
||||
"integrity": "sha512-fcwX4mndzpLQKBS1DVYhGAcYaYt7vsHNIvQV+WXMvnow5cgjPphq5CaayLaGsjRdSCKZFNGt7/GYAuXaNOiYCA==",
|
||||
"dev": true
|
||||
},
|
||||
"tinytim": {
|
||||
"version": "0.1.1",
|
||||
"resolved": "https://registry.npmjs.org/tinytim/-/tinytim-0.1.1.tgz",
|
||||
"integrity": "sha512-NIpsp9lBIxPNzB++HnMmUd4byzJSVbbO4F+As1Gb1IG/YQT5QvmBDjpx8SpDS8fhGC+t+Qw8ldQgbcAIaU+2cA==",
|
||||
"dev": true
|
||||
},
|
||||
"tmpl": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz",
|
||||
@@ -11218,29 +11055,6 @@
|
||||
"punycode": "^2.1.1"
|
||||
}
|
||||
},
|
||||
"tracer": {
|
||||
"version": "0.8.15",
|
||||
"resolved": "https://registry.npmjs.org/tracer/-/tracer-0.8.15.tgz",
|
||||
"integrity": "sha512-ZQzlhd6zZFIpAhACiZkxLjl65XqVwi8t8UEBVGRIHAQN6nj55ftJWiFell+WSqWCP/vEycrIbUSuiyMwul+TFw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"colors": "1.2.3",
|
||||
"dateformat": "3.0.3",
|
||||
"mkdirp": "^0.5.1",
|
||||
"tinytim": "0.1.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"mkdirp": {
|
||||
"version": "0.5.6",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz",
|
||||
"integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"minimist": "^1.2.6"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"ts-jest": {
|
||||
"version": "26.5.6",
|
||||
"resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-26.5.6.tgz",
|
||||
@@ -11321,12 +11135,6 @@
|
||||
"integrity": "sha512-hSAifV3k+i6lEoCJ2k6R2Z/rp/H3+8sdmcn5NrS3/3kE7+RyZXm9aqvxWqjEXHAd8b0pShatpcdMTvEdvAJltQ==",
|
||||
"dev": true
|
||||
},
|
||||
"ultron": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.1.tgz",
|
||||
"integrity": "sha512-UIEXBNeYmKptWH6z8ZnqTeS8fV74zG0/eRU9VGkpzz+LIJNs8W/zM/L+7ctCkRrgbNnnR0xxw4bKOr0cW0N0Og==",
|
||||
"dev": true
|
||||
},
|
||||
"underscore": {
|
||||
"version": "1.13.4",
|
||||
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.4.tgz",
|
||||
|
||||
+2
-2
@@ -11,7 +11,7 @@
|
||||
"format-check": "prettier --check ."
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.9.1",
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/exec": "^1.0.0",
|
||||
"@actions/io": "^1.0.0",
|
||||
"@actions/tool-cache": "1.1.2",
|
||||
@@ -24,8 +24,8 @@
|
||||
"@types/jest": "^26.0.0",
|
||||
"@types/js-yaml": "^3.12.7",
|
||||
"@types/node": "^12.20.41",
|
||||
"@vercel/ncc": "^0.36.1",
|
||||
"jest": "^26.0.0",
|
||||
"ncc": "^0.3.6",
|
||||
"prettier": "^2.7.1",
|
||||
"ts-jest": "^26.0.0",
|
||||
"typescript": "3.9.5"
|
||||
|
||||
@@ -56,7 +56,9 @@ export async function deploy(
|
||||
for (const ingressResource of ingressResources) {
|
||||
await kubectl.getResource(
|
||||
KubernetesConstants.DiscoveryAndLoadBalancerResource.INGRESS,
|
||||
ingressResource.name
|
||||
ingressResource.name,
|
||||
false,
|
||||
ingressResource.namespace
|
||||
)
|
||||
}
|
||||
core.endGroup()
|
||||
|
||||
@@ -38,7 +38,8 @@ export async function deleteGreenObjects(
|
||||
const resourcesToDelete: K8sDeleteObject[] = toDelete.map((obj) => {
|
||||
return {
|
||||
name: getBlueGreenResourceName(obj.metadata.name, GREEN_SUFFIX),
|
||||
kind: obj.kind
|
||||
kind: obj.kind,
|
||||
namespace: obj.metadata.namespace
|
||||
}
|
||||
})
|
||||
|
||||
@@ -66,31 +67,25 @@ export async function deleteObjects(
|
||||
// other common functions
|
||||
export function getManifestObjects(filePaths: string[]): BlueGreenManifests {
|
||||
const deploymentEntityList: K8sObject[] = []
|
||||
const serviceEntityList: K8sObject[] = []
|
||||
const routedServiceEntityList: K8sObject[] = []
|
||||
const unroutedServiceEntityList: K8sObject[] = []
|
||||
const ingressEntityList: K8sObject[] = []
|
||||
const otherEntitiesList: K8sObject[] = []
|
||||
const serviceNameMap = new Map<string, string>()
|
||||
|
||||
// Manifest objects per type. All resources should be parsed and
|
||||
// organized before we can check if services are “routed” or not.
|
||||
filePaths.forEach((filePath: string) => {
|
||||
const fileContents = fs.readFileSync(filePath).toString()
|
||||
yaml.safeLoadAll(fileContents, (inputObject) => {
|
||||
if (!!inputObject) {
|
||||
const kind = inputObject.kind
|
||||
const name = inputObject.metadata.name
|
||||
|
||||
if (isDeploymentEntity(kind)) {
|
||||
deploymentEntityList.push(inputObject)
|
||||
} else if (isServiceEntity(kind)) {
|
||||
if (isServiceRouted(inputObject, deploymentEntityList)) {
|
||||
routedServiceEntityList.push(inputObject)
|
||||
serviceNameMap.set(
|
||||
name,
|
||||
getBlueGreenResourceName(name, GREEN_SUFFIX)
|
||||
)
|
||||
} else {
|
||||
unroutedServiceEntityList.push(inputObject)
|
||||
}
|
||||
serviceEntityList.push(inputObject)
|
||||
} else if (isIngressEntity(kind)) {
|
||||
ingressEntityList.push(inputObject)
|
||||
} else {
|
||||
@@ -100,6 +95,16 @@ export function getManifestObjects(filePaths: string[]): BlueGreenManifests {
|
||||
})
|
||||
})
|
||||
|
||||
serviceEntityList.forEach((inputObject: any) => {
|
||||
if (isServiceRouted(inputObject, deploymentEntityList)) {
|
||||
const name = inputObject.metadata.name
|
||||
routedServiceEntityList.push(inputObject)
|
||||
serviceNameMap.set(name, getBlueGreenResourceName(name, GREEN_SUFFIX))
|
||||
} else {
|
||||
unroutedServiceEntityList.push(inputObject)
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
serviceEntityList: routedServiceEntityList,
|
||||
serviceNameMap: serviceNameMap,
|
||||
@@ -234,9 +239,10 @@ export function isServiceSelectorSubsetOfMatchLabel(
|
||||
export async function fetchResource(
|
||||
kubectl: Kubectl,
|
||||
kind: string,
|
||||
name: string
|
||||
name: string,
|
||||
namespace?: string
|
||||
): Promise<K8sObject> {
|
||||
const result = await kubectl.getResource(kind, name)
|
||||
const result = await kubectl.getResource(kind, name, false, namespace)
|
||||
if (result == null || !!result.stderr) {
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -97,7 +97,8 @@ export async function validateIngresses(
|
||||
const existingIngress = await fetchResource(
|
||||
kubectl,
|
||||
inputObject.kind,
|
||||
inputObject.metadata.name
|
||||
inputObject.metadata.name,
|
||||
inputObject?.metadata?.namespace
|
||||
)
|
||||
|
||||
const isValid =
|
||||
|
||||
@@ -31,7 +31,8 @@ export async function validateServicesState(
|
||||
const existingService = await fetchResource(
|
||||
kubectl,
|
||||
serviceObject.kind,
|
||||
serviceObject.metadata.name
|
||||
serviceObject.metadata.name,
|
||||
serviceObject?.metadata?.namespace
|
||||
)
|
||||
|
||||
let isServiceGreen =
|
||||
|
||||
@@ -142,7 +142,8 @@ export async function validateTrafficSplitsState(
|
||||
let trafficSplitObject = await fetchResource(
|
||||
kubectl,
|
||||
TRAFFIC_SPLIT_OBJECT,
|
||||
getBlueGreenResourceName(name, TRAFFIC_SPLIT_OBJECT_NAME_SUFFIX)
|
||||
getBlueGreenResourceName(name, TRAFFIC_SPLIT_OBJECT_NAME_SUFFIX),
|
||||
serviceObject?.metadata?.namespace
|
||||
)
|
||||
core.debug(
|
||||
`ts object extracted was ${JSON.stringify(trafficSplitObject)}`
|
||||
@@ -183,7 +184,8 @@ export async function cleanupSMI(
|
||||
serviceObject.metadata.name,
|
||||
GREEN_SUFFIX
|
||||
),
|
||||
kind: serviceObject.kind
|
||||
kind: serviceObject.kind,
|
||||
namespace: serviceObject?.metadata?.namespace
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -195,9 +195,13 @@ async function cleanUpCanary(
|
||||
files: string[],
|
||||
includeServices: boolean
|
||||
): Promise<string[]> {
|
||||
const deleteObject = async function (kind, name) {
|
||||
const deleteObject = async function (
|
||||
kind: string,
|
||||
name: string,
|
||||
namespace: string | undefined
|
||||
) {
|
||||
try {
|
||||
const result = await kubectl.delete([kind, name])
|
||||
const result = await kubectl.delete([kind, name], namespace)
|
||||
checkForErrors([result])
|
||||
} catch (ex) {
|
||||
// Ignore failures of delete if it doesn't exist
|
||||
@@ -213,6 +217,7 @@ async function cleanUpCanary(
|
||||
for (const inputObject of parsedYaml) {
|
||||
const name = inputObject.metadata.name
|
||||
const kind = inputObject.kind
|
||||
const namespace: string | undefined = inputObject?.metadata?.namespace
|
||||
|
||||
if (
|
||||
isDeploymentEntity(kind) ||
|
||||
@@ -222,8 +227,8 @@ async function cleanUpCanary(
|
||||
const canaryObjectName = getCanaryResourceName(name)
|
||||
const baselineObjectName = getBaselineResourceName(name)
|
||||
|
||||
await deleteObject(kind, canaryObjectName)
|
||||
await deleteObject(kind, baselineObjectName)
|
||||
await deleteObject(kind, canaryObjectName, namespace)
|
||||
await deleteObject(kind, baselineObjectName, namespace)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,8 +150,15 @@ export async function annotateAndLabelResources(
|
||||
resourceTypes: Resource[],
|
||||
allPods: any
|
||||
) {
|
||||
const defaultWorkflowFileName = 'k8s-deploy-failed-workflow-annotation'
|
||||
const githubToken = core.getInput('token')
|
||||
const workflowFilePath = await getWorkflowFilePath(githubToken)
|
||||
let workflowFilePath
|
||||
try {
|
||||
workflowFilePath = await getWorkflowFilePath(githubToken)
|
||||
} catch (ex) {
|
||||
core.warning(`Failed to extract workflow file name: ${ex}`)
|
||||
workflowFilePath = defaultWorkflowFileName
|
||||
}
|
||||
|
||||
const deploymentConfig = await getDeploymentConfig()
|
||||
const annotationKeyLabel = getWorkflowAnnotationKeyLabel()
|
||||
@@ -164,8 +171,11 @@ export async function annotateAndLabelResources(
|
||||
annotationKeyLabel,
|
||||
workflowFilePath,
|
||||
deploymentConfig
|
||||
).catch((err) => core.warning(`Failed to annotate resources: ${err} `))
|
||||
|
||||
await labelResources(files, kubectl, annotationKeyLabel).catch((err) =>
|
||||
core.warning(`Failed to label resources: ${err}`)
|
||||
)
|
||||
await labelResources(files, kubectl, annotationKeyLabel)
|
||||
}
|
||||
|
||||
async function annotateResources(
|
||||
@@ -208,7 +218,12 @@ async function annotateResources(
|
||||
)
|
||||
if (annotateNamespace) {
|
||||
annotateResults.push(
|
||||
await kubectl.annotate('namespace', namespace, annotationKeyValStr)
|
||||
await kubectl.annotate(
|
||||
'namespace',
|
||||
namespace,
|
||||
annotationKeyValStr,
|
||||
namespace
|
||||
)
|
||||
)
|
||||
}
|
||||
for (const file of files) {
|
||||
@@ -233,6 +248,7 @@ async function annotateResources(
|
||||
kubectl,
|
||||
resource.type,
|
||||
resource.name,
|
||||
resource.namespace,
|
||||
annotationKeyValStr,
|
||||
allPods
|
||||
)
|
||||
@@ -258,7 +274,7 @@ async function labelResources(
|
||||
const labelResults = []
|
||||
for (const file of files) {
|
||||
try {
|
||||
const labelResult = await kubectl.labelFiles(files, labels)
|
||||
const labelResult = await kubectl.labelFiles(file, labels)
|
||||
labelResults.push(labelResult)
|
||||
} catch (e) {
|
||||
core.warning(`failed to annotate resource: ${e}`)
|
||||
|
||||
@@ -2,6 +2,7 @@ export interface K8sObject {
|
||||
metadata: {
|
||||
name: string
|
||||
labels: Map<string, string>
|
||||
namespace?: string
|
||||
}
|
||||
kind: string
|
||||
spec: any
|
||||
@@ -16,6 +17,7 @@ export interface K8sServiceObject extends K8sObject {
|
||||
export interface K8sDeleteObject {
|
||||
name: string
|
||||
kind: string
|
||||
namespace?: string
|
||||
}
|
||||
|
||||
export interface K8sIngress extends K8sObject {
|
||||
|
||||
+176
-1
@@ -3,7 +3,6 @@ import * as exec from '@actions/exec'
|
||||
import * as io from '@actions/io'
|
||||
import * as core from '@actions/core'
|
||||
import * as toolCache from '@actions/tool-cache'
|
||||
import {config} from 'process'
|
||||
|
||||
describe('Kubectl path', () => {
|
||||
const version = '1.1'
|
||||
@@ -38,6 +37,7 @@ describe('Kubectl path', () => {
|
||||
const kubectlPath = 'kubectlPath'
|
||||
const testNamespace = 'testNamespace'
|
||||
const defaultNamespace = 'default'
|
||||
const otherNamespace = 'otherns'
|
||||
describe('Kubectl class', () => {
|
||||
describe('default namespace behavior', () => {
|
||||
const kubectl = new Kubectl(kubectlPath, defaultNamespace)
|
||||
@@ -122,6 +122,26 @@ describe('Kubectl class', () => {
|
||||
],
|
||||
{silent: false}
|
||||
)
|
||||
|
||||
// overrided ns
|
||||
const silent = false
|
||||
await kubectl.describe(
|
||||
resourceType,
|
||||
resourceName,
|
||||
silent,
|
||||
otherNamespace
|
||||
)
|
||||
expect(exec.getExecOutput).toBeCalledWith(
|
||||
kubectlPath,
|
||||
[
|
||||
'describe',
|
||||
resourceType,
|
||||
resourceName,
|
||||
'--namespace',
|
||||
otherNamespace
|
||||
],
|
||||
{silent}
|
||||
)
|
||||
})
|
||||
|
||||
it('describes a resource silently', async () => {
|
||||
@@ -140,6 +160,26 @@ describe('Kubectl class', () => {
|
||||
],
|
||||
{silent: true}
|
||||
)
|
||||
|
||||
// overrided ns
|
||||
const silent = false
|
||||
await kubectl.describe(
|
||||
resourceType,
|
||||
resourceName,
|
||||
silent,
|
||||
otherNamespace
|
||||
)
|
||||
expect(exec.getExecOutput).toBeCalledWith(
|
||||
kubectlPath,
|
||||
[
|
||||
'describe',
|
||||
resourceType,
|
||||
resourceName,
|
||||
'--namespace',
|
||||
otherNamespace
|
||||
],
|
||||
{silent}
|
||||
)
|
||||
})
|
||||
|
||||
it('annotates resource', async () => {
|
||||
@@ -165,6 +205,27 @@ describe('Kubectl class', () => {
|
||||
],
|
||||
{silent: false}
|
||||
)
|
||||
|
||||
// override ns
|
||||
await kubectl.annotate(
|
||||
resourceType,
|
||||
resourceName,
|
||||
annotation,
|
||||
otherNamespace
|
||||
)
|
||||
expect(exec.getExecOutput).toBeCalledWith(
|
||||
kubectlPath,
|
||||
[
|
||||
'annotate',
|
||||
resourceType,
|
||||
resourceName,
|
||||
annotation,
|
||||
'--overwrite',
|
||||
'--namespace',
|
||||
otherNamespace
|
||||
],
|
||||
{silent: false}
|
||||
)
|
||||
})
|
||||
|
||||
it('annotates files with single file', async () => {
|
||||
@@ -185,6 +246,22 @@ describe('Kubectl class', () => {
|
||||
],
|
||||
{silent: false}
|
||||
)
|
||||
|
||||
// override ns
|
||||
await kubectl.annotateFiles(file, annotation, otherNamespace)
|
||||
expect(exec.getExecOutput).toBeCalledWith(
|
||||
kubectlPath,
|
||||
[
|
||||
'annotate',
|
||||
'-f',
|
||||
file,
|
||||
annotation,
|
||||
'--overwrite',
|
||||
'--namespace',
|
||||
otherNamespace
|
||||
],
|
||||
{silent: false}
|
||||
)
|
||||
})
|
||||
|
||||
it('annotates files with mulitple files', async () => {
|
||||
@@ -205,6 +282,22 @@ describe('Kubectl class', () => {
|
||||
],
|
||||
{silent: false}
|
||||
)
|
||||
|
||||
// override ns
|
||||
await kubectl.annotateFiles(files, annotation, otherNamespace)
|
||||
expect(exec.getExecOutput).toBeCalledWith(
|
||||
kubectlPath,
|
||||
[
|
||||
'annotate',
|
||||
'-f',
|
||||
files.join(','),
|
||||
annotation,
|
||||
'--overwrite',
|
||||
'--namespace',
|
||||
otherNamespace
|
||||
],
|
||||
{silent: false}
|
||||
)
|
||||
})
|
||||
|
||||
it('labels files with single file', async () => {
|
||||
@@ -225,6 +318,21 @@ describe('Kubectl class', () => {
|
||||
],
|
||||
{silent: false}
|
||||
)
|
||||
|
||||
await kubectl.labelFiles(file, labels, otherNamespace)
|
||||
expect(exec.getExecOutput).toBeCalledWith(
|
||||
kubectlPath,
|
||||
[
|
||||
'label',
|
||||
'-f',
|
||||
file,
|
||||
...labels,
|
||||
'--overwrite',
|
||||
'--namespace',
|
||||
otherNamespace
|
||||
],
|
||||
{silent: false}
|
||||
)
|
||||
})
|
||||
|
||||
it('labels files with multiple files', async () => {
|
||||
@@ -245,6 +353,21 @@ describe('Kubectl class', () => {
|
||||
],
|
||||
{silent: false}
|
||||
)
|
||||
|
||||
await kubectl.labelFiles(files, labels, otherNamespace)
|
||||
expect(exec.getExecOutput).toBeCalledWith(
|
||||
kubectlPath,
|
||||
[
|
||||
'label',
|
||||
'-f',
|
||||
files.join(','),
|
||||
...labels,
|
||||
'--overwrite',
|
||||
'--namespace',
|
||||
otherNamespace
|
||||
],
|
||||
{silent: false}
|
||||
)
|
||||
})
|
||||
|
||||
it('gets all pods', async () => {
|
||||
@@ -273,6 +396,20 @@ describe('Kubectl class', () => {
|
||||
],
|
||||
{silent: false}
|
||||
)
|
||||
|
||||
// override ns
|
||||
await kubectl.checkRolloutStatus(resourceType, name, otherNamespace)
|
||||
expect(exec.getExecOutput).toBeCalledWith(
|
||||
kubectlPath,
|
||||
[
|
||||
'rollout',
|
||||
'status',
|
||||
`${resourceType}/${name}`,
|
||||
'--namespace',
|
||||
otherNamespace
|
||||
],
|
||||
{silent: false}
|
||||
)
|
||||
})
|
||||
|
||||
it('gets resource', async () => {
|
||||
@@ -291,6 +428,22 @@ describe('Kubectl class', () => {
|
||||
],
|
||||
{silent: false}
|
||||
)
|
||||
|
||||
// override ns
|
||||
const silent = true
|
||||
await kubectl.getResource(resourceType, name, silent, otherNamespace)
|
||||
expect(exec.getExecOutput).toBeCalledWith(
|
||||
kubectlPath,
|
||||
[
|
||||
'get',
|
||||
`${resourceType}/${name}`,
|
||||
'-o',
|
||||
'json',
|
||||
'--namespace',
|
||||
otherNamespace
|
||||
],
|
||||
{silent}
|
||||
)
|
||||
})
|
||||
|
||||
it('executes a command', async () => {
|
||||
@@ -321,6 +474,14 @@ describe('Kubectl class', () => {
|
||||
['delete', arg, '--namespace', testNamespace],
|
||||
{silent: false}
|
||||
)
|
||||
|
||||
// override ns
|
||||
await kubectl.delete(arg, otherNamespace)
|
||||
expect(exec.getExecOutput).toBeCalledWith(
|
||||
kubectlPath,
|
||||
['delete', arg, '--namespace', otherNamespace],
|
||||
{silent: false}
|
||||
)
|
||||
})
|
||||
|
||||
it('deletes with multiple arguments', async () => {
|
||||
@@ -331,6 +492,14 @@ describe('Kubectl class', () => {
|
||||
['delete', ...args, '--namespace', testNamespace],
|
||||
{silent: false}
|
||||
)
|
||||
|
||||
// override ns
|
||||
await kubectl.delete(args, otherNamespace)
|
||||
expect(exec.getExecOutput).toBeCalledWith(
|
||||
kubectlPath,
|
||||
['delete', ...args, '--namespace', otherNamespace],
|
||||
{silent: false}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -369,5 +538,11 @@ describe('Kubectl class', () => {
|
||||
[command, '--insecure-skip-tls-verify', '--namespace', testNamespace],
|
||||
{silent: false}
|
||||
)
|
||||
|
||||
const kubectlNoFlags = new Kubectl(kubectlPath)
|
||||
kubectlNoFlags.executeCommand(command)
|
||||
expect(exec.getExecOutput).toBeCalledWith(kubectlPath, [command], {
|
||||
silent: false
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
+60
-34
@@ -3,11 +3,11 @@ import {createInlineArray} from '../utilities/arrayUtils'
|
||||
import * as core from '@actions/core'
|
||||
import * as toolCache from '@actions/tool-cache'
|
||||
import * as io from '@actions/io'
|
||||
import {exec} from 'child_process'
|
||||
|
||||
export interface Resource {
|
||||
name: string
|
||||
type: string
|
||||
namespace?: string
|
||||
}
|
||||
|
||||
export class Kubectl {
|
||||
@@ -20,7 +20,7 @@ export class Kubectl {
|
||||
|
||||
constructor(
|
||||
kubectlPath: string,
|
||||
namespace: string = 'default',
|
||||
namespace: string = '',
|
||||
ignoreSSLErrors: boolean = false,
|
||||
resourceGroup: string = '',
|
||||
name: string = ''
|
||||
@@ -47,7 +47,7 @@ export class Kubectl {
|
||||
]
|
||||
if (force) applyArgs.push('--force')
|
||||
|
||||
return await this.execute(applyArgs)
|
||||
return await this.execute(applyArgs.concat(this.getFlags()))
|
||||
} catch (err) {
|
||||
core.debug('Kubectl apply failed:' + err)
|
||||
}
|
||||
@@ -56,27 +56,43 @@ export class Kubectl {
|
||||
public async describe(
|
||||
resourceType: string,
|
||||
resourceName: string,
|
||||
silent: boolean = false
|
||||
silent: boolean = false,
|
||||
namespace?: string
|
||||
): Promise<ExecOutput> {
|
||||
return await this.execute(
|
||||
['describe', resourceType, resourceName],
|
||||
['describe', resourceType, resourceName].concat(
|
||||
this.getFlags(namespace)
|
||||
),
|
||||
silent
|
||||
)
|
||||
}
|
||||
|
||||
public async getNewReplicaSet(deployment: string) {
|
||||
const result = await this.describe('deployment', deployment, true)
|
||||
public async getNewReplicaSet(deployment: string, namespace?: string) {
|
||||
const result = await this.describe(
|
||||
'deployment',
|
||||
deployment,
|
||||
true,
|
||||
namespace
|
||||
)
|
||||
|
||||
let newReplicaSet = ''
|
||||
if (result?.stdout) {
|
||||
const stdout = result.stdout.split('\n')
|
||||
core.debug('stdout from getNewReplicaSet is ' + JSON.stringify(stdout))
|
||||
stdout.forEach((line: string) => {
|
||||
const newreplicaset = 'newreplicaset'
|
||||
if (line && line.toLowerCase().indexOf(newreplicaset) > -1)
|
||||
if (line && line.toLowerCase().indexOf(newreplicaset) > -1) {
|
||||
core.debug(
|
||||
`found string of interest for replicaset, line is ${line}`
|
||||
)
|
||||
core.debug(
|
||||
`substring is ${line.substring(newreplicaset.length).trim()}`
|
||||
)
|
||||
newReplicaSet = line
|
||||
.substring(newreplicaset.length)
|
||||
.trim()
|
||||
.split(' ')[0]
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -86,7 +102,8 @@ export class Kubectl {
|
||||
public async annotate(
|
||||
resourceType: string,
|
||||
resourceName: string,
|
||||
annotation: string
|
||||
annotation: string,
|
||||
namespace?: string
|
||||
): Promise<ExecOutput> {
|
||||
const args = [
|
||||
'annotate',
|
||||
@@ -94,13 +111,14 @@ export class Kubectl {
|
||||
resourceName,
|
||||
annotation,
|
||||
'--overwrite'
|
||||
]
|
||||
].concat(this.getFlags(namespace))
|
||||
return await this.execute(args)
|
||||
}
|
||||
|
||||
public async annotateFiles(
|
||||
files: string | string[],
|
||||
annotation: string
|
||||
annotation: string,
|
||||
namespace?: string
|
||||
): Promise<ExecOutput> {
|
||||
const filesToAnnotate = createInlineArray(files)
|
||||
core.debug(`annotating ${filesToAnnotate} with annotation ${annotation}`)
|
||||
@@ -110,16 +128,14 @@ export class Kubectl {
|
||||
filesToAnnotate,
|
||||
annotation,
|
||||
'--overwrite'
|
||||
]
|
||||
core.debug(
|
||||
`sending args from annotate to execute: ${JSON.stringify(args)}`
|
||||
)
|
||||
].concat(this.getFlags(namespace))
|
||||
return await this.execute(args)
|
||||
}
|
||||
|
||||
public async labelFiles(
|
||||
files: string | string[],
|
||||
labels: string[]
|
||||
labels: string[],
|
||||
namespace?: string
|
||||
): Promise<ExecOutput> {
|
||||
const args = [
|
||||
'label',
|
||||
@@ -127,51 +143,59 @@ export class Kubectl {
|
||||
createInlineArray(files),
|
||||
...labels,
|
||||
'--overwrite'
|
||||
]
|
||||
].concat(this.getFlags(namespace))
|
||||
return await this.execute(args)
|
||||
}
|
||||
|
||||
public async getAllPods(): Promise<ExecOutput> {
|
||||
return await this.execute(['get', 'pods', '-o', 'json'], true)
|
||||
return await this.execute(
|
||||
['get', 'pods', '-o', 'json'].concat(this.getFlags()),
|
||||
true
|
||||
)
|
||||
}
|
||||
|
||||
public async checkRolloutStatus(
|
||||
resourceType: string,
|
||||
name: string
|
||||
name: string,
|
||||
namespace?: string
|
||||
): Promise<ExecOutput> {
|
||||
return await this.execute([
|
||||
'rollout',
|
||||
'status',
|
||||
`${resourceType}/${name}`
|
||||
])
|
||||
return await this.execute(
|
||||
['rollout', 'status', `${resourceType}/${name}`].concat(
|
||||
this.getFlags(namespace)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
public async getResource(
|
||||
resourceType: string,
|
||||
name: string,
|
||||
silentFailure: boolean = false
|
||||
silentFailure: boolean = false,
|
||||
namespace?: string
|
||||
): Promise<ExecOutput> {
|
||||
core.debug(
|
||||
'fetching resource of type ' + resourceType + ' and name ' + name
|
||||
)
|
||||
return await this.execute(
|
||||
['get', `${resourceType}/${name}`, '-o', 'json'],
|
||||
['get', `${resourceType}/${name}`, '-o', 'json'].concat(
|
||||
this.getFlags(namespace)
|
||||
),
|
||||
silentFailure
|
||||
)
|
||||
}
|
||||
|
||||
public executeCommand(command: string, args?: string) {
|
||||
if (!command) throw new Error('Command must be defined')
|
||||
return args ? this.execute([command, args]) : this.execute([command])
|
||||
const a = args ? [args] : []
|
||||
return this.execute([command, ...a.concat(this.getFlags())])
|
||||
}
|
||||
|
||||
public delete(args: string | string[]) {
|
||||
if (typeof args === 'string') return this.execute(['delete', args])
|
||||
return this.execute(['delete', ...args])
|
||||
public delete(args: string | string[], namespace?: string) {
|
||||
if (typeof args === 'string')
|
||||
return this.execute(['delete', args].concat(this.getFlags(namespace)))
|
||||
return this.execute(['delete', ...args.concat(this.getFlags(namespace))])
|
||||
}
|
||||
|
||||
protected async execute(args: string[], silent: boolean = false) {
|
||||
args = args.concat(this.getExecuteFlags())
|
||||
core.debug(`Kubectl run with command: ${this.kubectlPath} ${args}`)
|
||||
|
||||
return await getExecOutput(this.kubectlPath, args, {
|
||||
@@ -179,13 +203,15 @@ export class Kubectl {
|
||||
})
|
||||
}
|
||||
|
||||
protected getExecuteFlags(): string[] {
|
||||
protected getFlags(namespaceOverride?: string): string[] {
|
||||
const flags = []
|
||||
if (this.ignoreSSLErrors) {
|
||||
flags.push('--insecure-skip-tls-verify')
|
||||
}
|
||||
if (this.namespace) {
|
||||
flags.push('--namespace', this.namespace)
|
||||
|
||||
const ns = namespaceOverride || this.namespace
|
||||
if (ns) {
|
||||
flags.push('--namespace', ns)
|
||||
}
|
||||
|
||||
return flags
|
||||
|
||||
@@ -1,12 +1,32 @@
|
||||
import {PrivateKubectl} from './privatekubectl'
|
||||
import * as exec from '@actions/exec'
|
||||
|
||||
describe('Private kubectl', () => {
|
||||
const testString = `kubectl annotate -f test.yml,test2.yml,test3.yml -f test4.yml --filename test5.yml actions.github.com/k8s-deploy={"run":"3498366832","repository":"jaiveerk/k8s-deploy","workflow":"Minikube Integration Tests - private cluster","workflowFileName":"run-integration-tests-private.yml","jobName":"run-integration-test","createdBy":"jaiveerk","runUri":"https://github.com/jaiveerk/k8s-deploy/actions/runs/3498366832","commit":"c63b323186ea1320a31290de6dcc094c06385e75","lastSuccessRunCommit":"NA","branch":"refs/heads/main","deployTimestamp":1668787848577,"dockerfilePaths":{"nginx:1.14.2":""},"manifestsPaths":["https://github.com/jaiveerk/k8s-deploy/blob/c63b323186ea1320a31290de6dcc094c06385e75/test/integration/manifests/test.yml"],"helmChartPaths":[],"provider":"GitHub"} --overwrite --namespace test-3498366832`
|
||||
const mockKube = new PrivateKubectl('')
|
||||
const mockKube = new PrivateKubectl(
|
||||
'kubectlPath',
|
||||
'namespace',
|
||||
true,
|
||||
'resourceGroup',
|
||||
'resourceName'
|
||||
)
|
||||
|
||||
it('should extract filenames correctly', () => {
|
||||
expect(mockKube.extractFilesnames(testString)).toEqual(
|
||||
'test.yml test2.yml test3.yml test4.yml test5.yml'
|
||||
)
|
||||
})
|
||||
|
||||
test('Should throw well defined Error on error from Azure', async () => {
|
||||
const errorMsg = 'An error message'
|
||||
jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => {
|
||||
return {exitCode: 1, stdout: '', stderr: errorMsg}
|
||||
})
|
||||
|
||||
await expect(mockKube.executeCommand('az', 'test')).rejects.toThrow(
|
||||
Error(
|
||||
`Call to private cluster failed. Command: 'kubectl az test --insecure-skip-tls-verify --namespace namespace', errormessage: ${errorMsg}`
|
||||
)
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -8,8 +8,6 @@ import * as path from 'path'
|
||||
|
||||
export class PrivateKubectl extends Kubectl {
|
||||
protected async execute(args: string[], silent: boolean = false) {
|
||||
args = args.concat(this.getExecuteFlags())
|
||||
|
||||
args.unshift('kubectl')
|
||||
let kubectlCmd = args.join(' ')
|
||||
let addFileFlag = false
|
||||
@@ -75,11 +73,18 @@ export class PrivateKubectl extends Kubectl {
|
||||
runOutput
|
||||
)}`
|
||||
)
|
||||
|
||||
if (runOutput.exitCode !== 0) {
|
||||
throw Error(
|
||||
`Call to private cluster failed. Command: '${kubectlCmd}', errormessage: ${runOutput.stderr}`
|
||||
)
|
||||
}
|
||||
|
||||
const runObj: {logs: string; exitCode: number} = JSON.parse(
|
||||
runOutput.stdout
|
||||
)
|
||||
if (!silent) core.info(runObj.logs)
|
||||
if (runOutput.exitCode !== 0 && runObj.exitCode !== 0) {
|
||||
if (runObj.exitCode !== 0) {
|
||||
throw Error(`failed private cluster Kubectl command: ${kubectlCmd}`)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ import * as core from '@actions/core'
|
||||
import {ExecOutput} from '@actions/exec'
|
||||
import {Kubectl} from '../types/kubectl'
|
||||
|
||||
const NAMESPACE = 'namespace'
|
||||
|
||||
export function checkForErrors(
|
||||
execResults: ExecOutput[],
|
||||
warnIfError?: boolean
|
||||
@@ -30,7 +32,12 @@ export async function getLastSuccessfulRunSha(
|
||||
annotationKey: string
|
||||
): Promise<string> {
|
||||
try {
|
||||
const result = await kubectl.getResource('namespace', namespaceName)
|
||||
const result = await kubectl.getResource(
|
||||
NAMESPACE,
|
||||
namespaceName,
|
||||
false,
|
||||
namespaceName
|
||||
)
|
||||
if (result?.stderr) {
|
||||
core.warning(result.stderr)
|
||||
return process.env.GITHUB_SHA
|
||||
@@ -53,12 +60,13 @@ export async function annotateChildPods(
|
||||
kubectl: Kubectl,
|
||||
resourceType: string,
|
||||
resourceName: string,
|
||||
namespace: string | undefined,
|
||||
annotationKeyValStr: string,
|
||||
allPods
|
||||
): Promise<ExecOutput[]> {
|
||||
let owner = resourceName
|
||||
if (resourceType.toLowerCase().indexOf('deployment') > -1) {
|
||||
owner = await kubectl.getNewReplicaSet(resourceName)
|
||||
owner = await kubectl.getNewReplicaSet(resourceName, namespace)
|
||||
}
|
||||
|
||||
const commandExecutionResults = []
|
||||
@@ -72,7 +80,8 @@ export async function annotateChildPods(
|
||||
kubectl.annotate(
|
||||
'pod',
|
||||
pod.metadata.name,
|
||||
annotationKeyValStr
|
||||
annotationKeyValStr,
|
||||
namespace
|
||||
)
|
||||
)
|
||||
break
|
||||
|
||||
@@ -4,6 +4,9 @@ import {Kubectl, Resource} from '../types/kubectl'
|
||||
import {checkForErrors} from './kubectlUtils'
|
||||
import {sleep} from './timeUtils'
|
||||
|
||||
const IS_SILENT = false
|
||||
const POD = 'pod'
|
||||
|
||||
export async function checkManifestStability(
|
||||
kubectl: Kubectl,
|
||||
resources: Resource[]
|
||||
@@ -20,24 +23,35 @@ export async function checkManifestStability(
|
||||
try {
|
||||
const result = await kubectl.checkRolloutStatus(
|
||||
resource.type,
|
||||
resource.name
|
||||
resource.name,
|
||||
resource.namespace
|
||||
)
|
||||
checkForErrors([result])
|
||||
} catch (ex) {
|
||||
core.error(ex)
|
||||
await kubectl.describe(resource.type, resource.name)
|
||||
await kubectl.describe(
|
||||
resource.type,
|
||||
resource.name,
|
||||
IS_SILENT,
|
||||
resource.namespace
|
||||
)
|
||||
rolloutStatusHasErrors = true
|
||||
}
|
||||
}
|
||||
|
||||
if (resource.type == KubernetesConstants.KubernetesWorkload.POD) {
|
||||
try {
|
||||
await checkPodStatus(kubectl, resource.name)
|
||||
await checkPodStatus(kubectl, resource)
|
||||
} catch (ex) {
|
||||
core.warning(
|
||||
`Could not determine pod status: ${JSON.stringify(ex)}`
|
||||
)
|
||||
await kubectl.describe(resource.type, resource.name)
|
||||
await kubectl.describe(
|
||||
resource.type,
|
||||
resource.name,
|
||||
IS_SILENT,
|
||||
resource.namespace
|
||||
)
|
||||
}
|
||||
}
|
||||
if (
|
||||
@@ -45,14 +59,11 @@ export async function checkManifestStability(
|
||||
KubernetesConstants.DiscoveryAndLoadBalancerResource.SERVICE
|
||||
) {
|
||||
try {
|
||||
const service = await getService(kubectl, resource.name)
|
||||
const service = await getService(kubectl, resource)
|
||||
const {spec, status} = service
|
||||
if (spec.type === KubernetesConstants.ServiceTypes.LOAD_BALANCER) {
|
||||
if (!isLoadBalancerIPAssigned(status)) {
|
||||
await waitForServiceExternalIPAssignment(
|
||||
kubectl,
|
||||
resource.name
|
||||
)
|
||||
await waitForServiceExternalIPAssignment(kubectl, resource)
|
||||
} else {
|
||||
core.info(
|
||||
`ServiceExternalIP ${resource.name} ${status.loadBalancer.ingress[0].ip}`
|
||||
@@ -63,7 +74,12 @@ export async function checkManifestStability(
|
||||
core.warning(
|
||||
`Could not determine service status of: ${resource.name} Error: ${ex}`
|
||||
)
|
||||
await kubectl.describe(resource.type, resource.name)
|
||||
await kubectl.describe(
|
||||
resource.type,
|
||||
resource.name,
|
||||
IS_SILENT,
|
||||
resource.namespace
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,7 +91,7 @@ export async function checkManifestStability(
|
||||
|
||||
export async function checkPodStatus(
|
||||
kubectl: Kubectl,
|
||||
podName: string
|
||||
pod: Resource
|
||||
): Promise<void> {
|
||||
const sleepTimeout = 10 * 1000 // 10 seconds
|
||||
const iterations = 60 // 60 * 10 seconds timeout = 10 minutes max timeout
|
||||
@@ -85,8 +101,8 @@ export async function checkPodStatus(
|
||||
for (let i = 0; i < iterations; i++) {
|
||||
await sleep(sleepTimeout)
|
||||
|
||||
core.debug(`Polling for pod status: ${podName}`)
|
||||
podStatus = await getPodStatus(kubectl, podName)
|
||||
core.debug(`Polling for pod status: ${pod.name}`)
|
||||
podStatus = await getPodStatus(kubectl, pod)
|
||||
|
||||
if (
|
||||
podStatus &&
|
||||
@@ -97,37 +113,42 @@ export async function checkPodStatus(
|
||||
}
|
||||
}
|
||||
|
||||
podStatus = await getPodStatus(kubectl, podName)
|
||||
podStatus = await getPodStatus(kubectl, pod)
|
||||
switch (podStatus.phase) {
|
||||
case 'Succeeded':
|
||||
case 'Running':
|
||||
if (isPodReady(podStatus)) {
|
||||
console.log(`pod/${podName} is successfully rolled out`)
|
||||
console.log(`pod/${pod.name} is successfully rolled out`)
|
||||
} else {
|
||||
kubectlDescribeNeeded = true
|
||||
}
|
||||
break
|
||||
case 'Pending':
|
||||
if (!isPodReady(podStatus)) {
|
||||
core.warning(`pod/${podName} rollout status check timed out`)
|
||||
core.warning(`pod/${pod.name} rollout status check timed out`)
|
||||
kubectlDescribeNeeded = true
|
||||
}
|
||||
break
|
||||
case 'Failed':
|
||||
core.error(`pod/${podName} rollout failed`)
|
||||
core.error(`pod/${pod.name} rollout failed`)
|
||||
kubectlDescribeNeeded = true
|
||||
break
|
||||
default:
|
||||
core.warning(`pod/${podName} rollout status: ${podStatus.phase}`)
|
||||
core.warning(`pod/${pod.name} rollout status: ${podStatus.phase}`)
|
||||
}
|
||||
|
||||
if (kubectlDescribeNeeded) {
|
||||
await kubectl.describe('pod', podName)
|
||||
await kubectl.describe(POD, pod.name, IS_SILENT, pod.namespace)
|
||||
}
|
||||
}
|
||||
|
||||
async function getPodStatus(kubectl: Kubectl, podName: string) {
|
||||
const podResult = await kubectl.getResource('pod', podName)
|
||||
async function getPodStatus(kubectl: Kubectl, pod: Resource) {
|
||||
const podResult = await kubectl.getResource(
|
||||
POD,
|
||||
pod.name,
|
||||
IS_SILENT,
|
||||
pod.namespace
|
||||
)
|
||||
checkForErrors([podResult])
|
||||
|
||||
return JSON.parse(podResult.stdout).status
|
||||
@@ -151,10 +172,12 @@ function isPodReady(podStatus: any): boolean {
|
||||
return allContainersAreReady
|
||||
}
|
||||
|
||||
async function getService(kubectl: Kubectl, serviceName) {
|
||||
async function getService(kubectl: Kubectl, service: Resource) {
|
||||
const serviceResult = await kubectl.getResource(
|
||||
KubernetesConstants.DiscoveryAndLoadBalancerResource.SERVICE,
|
||||
serviceName
|
||||
service.name,
|
||||
IS_SILENT,
|
||||
service.namespace
|
||||
)
|
||||
|
||||
checkForErrors([serviceResult])
|
||||
@@ -163,25 +186,25 @@ async function getService(kubectl: Kubectl, serviceName) {
|
||||
|
||||
async function waitForServiceExternalIPAssignment(
|
||||
kubectl: Kubectl,
|
||||
serviceName: string
|
||||
service: Resource
|
||||
): Promise<void> {
|
||||
const sleepTimeout = 10 * 1000 // 10 seconds
|
||||
const iterations = 18 // 18 * 10 seconds timeout = 3 minutes max timeout
|
||||
|
||||
for (let i = 0; i < iterations; i++) {
|
||||
core.info(`Wait for service ip assignment : ${serviceName}`)
|
||||
core.info(`Wait for service ip assignment : ${service.name}`)
|
||||
await sleep(sleepTimeout)
|
||||
|
||||
const status = (await getService(kubectl, serviceName)).status
|
||||
const status = (await getService(kubectl, service)).status
|
||||
if (isLoadBalancerIPAssigned(status)) {
|
||||
core.info(
|
||||
`ServiceExternalIP ${serviceName} ${status.loadBalancer.ingress[0].ip}`
|
||||
`ServiceExternalIP ${service.name} ${status.loadBalancer.ingress[0].ip}`
|
||||
)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
core.warning(`Wait for service ip assignment timed out${serviceName}`)
|
||||
core.warning(`Wait for service ip assignment timed out ${service.name}`)
|
||||
}
|
||||
|
||||
function isLoadBalancerIPAssigned(status: any) {
|
||||
|
||||
@@ -280,7 +280,8 @@ export function getResources(
|
||||
) {
|
||||
resources.push({
|
||||
type: inputObject.kind,
|
||||
name: inputObject.metadata.name
|
||||
name: inputObject.metadata.name,
|
||||
namespace: inputObject?.metadata?.namespace
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import {cleanLabel} from '../utilities/workflowAnnotationUtils'
|
||||
import {
|
||||
cleanLabel,
|
||||
removeInvalidLabelCharacters,
|
||||
VALID_LABEL_REGEX
|
||||
} from '../utilities/workflowAnnotationUtils'
|
||||
|
||||
describe('WorkflowAnnotationUtils', () => {
|
||||
describe('cleanLabel', () => {
|
||||
@@ -16,5 +20,14 @@ describe('WorkflowAnnotationUtils', () => {
|
||||
cleanLabel('Workflow Name / With Slashes / And Spaces')
|
||||
).toEqual('Workflow_Name_-_With_Slashes_-_And_Spaces')
|
||||
})
|
||||
it('should return a blank string when regex fails (https://github.com/Azure/k8s-deploy/issues/266)', () => {
|
||||
const label = '持续部署'
|
||||
expect(cleanLabel(label)).toEqual('github-workflow-file')
|
||||
|
||||
let removedInvalidChars = removeInvalidLabelCharacters(label)
|
||||
|
||||
const regexResult = VALID_LABEL_REGEX.exec(removedInvalidChars)
|
||||
expect(regexResult).toBe(null)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -2,6 +2,8 @@ import {DeploymentConfig} from '../types/deploymentConfig'
|
||||
|
||||
const ANNOTATION_PREFIX = 'actions.github.com'
|
||||
|
||||
export const VALID_LABEL_REGEX = /([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]/
|
||||
|
||||
export function getWorkflowAnnotations(
|
||||
lastSuccessRunSha: string,
|
||||
workflowFilePath: string,
|
||||
@@ -37,11 +39,17 @@ export function getWorkflowAnnotationKeyLabel(): string {
|
||||
* @returns cleaned label
|
||||
*/
|
||||
export function cleanLabel(label: string): string {
|
||||
let removedInvalidChars = label
|
||||
let removedInvalidChars = removeInvalidLabelCharacters(label)
|
||||
|
||||
const regexResult = VALID_LABEL_REGEX.exec(removedInvalidChars) || [
|
||||
'github-workflow-file'
|
||||
]
|
||||
return regexResult[0]
|
||||
}
|
||||
|
||||
export function removeInvalidLabelCharacters(label: string): string {
|
||||
return label
|
||||
.replace(/\s/gi, '_')
|
||||
.replace(/[\/\\\|]/gi, '-')
|
||||
.replace(/[^-A-Za-z0-9_.]/gi, '')
|
||||
|
||||
const regex = /([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]/
|
||||
return regex.exec(removedInvalidChars)[0] || ''
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user