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
core.startGroup("Checking manifest stability");
const resourceTypes: Resource[] = getResources(
deployedManifestFiles,
models.DEPLOYMENT_TYPES.concat([
KubernetesConstants.DiscoveryAndLoadBalancerResource.SERVICE,
])
);
await checkManifestStability(kubectl, resourceTypes);
core.endGroup();
// check manifest stability if (deploymentStrategy == DeploymentStrategy.BLUE_GREEN) {
core.info('Checking manifest stability') core.group("Routing Blue/Green", async () => {
const resourceTypes: Resource[] = getResources(
deployedManifestFiles,
models.DEPLOYMENT_TYPES.concat([
KubernetesConstants.DiscoveryAndLoadBalancerResource.SERVICE
])
)
await checkManifestStability(kubectl, resourceTypes)
if (deploymentStrategy == DeploymentStrategy.BLUE_GREEN) {
core.info('Routing blue green')
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 // print ingresses
core.info('Printing ingresses') core.startGroup("Printing ingresses");
const ingressResources: Resource[] = getResources(deployedManifestFiles, [ const ingressResources: Resource[] = getResources(deployedManifestFiles, [
KubernetesConstants.DiscoveryAndLoadBalancerResource.INGRESS KubernetesConstants.DiscoveryAndLoadBalancerResource.INGRESS,
]) ]);
for (const ingressResource of ingressResources) { for (const ingressResource of ingressResources) {
await kubectl.getResource( await kubectl.getResource(
KubernetesConstants.DiscoveryAndLoadBalancerResource.INGRESS, KubernetesConstants.DiscoveryAndLoadBalancerResource.INGRESS,
ingressResource.name ingressResource.name
) );
} }
core.endGroup();
// annotate resources // annotate resources
core.info('Annotating resources') core.startGroup("Annotating resources");
let allPods let allPods;
try { try {
allPods = JSON.parse((await kubectl.getAllPods()).stdout) allPods = JSON.parse((await kubectl.getAllPods()).stdout);
} catch (e) { } catch (e) {
core.debug('Unable to parse pods: ' + e) core.debug("Unable to parse pods: " + e);
} }
await annotateAndLabelResources( await annotateAndLabelResources(
deployedManifestFiles, deployedManifestFiles,
kubectl, kubectl,
resourceTypes, resourceTypes,
allPods allPods
) );
core.endGroup();
} }