From d35174fe933aaf403b9c6d8935fb5eb7217facfd Mon Sep 17 00:00:00 2001 From: Ajinkya <11447401+ajinkya599@users.noreply.github.com> Date: Fri, 30 Oct 2020 13:10:27 +0530 Subject: [PATCH] Fixing issues found in bug bash. (#71) --- README.md | 2 +- lib/actions/promote.js | 214 +++++++++--------- .../ingress-blue-green-helper.js | 2 +- .../strategy-helpers/smi-blue-green-helper.js | 2 +- .../ingress-blue-green-helper.ts | 2 +- .../strategy-helpers/smi-blue-green-helper.ts | 2 +- 6 files changed, 112 insertions(+), 112 deletions(-) diff --git a/README.md b/README.md index ae033bbc..4231de2e 100644 --- a/README.md +++ b/README.md @@ -218,7 +218,7 @@ Following are the key capabilities of this action: service.yaml ingress-yml strategy: blue-green - strategy: ingress # should be the same as the value when action was deploy + route-method: ingress # should be the same as the value when action was deploy action: promote # substitute reject if you want to reject ``` diff --git a/lib/actions/promote.js b/lib/actions/promote.js index 582afa72..5eefb292 100644 --- a/lib/actions/promote.js +++ b/lib/actions/promote.js @@ -1,107 +1,107 @@ -'use strict'; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -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"); -const SMICanaryDeploymentHelper = require("../utilities/strategy-helpers/smi-canary-deployment-helper"); -const utils = require("../utilities/manifest-utilities"); -const TaskInputParameters = require("../input-parameters"); -const manifest_utilities_1 = require("../utilities/manifest-utilities"); -const KubernetesObjectUtility = require("../utilities/resource-object-utility"); -const models = require("../constants"); -const KubernetesManifestUtility = require("../utilities/manifest-stability-utility"); -const blue_green_helper_1 = require("../utilities/strategy-helpers/blue-green-helper"); -const blue_green_helper_2 = require("../utilities/strategy-helpers/blue-green-helper"); -const service_blue_green_helper_1 = require("../utilities/strategy-helpers/service-blue-green-helper"); -const ingress_blue_green_helper_1 = require("../utilities/strategy-helpers/ingress-blue-green-helper"); -const smi_blue_green_helper_1 = require("../utilities/strategy-helpers/smi-blue-green-helper"); -const kubectl_object_model_1 = require("../kubectl-object-model"); -function promote() { - return __awaiter(this, void 0, void 0, function* () { - const kubectl = new kubectl_object_model_1.Kubectl(yield utils.getKubectl(), TaskInputParameters.namespace, true); - if (canaryDeploymentHelper.isCanaryDeploymentStrategy()) { - yield promoteCanary(kubectl); - } - else if (blue_green_helper_2.isBlueGreenDeploymentStrategy()) { - yield promoteBlueGreen(kubectl); - } - else { - core.debug('Strategy is not canary or blue-green deployment. Invalid request.'); - throw ('InvalidPromotetActionDeploymentStrategy'); - } - }); -} -exports.promote = promote; -function promoteCanary(kubectl) { - return __awaiter(this, void 0, void 0, function* () { - let includeServices = false; - if (canaryDeploymentHelper.isSMICanaryStrategy()) { - includeServices = true; - // In case of SMI traffic split strategy when deployment is promoted, first we will redirect traffic to - // Canary deployment, then update stable deployment and then redirect traffic to stable deployment - core.debug('Redirecting traffic to canary deployment'); - SMICanaryDeploymentHelper.redirectTrafficToCanaryDeployment(kubectl, TaskInputParameters.manifests); - core.debug('Deploying input manifests with SMI canary strategy'); - yield deploymentHelper.deploy(kubectl, TaskInputParameters.manifests, 'None'); - core.debug('Redirecting traffic to stable deployment'); - SMICanaryDeploymentHelper.redirectTrafficToStableDeployment(kubectl, TaskInputParameters.manifests); - } - else { - core.debug('Deploying input manifests'); - yield deploymentHelper.deploy(kubectl, TaskInputParameters.manifests, 'None'); - } - core.debug('Deployment strategy selected is Canary. Deleting canary and baseline workloads.'); - try { - canaryDeploymentHelper.deleteCanaryDeployment(kubectl, TaskInputParameters.manifests, includeServices); - } - catch (ex) { - core.warning('Exception occurred while deleting canary and baseline workloads. Exception: ' + ex); - } - }); -} -function promoteBlueGreen(kubectl) { - return __awaiter(this, void 0, void 0, function* () { - // updated container images and pull secrets - let inputManifestFiles = manifest_utilities_1.getUpdatedManifestFiles(TaskInputParameters.manifests); - const manifestObjects = blue_green_helper_1.getManifestObjects(inputManifestFiles); - core.debug('deleting old deployment and making new ones'); - let result; - if (blue_green_helper_2.isIngressRoute()) { - result = yield ingress_blue_green_helper_1.promoteBlueGreenIngress(kubectl, manifestObjects); - } - else if (blue_green_helper_2.isSMIRoute()) { - result = yield smi_blue_green_helper_1.promoteBlueGreenSMI(kubectl, manifestObjects); - } - else { - result = yield service_blue_green_helper_1.promoteBlueGreenService(kubectl, manifestObjects); - } - // checking stability of newly created deployments - const deployedManifestFiles = result.newFilePaths; - const resources = KubernetesObjectUtility.getResources(deployedManifestFiles, models.deploymentTypes.concat([models.DiscoveryAndLoadBalancerResource.service])); - yield KubernetesManifestUtility.checkManifestStability(kubectl, resources); - core.debug('routing to new deployments'); - if (blue_green_helper_2.isIngressRoute()) { - ingress_blue_green_helper_1.routeBlueGreenIngress(kubectl, null, manifestObjects.serviceNameMap, manifestObjects.ingressEntityList); - blue_green_helper_1.deleteWorkloadsAndServicesWithLabel(kubectl, blue_green_helper_2.GREEN_LABEL_VALUE, manifestObjects.deploymentEntityList, manifestObjects.serviceEntityList); - } - else if (blue_green_helper_2.isSMIRoute()) { - smi_blue_green_helper_1.routeBlueGreenSMI(kubectl, blue_green_helper_2.NONE_LABEL_VALUE, manifestObjects.serviceEntityList); - blue_green_helper_1.deleteWorkloadsWithLabel(kubectl, blue_green_helper_2.GREEN_LABEL_VALUE, manifestObjects.deploymentEntityList); - smi_blue_green_helper_1.cleanupSMI(kubectl, manifestObjects.serviceEntityList); - } - else { - service_blue_green_helper_1.routeBlueGreenService(kubectl, blue_green_helper_2.NONE_LABEL_VALUE, manifestObjects.serviceEntityList); - blue_green_helper_1.deleteWorkloadsWithLabel(kubectl, blue_green_helper_2.GREEN_LABEL_VALUE, manifestObjects.deploymentEntityList); - } - }); -} +'use strict'; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +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"); +const SMICanaryDeploymentHelper = require("../utilities/strategy-helpers/smi-canary-deployment-helper"); +const utils = require("../utilities/manifest-utilities"); +const TaskInputParameters = require("../input-parameters"); +const manifest_utilities_1 = require("../utilities/manifest-utilities"); +const KubernetesObjectUtility = require("../utilities/resource-object-utility"); +const models = require("../constants"); +const KubernetesManifestUtility = require("../utilities/manifest-stability-utility"); +const blue_green_helper_1 = require("../utilities/strategy-helpers/blue-green-helper"); +const blue_green_helper_2 = require("../utilities/strategy-helpers/blue-green-helper"); +const service_blue_green_helper_1 = require("../utilities/strategy-helpers/service-blue-green-helper"); +const ingress_blue_green_helper_1 = require("../utilities/strategy-helpers/ingress-blue-green-helper"); +const smi_blue_green_helper_1 = require("../utilities/strategy-helpers/smi-blue-green-helper"); +const kubectl_object_model_1 = require("../kubectl-object-model"); +function promote() { + return __awaiter(this, void 0, void 0, function* () { + const kubectl = new kubectl_object_model_1.Kubectl(yield utils.getKubectl(), TaskInputParameters.namespace, true); + if (canaryDeploymentHelper.isCanaryDeploymentStrategy()) { + yield promoteCanary(kubectl); + } + else if (blue_green_helper_2.isBlueGreenDeploymentStrategy()) { + yield promoteBlueGreen(kubectl); + } + else { + core.debug('Strategy is not canary or blue-green deployment. Invalid request.'); + throw ('InvalidPromotetActionDeploymentStrategy'); + } + }); +} +exports.promote = promote; +function promoteCanary(kubectl) { + return __awaiter(this, void 0, void 0, function* () { + let includeServices = false; + if (canaryDeploymentHelper.isSMICanaryStrategy()) { + includeServices = true; + // In case of SMI traffic split strategy when deployment is promoted, first we will redirect traffic to + // Canary deployment, then update stable deployment and then redirect traffic to stable deployment + core.debug('Redirecting traffic to canary deployment'); + SMICanaryDeploymentHelper.redirectTrafficToCanaryDeployment(kubectl, TaskInputParameters.manifests); + core.debug('Deploying input manifests with SMI canary strategy'); + yield deploymentHelper.deploy(kubectl, TaskInputParameters.manifests, 'None'); + core.debug('Redirecting traffic to stable deployment'); + SMICanaryDeploymentHelper.redirectTrafficToStableDeployment(kubectl, TaskInputParameters.manifests); + } + else { + core.debug('Deploying input manifests'); + yield deploymentHelper.deploy(kubectl, TaskInputParameters.manifests, 'None'); + } + core.debug('Deployment strategy selected is Canary. Deleting canary and baseline workloads.'); + try { + canaryDeploymentHelper.deleteCanaryDeployment(kubectl, TaskInputParameters.manifests, includeServices); + } + catch (ex) { + core.warning('Exception occurred while deleting canary and baseline workloads. Exception: ' + ex); + } + }); +} +function promoteBlueGreen(kubectl) { + return __awaiter(this, void 0, void 0, function* () { + // updated container images and pull secrets + let inputManifestFiles = manifest_utilities_1.getUpdatedManifestFiles(TaskInputParameters.manifests); + const manifestObjects = blue_green_helper_1.getManifestObjects(inputManifestFiles); + core.debug('deleting old deployment and making new ones'); + let result; + if (blue_green_helper_2.isIngressRoute()) { + result = yield ingress_blue_green_helper_1.promoteBlueGreenIngress(kubectl, manifestObjects); + } + else if (blue_green_helper_2.isSMIRoute()) { + result = yield smi_blue_green_helper_1.promoteBlueGreenSMI(kubectl, manifestObjects); + } + else { + result = yield service_blue_green_helper_1.promoteBlueGreenService(kubectl, manifestObjects); + } + // checking stability of newly created deployments + const deployedManifestFiles = result.newFilePaths; + const resources = KubernetesObjectUtility.getResources(deployedManifestFiles, models.deploymentTypes.concat([models.DiscoveryAndLoadBalancerResource.service])); + yield KubernetesManifestUtility.checkManifestStability(kubectl, resources); + core.debug('routing to new deployments'); + if (blue_green_helper_2.isIngressRoute()) { + ingress_blue_green_helper_1.routeBlueGreenIngress(kubectl, null, manifestObjects.serviceNameMap, manifestObjects.ingressEntityList); + blue_green_helper_1.deleteWorkloadsAndServicesWithLabel(kubectl, blue_green_helper_2.GREEN_LABEL_VALUE, manifestObjects.deploymentEntityList, manifestObjects.serviceEntityList); + } + else if (blue_green_helper_2.isSMIRoute()) { + smi_blue_green_helper_1.routeBlueGreenSMI(kubectl, blue_green_helper_2.NONE_LABEL_VALUE, manifestObjects.serviceEntityList); + blue_green_helper_1.deleteWorkloadsWithLabel(kubectl, blue_green_helper_2.GREEN_LABEL_VALUE, manifestObjects.deploymentEntityList); + smi_blue_green_helper_1.cleanupSMI(kubectl, manifestObjects.serviceEntityList); + } + else { + service_blue_green_helper_1.routeBlueGreenService(kubectl, blue_green_helper_2.NONE_LABEL_VALUE, manifestObjects.serviceEntityList); + blue_green_helper_1.deleteWorkloadsWithLabel(kubectl, blue_green_helper_2.GREEN_LABEL_VALUE, manifestObjects.deploymentEntityList); + } + }); +} diff --git a/lib/utilities/strategy-helpers/ingress-blue-green-helper.js b/lib/utilities/strategy-helpers/ingress-blue-green-helper.js index 345df7f1..55d36f58 100644 --- a/lib/utilities/strategy-helpers/ingress-blue-green-helper.js +++ b/lib/utilities/strategy-helpers/ingress-blue-green-helper.js @@ -71,7 +71,7 @@ exports.rejectBlueGreenIngress = rejectBlueGreenIngress; function routeBlueGreenIngress(kubectl, nextLabel, serviceNameMap, ingressEntityList) { let newObjectsList = []; if (!nextLabel) { - newObjectsList = newObjectsList.concat(ingressEntityList); + newObjectsList = ingressEntityList.filter(ingress => isIngressRouted(ingress, serviceNameMap)); } else { ingressEntityList.forEach((inputObject) => { diff --git a/lib/utilities/strategy-helpers/smi-blue-green-helper.js b/lib/utilities/strategy-helpers/smi-blue-green-helper.js index 82683621..21fba534 100644 --- a/lib/utilities/strategy-helpers/smi-blue-green-helper.js +++ b/lib/utilities/strategy-helpers/smi-blue-green-helper.js @@ -174,9 +174,9 @@ exports.validateTrafficSplitsState = validateTrafficSplitsState; function cleanupSMI(kubectl, serviceEntityList) { const deleteList = []; serviceEntityList.forEach((serviceObject) => { + deleteList.push({ name: blue_green_helper_1.getBlueGreenResourceName(serviceObject.metadata.name, TRAFFIC_SPLIT_OBJECT_NAME_SUFFIX), kind: TRAFFIC_SPLIT_OBJECT }); deleteList.push({ name: blue_green_helper_1.getBlueGreenResourceName(serviceObject.metadata.name, blue_green_helper_2.GREEN_SUFFIX), kind: serviceObject.kind }); deleteList.push({ name: blue_green_helper_1.getBlueGreenResourceName(serviceObject.metadata.name, blue_green_helper_2.STABLE_SUFFIX), kind: serviceObject.kind }); - deleteList.push({ name: blue_green_helper_1.getBlueGreenResourceName(serviceObject.metadata.name, TRAFFIC_SPLIT_OBJECT_NAME_SUFFIX), kind: TRAFFIC_SPLIT_OBJECT }); }); // deleting all objects blue_green_helper_1.deleteObjects(kubectl, deleteList); diff --git a/src/utilities/strategy-helpers/ingress-blue-green-helper.ts b/src/utilities/strategy-helpers/ingress-blue-green-helper.ts index f36f929a..f57bf664 100644 --- a/src/utilities/strategy-helpers/ingress-blue-green-helper.ts +++ b/src/utilities/strategy-helpers/ingress-blue-green-helper.ts @@ -68,7 +68,7 @@ export async function rejectBlueGreenIngress(kubectl: Kubectl, filePaths: string export function routeBlueGreenIngress(kubectl: Kubectl, nextLabel: string, serviceNameMap: Map, ingressEntityList: any[]) { let newObjectsList = []; if (!nextLabel) { - newObjectsList = newObjectsList.concat(ingressEntityList); + newObjectsList = ingressEntityList.filter(ingress => isIngressRouted(ingress, serviceNameMap)); } else { ingressEntityList.forEach((inputObject) => { if (isIngressRouted(inputObject, serviceNameMap)) { diff --git a/src/utilities/strategy-helpers/smi-blue-green-helper.ts b/src/utilities/strategy-helpers/smi-blue-green-helper.ts index fd77a461..10a376cb 100644 --- a/src/utilities/strategy-helpers/smi-blue-green-helper.ts +++ b/src/utilities/strategy-helpers/smi-blue-green-helper.ts @@ -177,9 +177,9 @@ export function validateTrafficSplitsState(kubectl: Kubectl, serviceEntityList: export function cleanupSMI(kubectl: Kubectl, serviceEntityList: any[]) { const deleteList = []; serviceEntityList.forEach((serviceObject) => { + deleteList.push({ name: getBlueGreenResourceName(serviceObject.metadata.name, TRAFFIC_SPLIT_OBJECT_NAME_SUFFIX), kind: TRAFFIC_SPLIT_OBJECT }); deleteList.push({name: getBlueGreenResourceName(serviceObject.metadata.name, GREEN_SUFFIX), kind: serviceObject.kind}); deleteList.push({name: getBlueGreenResourceName(serviceObject.metadata.name, STABLE_SUFFIX), kind: serviceObject.kind}); - deleteList.push({name: getBlueGreenResourceName(serviceObject.metadata.name, TRAFFIC_SPLIT_OBJECT_NAME_SUFFIX), kind: TRAFFIC_SPLIT_OBJECT}); }); // deleting all objects