Logging Changes with group

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

View File

@ -1,88 +1,90 @@
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.startGroup("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.endGroup(); core.endGroup();
core.debug("Deployed manifest files: " + deployedManifestFiles); core.debug('Deployed manifest files: ' + deployedManifestFiles)
// check manifest stability
core.startGroup("Checking manifest stability"); // check manifest stability
const resourceTypes: Resource[] = getResources( core.startGroup('Checking manifest stability')
deployedManifestFiles, const resourceTypes: Resource[] = getResources(
models.DEPLOYMENT_TYPES.concat([ deployedManifestFiles,
KubernetesConstants.DiscoveryAndLoadBalancerResource.SERVICE, models.DEPLOYMENT_TYPES.concat([
]) KubernetesConstants.DiscoveryAndLoadBalancerResource.SERVICE
); ])
await checkManifestStability(kubectl, resourceTypes); )
core.endGroup(); await checkManifestStability(kubectl, resourceTypes)
core.endGroup();
if (deploymentStrategy == DeploymentStrategy.BLUE_GREEN) {
core.group("Routing Blue/Green", async () => { if (deploymentStrategy == DeploymentStrategy.BLUE_GREEN) {
core.startGroup('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)
}); core.endGroup();
} }
// print ingresses // print ingresses
core.startGroup("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(); core.endGroup();
// annotate resources
core.startGroup("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(); )
} core.endGroup();
}