added blue green strategy (#47)

* added blue green strategy

* Addressed review comments

* addressed pr comments

* updated names in test

* addressed final pr comments
This commit is contained in:
Sundar
2020-07-13 08:59:05 +05:30
committed by GitHub
parent c9b54fdae2
commit b4bc3003e8
26 changed files with 2893 additions and 175 deletions
+54 -7
View File
@@ -1,22 +1,35 @@
'use strict';
import * as core from '@actions/core';
import * as deploymentHelper from '../utilities/strategy-helpers/deployment-helper';
import * as canaryDeploymentHelper from '../utilities/strategy-helpers/canary-deployment-helper';
import * as SMICanaryDeploymentHelper from '../utilities/strategy-helpers/smi-canary-deployment-helper';
import * as utils from '../utilities/manifest-utilities';
import * as TaskInputParameters from '../input-parameters';
import { getUpdatedManifestFiles } from '../utilities/manifest-utilities'
import * as KubernetesObjectUtility from '../utilities/resource-object-utility';
import * as models from '../constants';
import * as KubernetesManifestUtility from '../utilities/manifest-stability-utility';
import { getManifestObjects, deleteWorkloadsWithLabel, deleteWorkloadsAndServicesWithLabel } from '../utilities/strategy-helpers/blue-green-helper';
import { isBlueGreenDeploymentStrategy, isIngressRoute, isSMIRoute, GREEN_LABEL_VALUE, NONE_LABEL_VALUE } from '../utilities/strategy-helpers/blue-green-helper';
import { routeBlueGreenService, promoteBlueGreenService } from '../utilities/strategy-helpers/service-blue-green-helper';
import { routeBlueGreenIngress, promoteBlueGreenIngress } from '../utilities/strategy-helpers/ingress-blue-green-helper';
import { routeBlueGreenSMI, promoteBlueGreenSMI, cleanupSMI } from '../utilities/strategy-helpers/smi-blue-green-helper';
import { Kubectl, Resource } from '../kubectl-object-model';
import { Kubectl } from '../kubectl-object-model';
export async function promote() {
const kubectl = new Kubectl(await utils.getKubectl(), TaskInputParameters.namespace, true);
export async function promote(ignoreSslErrors?: boolean) {
const kubectl = new Kubectl(await utils.getKubectl(), TaskInputParameters.namespace, ignoreSslErrors);
if (!canaryDeploymentHelper.isCanaryDeploymentStrategy()) {
core.debug('Strategy is not canary deployment. Invalid request.');
if (canaryDeploymentHelper.isCanaryDeploymentStrategy()) {
await promoteCanary(kubectl);
} else if (isBlueGreenDeploymentStrategy()) {
await promoteBlueGreen(kubectl);
} else {
core.debug('Strategy is not canary or blue-green deployment. Invalid request.');
throw ('InvalidPromotetActionDeploymentStrategy');
}
}
async function promoteCanary(kubectl: Kubectl) {
let includeServices = false;
if (canaryDeploymentHelper.isSMICanaryStrategy()) {
includeServices = true;
@@ -41,4 +54,38 @@ export async function promote(ignoreSslErrors?: boolean) {
} catch (ex) {
core.warning('Exception occurred while deleting canary and baseline workloads. Exception: ' + ex);
}
}
async function promoteBlueGreen(kubectl: Kubectl) {
// updated container images and pull secrets
let inputManifestFiles: string[] = getUpdatedManifestFiles(TaskInputParameters.manifests);
const manifestObjects = getManifestObjects(inputManifestFiles);
core.debug('deleting old deployment and making new ones');
let result;
if(isIngressRoute()) {
result = await promoteBlueGreenIngress(kubectl, manifestObjects);
} else if (isSMIRoute()) {
result = await promoteBlueGreenSMI(kubectl, manifestObjects);
} else {
result = await promoteBlueGreenService(kubectl, manifestObjects);
}
// checking stability of newly created deployments
const deployedManifestFiles = result.newFilePaths;
const resources: Resource[] = KubernetesObjectUtility.getResources(deployedManifestFiles, models.deploymentTypes.concat([models.DiscoveryAndLoadBalancerResource.service]));
await KubernetesManifestUtility.checkManifestStability(kubectl, resources);
core.debug('routing to new deployments');
if(isIngressRoute()) {
routeBlueGreenIngress(kubectl, null, manifestObjects.serviceNameMap, manifestObjects.serviceEntityList, manifestObjects.ingressEntityList);
deleteWorkloadsAndServicesWithLabel(kubectl, GREEN_LABEL_VALUE, manifestObjects.deploymentEntityList, manifestObjects.serviceEntityList);
} else if (isSMIRoute()) {
routeBlueGreenSMI(kubectl, NONE_LABEL_VALUE, manifestObjects.deploymentEntityList, manifestObjects.serviceEntityList);
deleteWorkloadsWithLabel(kubectl, GREEN_LABEL_VALUE, manifestObjects.deploymentEntityList);
cleanupSMI(kubectl, manifestObjects.deploymentEntityList, manifestObjects.serviceEntityList);
} else {
routeBlueGreenService(kubectl, NONE_LABEL_VALUE, manifestObjects.deploymentEntityList, manifestObjects.serviceEntityList);
deleteWorkloadsWithLabel(kubectl, GREEN_LABEL_VALUE, manifestObjects.deploymentEntityList);
}
}
+27 -5
View File
@@ -5,15 +5,26 @@ import * as SMICanaryDeploymentHelper from '../utilities/strategy-helpers/smi-ca
import { Kubectl } from '../kubectl-object-model';
import * as utils from '../utilities/manifest-utilities';
import * as TaskInputParameters from '../input-parameters';
import { rejectBlueGreenService } from '../utilities/strategy-helpers/service-blue-green-helper';
import { rejectBlueGreenIngress } from '../utilities/strategy-helpers/ingress-blue-green-helper';
import { rejectBlueGreenSMI } from '../utilities/strategy-helpers/smi-blue-green-helper'
import { isSMIRoute, isIngressRoute, isBlueGreenDeploymentStrategy } from '../utilities/strategy-helpers/blue-green-helper'
import { getManifestFiles } from '../utilities/strategy-helpers/deployment-helper'
export async function reject(ignoreSslErrors?: boolean) {
const kubectl = new Kubectl(await utils.getKubectl(), TaskInputParameters.namespace, ignoreSslErrors);
export async function reject() {
const kubectl = new Kubectl(await utils.getKubectl(), TaskInputParameters.namespace, true);
if (!canaryDeploymentHelper.isCanaryDeploymentStrategy()) {
core.debug('Strategy is not canary deployment. Invalid request.');
throw ('InvalidRejectActionDeploymentStrategy');
if (canaryDeploymentHelper.isCanaryDeploymentStrategy()) {
await rejectCanary(kubectl);
} else if (isBlueGreenDeploymentStrategy()) {
await rejectBlueGreen(kubectl);
} else {
core.debug('Strategy is not canary or blue-green deployment. Invalid request.');
throw ('InvalidDeletetActionDeploymentStrategy');
}
}
async function rejectCanary(kubectl: Kubectl) {
let includeServices = false;
if (canaryDeploymentHelper.isSMICanaryStrategy()) {
core.debug('Reject deployment with SMI canary strategy');
@@ -23,4 +34,15 @@ export async function reject(ignoreSslErrors?: boolean) {
core.debug('Deployment strategy selected is Canary. Deleting baseline and canary workloads.');
canaryDeploymentHelper.deleteCanaryDeployment(kubectl, TaskInputParameters.manifests, includeServices);
}
async function rejectBlueGreen(kubectl: Kubectl) {
let inputManifestFiles: string[] = getManifestFiles(TaskInputParameters.manifests);
if(isIngressRoute()) {
await rejectBlueGreenIngress(kubectl, inputManifestFiles);
} else if (isSMIRoute()) {
await rejectBlueGreenSMI(kubectl, inputManifestFiles);
} else {
await rejectBlueGreenService(kubectl, inputManifestFiles);
}
}