Resolved issue with Canary deploy (#247)

This commit is contained in:
Jaiveer Katariya
2022-10-14 12:25:27 -04:00
committed by GitHub
parent c8f050230d
commit d64c205796
7 changed files with 151 additions and 96 deletions
+30 -4
View File
@@ -2,6 +2,7 @@ import {Kubectl} from '../../types/kubectl'
import * as fs from 'fs'
import * as yaml from 'js-yaml'
import * as core from '@actions/core'
import {ExecOutput} from '@actions/exec'
import {
isDeploymentEntity,
isServiceEntity,
@@ -30,7 +31,7 @@ export async function deleteCanaryDeployment(
includeServices: boolean
) {
if (manifestFilePaths == null || manifestFilePaths.length == 0) {
throw new Error('Manifest file not found')
throw new Error('Manifest files for deleting canary deployment not found')
}
await cleanUpCanary(kubectl, manifestFilePaths, includeServices)
@@ -54,7 +55,7 @@ export function isResourceMarkedAsStable(inputObject: any): boolean {
export function getStableResource(inputObject: any): object {
const replicaCount = specContainsReplicas(inputObject.kind)
? inputObject.metadata.replicas
? inputObject.spec.replicas
: 0
return getNewCanaryObject(inputObject, replicaCount, STABLE_LABEL_VALUE)
@@ -79,7 +80,12 @@ export async function fetchResource(
kind: string,
name: string
) {
const result = await kubectl.getResource(kind, name)
let result: ExecOutput
try {
result = await kubectl.getResource(kind, name)
} catch (e) {
core.debug(`detected error while fetching resources: ${e}`)
}
if (!result || result?.stderr) {
return null
@@ -93,7 +99,7 @@ export async function fetchResource(
return resource
} catch (ex) {
core.debug(
`Exception occurred while Parsing ${resource} in JSON object: ${ex}`
`Exception occurred while parsing ${resource} in JSON object: ${ex}`
)
}
}
@@ -111,6 +117,26 @@ export function getStableResourceName(name: string) {
return name + STABLE_SUFFIX
}
export function getBaselineDeploymentFromStableDeployment(
inputObject: any,
replicaCount: number
): object {
// TODO: REFACTOR TO MAKE EVERYTHING TYPE SAFE
const oldName = inputObject.metadata.name
const newName =
oldName.substring(0, oldName.length - STABLE_SUFFIX.length) +
BASELINE_SUFFIX
const newObject = getNewCanaryObject(
inputObject,
replicaCount,
BASELINE_LABEL_VALUE
) as any
newObject.metadata.name = newName
return newObject
}
function getNewCanaryObject(
inputObject: any,
replicas: number,