mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-06-26 14:49:26 +08:00
Resolved issue with Canary deploy (#247)
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user