Logging changes for deploy

This commit is contained in:
Hariharan Subramanian 2022-06-27 16:33:31 -04:00 committed by GitHub
parent dcd9bc6b1a
commit 8da762e272
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,85 +1,88 @@
import * as core from '@actions/core' import * as core from "@actions/core";
import * as models from '../types/kubernetesTypes' import * as models from "../types/kubernetesTypes";
import * as KubernetesConstants from '../types/kubernetesTypes' import * as KubernetesConstants from "../types/kubernetesTypes";
import {Kubectl, Resource} from '../types/kubectl' import { Kubectl, Resource } from "../types/kubectl";
import { import {
getResources, getResources,
updateManifestFiles updateManifestFiles,
} from '../utilities/manifestUpdateUtils' } from "../utilities/manifestUpdateUtils";
import {routeBlueGreen} from '../strategyHelpers/blueGreen/blueGreenHelper' import { routeBlueGreen } from "../strategyHelpers/blueGreen/blueGreenHelper";
import { import {
annotateAndLabelResources, annotateAndLabelResources,
checkManifestStability, checkManifestStability,
deployManifests deployManifests,
} from '../strategyHelpers/deploymentHelper' } from "../strategyHelpers/deploymentHelper";
import {DeploymentStrategy} from '../types/deploymentStrategy' import { DeploymentStrategy } from "../types/deploymentStrategy";
import {parseTrafficSplitMethod} from '../types/trafficSplitMethod' import { parseTrafficSplitMethod } from "../types/trafficSplitMethod";
import {parseRouteStrategy} from '../types/routeStrategy' import { parseRouteStrategy } from "../types/routeStrategy";
export async function deploy( export async function deploy(
kubectl: Kubectl, kubectl: Kubectl,
manifestFilePaths: string[], manifestFilePaths: string[],
deploymentStrategy: DeploymentStrategy deploymentStrategy: DeploymentStrategy
) { ) {
// update manifests // update manifests
const inputManifestFiles: string[] = updateManifestFiles(manifestFilePaths) const inputManifestFiles: string[] = updateManifestFiles(manifestFilePaths);
core.debug('Input manifest files: ' + inputManifestFiles) core.debug("Input manifest files: " + inputManifestFiles);
// deploy manifests // deploy manifests
core.info('Deploying manifests') core.startGroup("Deploying manifests");
const trafficSplitMethod = parseTrafficSplitMethod( const trafficSplitMethod = parseTrafficSplitMethod(
core.getInput('traffic-split-method', {required: true}) core.getInput("traffic-split-method", { required: true })
) );
const deployedManifestFiles = await deployManifests( const deployedManifestFiles = await deployManifests(
inputManifestFiles, inputManifestFiles,
deploymentStrategy, deploymentStrategy,
kubectl, kubectl,
trafficSplitMethod trafficSplitMethod
) );
core.debug('Deployed manifest files: ' + deployedManifestFiles) core.endGroup();
core.debug("Deployed manifest files: " + deployedManifestFiles);
// check manifest stability // check manifest stability
core.info('Checking manifest stability') core.startGroup("Checking manifest stability");
const resourceTypes: Resource[] = getResources( const resourceTypes: Resource[] = getResources(
deployedManifestFiles, deployedManifestFiles,
models.DEPLOYMENT_TYPES.concat([ models.DEPLOYMENT_TYPES.concat([
KubernetesConstants.DiscoveryAndLoadBalancerResource.SERVICE KubernetesConstants.DiscoveryAndLoadBalancerResource.SERVICE,
]) ])
) );
await checkManifestStability(kubectl, resourceTypes) await checkManifestStability(kubectl, resourceTypes);
core.endGroup();
if (deploymentStrategy == DeploymentStrategy.BLUE_GREEN) {
core.info('Routing blue green') if (deploymentStrategy == DeploymentStrategy.BLUE_GREEN) {
core.group("Routing Blue/Green", async () => {
const routeStrategy = parseRouteStrategy( const routeStrategy = parseRouteStrategy(
core.getInput('route-method', {required: true}) core.getInput("route-method", { required: true })
) );
await routeBlueGreen(kubectl, inputManifestFiles, routeStrategy) await routeBlueGreen(kubectl, inputManifestFiles, routeStrategy);
} });
}
// print ingresses
core.info('Printing ingresses') // print ingresses
const ingressResources: Resource[] = getResources(deployedManifestFiles, [ core.startGroup("Printing ingresses");
KubernetesConstants.DiscoveryAndLoadBalancerResource.INGRESS const ingressResources: Resource[] = getResources(deployedManifestFiles, [
]) KubernetesConstants.DiscoveryAndLoadBalancerResource.INGRESS,
for (const ingressResource of ingressResources) { ]);
await kubectl.getResource( for (const ingressResource of ingressResources) {
KubernetesConstants.DiscoveryAndLoadBalancerResource.INGRESS, await kubectl.getResource(
ingressResource.name KubernetesConstants.DiscoveryAndLoadBalancerResource.INGRESS,
) ingressResource.name
} );
}
// annotate resources core.endGroup();
core.info('Annotating resources') // annotate resources
let allPods core.startGroup("Annotating resources");
try { let allPods;
allPods = JSON.parse((await kubectl.getAllPods()).stdout) try {
} catch (e) { allPods = JSON.parse((await kubectl.getAllPods()).stdout);
core.debug('Unable to parse pods: ' + e) } catch (e) {
} core.debug("Unable to parse pods: " + e);
await annotateAndLabelResources( }
deployedManifestFiles, await annotateAndLabelResources(
kubectl, deployedManifestFiles,
resourceTypes, kubectl,
allPods resourceTypes,
) allPods
} );
core.endGroup();
}