From 75d14cf7f6e69b7e7de8e779fe0461f1fd4c9d23 Mon Sep 17 00:00:00 2001 From: tauhid621 Date: Tue, 16 Jun 2020 22:15:55 +0530 Subject: [PATCH] Optional force flag added --- action.yml | 4 ++++ lib/actions/promote.js | 1 + lib/actions/reject.js | 1 + lib/constants.js | 1 + lib/input-parameters.js | 2 ++ lib/kubectl-object-model.js | 9 ++++++++- lib/run.js | 1 + lib/utilities/files-helper.js | 1 + lib/utilities/kubectl-util.js | 1 + lib/utilities/manifest-stability-utility.js | 1 + lib/utilities/manifest-utilities.js | 1 + lib/utilities/resource-object-utility.js | 1 + .../strategy-helpers/canary-deployment-helper.js | 1 + lib/utilities/strategy-helpers/deployment-helper.js | 1 + .../strategy-helpers/pod-canary-deployment-helper.js | 1 + .../strategy-helpers/smi-canary-deployment-helper.js | 1 + lib/utilities/string-comparison.js | 1 + lib/utilities/tool-runner.js | 1 + lib/utilities/utility.js | 1 + src/input-parameters.ts | 1 + src/kubectl-object-model.ts | 10 +++++++++- 21 files changed, 40 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 1146e5c1..1d53d10e 100644 --- a/action.yml +++ b/action.yml @@ -41,6 +41,10 @@ inputs: description: 'deploy/promote/reject' required: true default: 'deploy' + force: + description: 'Deploy when a previous deployment already exists' + required: false + default: false branding: color: 'green' # optional, decorates the entry in the GitHub Marketplace diff --git a/lib/actions/promote.js b/lib/actions/promote.js index 2bdf58c9..50e3fd05 100644 --- a/lib/actions/promote.js +++ b/lib/actions/promote.js @@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", { value: true }); +exports.promote = void 0; const core = require("@actions/core"); const deploymentHelper = require("../utilities/strategy-helpers/deployment-helper"); const canaryDeploymentHelper = require("../utilities/strategy-helpers/canary-deployment-helper"); diff --git a/lib/actions/reject.js b/lib/actions/reject.js index d3177ef6..cb0d73ee 100644 --- a/lib/actions/reject.js +++ b/lib/actions/reject.js @@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", { value: true }); +exports.reject = void 0; const core = require("@actions/core"); const canaryDeploymentHelper = require("../utilities/strategy-helpers/canary-deployment-helper"); const SMICanaryDeploymentHelper = require("../utilities/strategy-helpers/smi-canary-deployment-helper"); diff --git a/lib/constants.js b/lib/constants.js index 50919389..8f537d25 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -1,5 +1,6 @@ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); +exports.workloadTypesWithRolloutStatus = exports.workloadTypes = exports.deploymentTypes = exports.ServiceTypes = exports.DiscoveryAndLoadBalancerResource = exports.KubernetesWorkload = void 0; class KubernetesWorkload { } exports.KubernetesWorkload = KubernetesWorkload; diff --git a/lib/input-parameters.js b/lib/input-parameters.js index 63869312..93040606 100644 --- a/lib/input-parameters.js +++ b/lib/input-parameters.js @@ -1,5 +1,6 @@ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); +exports.forceDeployment = exports.args = exports.baselineAndCanaryReplicas = exports.trafficSplitMethod = exports.deploymentStrategy = exports.canaryPercentage = exports.manifests = exports.imagePullSecrets = exports.containers = exports.namespace = void 0; const core = require("@actions/core"); exports.namespace = core.getInput('namespace'); exports.containers = core.getInput('images').split('\n'); @@ -10,6 +11,7 @@ exports.deploymentStrategy = core.getInput('strategy'); exports.trafficSplitMethod = core.getInput('traffic-split-method'); exports.baselineAndCanaryReplicas = core.getInput('baseline-and-canary-replicas'); exports.args = core.getInput('arguments'); +exports.forceDeployment = core.getInput('force').toLowerCase() === 'true'; if (!exports.namespace) { core.debug('Namespace was not supplied; using "default" namespace instead.'); exports.namespace = 'default'; diff --git a/lib/kubectl-object-model.js b/lib/kubectl-object-model.js index 9effab10..425426b9 100644 --- a/lib/kubectl-object-model.js +++ b/lib/kubectl-object-model.js @@ -9,7 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", { value: true }); +exports.Kubectl = void 0; const tool_runner_1 = require("./utilities/tool-runner"); +const TaskInputParameters = require("./input-parameters"); class Kubectl { constructor(kubectlPath, namespace, ignoreSSLErrors) { this.kubectlPath = kubectlPath; @@ -22,7 +24,12 @@ class Kubectl { } } apply(configurationPaths) { - return this.execute(['apply', '-f', this.createInlineArray(configurationPaths)]); + let applyArgs = ['apply', '-f', this.createInlineArray(configurationPaths)]; + if (TaskInputParameters.forceDeployment) { + console.log("force flag is on, deployment will continue even if previous deployment already exists"); + applyArgs.push('--force'); + } + return this.execute(applyArgs); } describe(resourceType, resourceName, silent) { return this.execute(['describe', resourceType, resourceName], silent); diff --git a/lib/run.js b/lib/run.js index 369a0efd..09207bf6 100644 --- a/lib/run.js +++ b/lib/run.js @@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", { value: true }); +exports.run = void 0; const core = require("@actions/core"); const io = require("@actions/io"); const path = require("path"); diff --git a/lib/utilities/files-helper.js b/lib/utilities/files-helper.js index b7cd2754..4b9ecc81 100644 --- a/lib/utilities/files-helper.js +++ b/lib/utilities/files-helper.js @@ -1,5 +1,6 @@ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); +exports.writeManifestToFile = exports.writeObjectsToFile = exports.assertFileExists = exports.ensureDirExists = exports.getNewUserDirPath = exports.getTempDirectory = void 0; const fs = require("fs"); const path = require("path"); const core = require("@actions/core"); diff --git a/lib/utilities/kubectl-util.js b/lib/utilities/kubectl-util.js index 464e088e..a5bbcb63 100644 --- a/lib/utilities/kubectl-util.js +++ b/lib/utilities/kubectl-util.js @@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", { value: true }); +exports.getTrafficSplitAPIVersion = exports.downloadKubectl = exports.getStableKubectlVersion = exports.getkubectlDownloadURL = void 0; const core = require("@actions/core"); const fs = require("fs"); const os = require("os"); diff --git a/lib/utilities/manifest-stability-utility.js b/lib/utilities/manifest-stability-utility.js index c5cd5013..778219a7 100644 --- a/lib/utilities/manifest-stability-utility.js +++ b/lib/utilities/manifest-stability-utility.js @@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", { value: true }); +exports.checkPodStatus = exports.checkManifestStability = void 0; const core = require("@actions/core"); const utils = require("./utility"); const KubernetesConstants = require("../constants"); diff --git a/lib/utilities/manifest-utilities.js b/lib/utilities/manifest-utilities.js index 04f29ff8..0237cdc4 100644 --- a/lib/utilities/manifest-utilities.js +++ b/lib/utilities/manifest-utilities.js @@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", { value: true }); +exports.isWorkloadEntity = exports.updateImagePullSecrets = exports.updateContainerImagesInManifestFiles = exports.substituteImageNameInSpecFile = exports.getDeleteCmdArgs = exports.createKubectlArgs = exports.getKubectl = exports.getManifestFiles = void 0; const core = require("@actions/core"); const kubectlutility = require("./kubectl-util"); const io = require("@actions/io"); diff --git a/lib/utilities/resource-object-utility.js b/lib/utilities/resource-object-utility.js index 14c7f740..ebb7e564 100644 --- a/lib/utilities/resource-object-utility.js +++ b/lib/utilities/resource-object-utility.js @@ -1,5 +1,6 @@ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); +exports.getResources = exports.updateSelectorLabels = exports.updateSpecLabels = exports.updateImageDetails = exports.updateImagePullSecrets = exports.updateObjectLabels = exports.getReplicaCount = exports.isServiceEntity = exports.isWorkloadEntity = exports.isDeploymentEntity = void 0; const fs = require("fs"); const core = require("@actions/core"); const yaml = require("js-yaml"); diff --git a/lib/utilities/strategy-helpers/canary-deployment-helper.js b/lib/utilities/strategy-helpers/canary-deployment-helper.js index d8c5cb91..7df15ce1 100644 --- a/lib/utilities/strategy-helpers/canary-deployment-helper.js +++ b/lib/utilities/strategy-helpers/canary-deployment-helper.js @@ -1,5 +1,6 @@ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); +exports.getStableResourceName = exports.getBaselineResourceName = exports.getCanaryResourceName = exports.isSMICanaryStrategy = exports.isCanaryDeploymentStrategy = exports.fetchResource = exports.fetchCanaryResource = exports.getNewCanaryResource = exports.getNewBaselineResource = exports.getStableResource = exports.isResourceMarkedAsStable = exports.markResourceAsStable = exports.deleteCanaryDeployment = exports.STABLE_LABEL_VALUE = exports.STABLE_SUFFIX = exports.CANARY_LABEL_VALUE = exports.BASELINE_LABEL_VALUE = exports.CANARY_VERSION_LABEL = exports.TRAFFIC_SPLIT_STRATEGY = exports.CANARY_DEPLOYMENT_STRATEGY = void 0; const fs = require("fs"); const yaml = require("js-yaml"); const core = require("@actions/core"); diff --git a/lib/utilities/strategy-helpers/deployment-helper.js b/lib/utilities/strategy-helpers/deployment-helper.js index a880bd9c..a2e242cd 100644 --- a/lib/utilities/strategy-helpers/deployment-helper.js +++ b/lib/utilities/strategy-helpers/deployment-helper.js @@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", { value: true }); +exports.deploy = void 0; const fs = require("fs"); const core = require("@actions/core"); const yaml = require("js-yaml"); diff --git a/lib/utilities/strategy-helpers/pod-canary-deployment-helper.js b/lib/utilities/strategy-helpers/pod-canary-deployment-helper.js index 3a66581a..4e0ae883 100644 --- a/lib/utilities/strategy-helpers/pod-canary-deployment-helper.js +++ b/lib/utilities/strategy-helpers/pod-canary-deployment-helper.js @@ -1,5 +1,6 @@ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); +exports.deployPodCanary = void 0; const core = require("@actions/core"); const fs = require("fs"); const yaml = require("js-yaml"); diff --git a/lib/utilities/strategy-helpers/smi-canary-deployment-helper.js b/lib/utilities/strategy-helpers/smi-canary-deployment-helper.js index 4a871824..fd90abcb 100644 --- a/lib/utilities/strategy-helpers/smi-canary-deployment-helper.js +++ b/lib/utilities/strategy-helpers/smi-canary-deployment-helper.js @@ -1,5 +1,6 @@ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); +exports.redirectTrafficToStableDeployment = exports.redirectTrafficToCanaryDeployment = exports.deploySMICanary = void 0; const core = require("@actions/core"); const fs = require("fs"); const yaml = require("js-yaml"); diff --git a/lib/utilities/string-comparison.js b/lib/utilities/string-comparison.js index 5edaa9aa..9dd1b0a1 100644 --- a/lib/utilities/string-comparison.js +++ b/lib/utilities/string-comparison.js @@ -1,5 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); +exports.isEqual = exports.StringComparer = void 0; var StringComparer; (function (StringComparer) { StringComparer[StringComparer["Ordinal"] = 0] = "Ordinal"; diff --git a/lib/utilities/tool-runner.js b/lib/utilities/tool-runner.js index cd46a5f5..e1ea302e 100644 --- a/lib/utilities/tool-runner.js +++ b/lib/utilities/tool-runner.js @@ -1,5 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); +exports.ToolRunner = void 0; const os = require("os"); const events = require("events"); const child = require("child_process"); diff --git a/lib/utilities/utility.js b/lib/utilities/utility.js index 35b79737..db0543a5 100644 --- a/lib/utilities/utility.js +++ b/lib/utilities/utility.js @@ -1,5 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); +exports.getCurrentTime = exports.getRandomInt = exports.sleep = exports.checkForErrors = exports.isEqual = exports.getExecutableExtension = void 0; const os = require("os"); const core = require("@actions/core"); function getExecutableExtension() { diff --git a/src/input-parameters.ts b/src/input-parameters.ts index da8f73bb..ad0b4a62 100644 --- a/src/input-parameters.ts +++ b/src/input-parameters.ts @@ -11,6 +11,7 @@ export const deploymentStrategy: string = core.getInput('strategy'); export const trafficSplitMethod: string = core.getInput('traffic-split-method'); export const baselineAndCanaryReplicas: string = core.getInput('baseline-and-canary-replicas'); export const args: string = core.getInput('arguments'); +export const forceDeployment: boolean = core.getInput('force').toLowerCase() === 'true'; if (!namespace) { core.debug('Namespace was not supplied; using "default" namespace instead.'); diff --git a/src/kubectl-object-model.ts b/src/kubectl-object-model.ts index 62ec9ced..8b224f10 100644 --- a/src/kubectl-object-model.ts +++ b/src/kubectl-object-model.ts @@ -1,4 +1,5 @@ import { ToolRunner, IExecOptions } from "./utilities/tool-runner"; +import * as TaskInputParameters from './input-parameters'; export interface Resource { name: string; @@ -21,7 +22,14 @@ export class Kubectl { } public apply(configurationPaths: string | string[]) { - return this.execute(['apply', '-f', this.createInlineArray(configurationPaths)]); + let applyArgs: string[] = ['apply', '-f', this.createInlineArray(configurationPaths)]; + + if (TaskInputParameters.forceDeployment) { + console.log("force flag is on, deployment will continue even if previous deployment already exists"); + applyArgs.push('--force'); + } + + return this.execute(applyArgs); } public describe(resourceType: string, resourceName: string, silent?: boolean) {