in src/strategyHelpers/canary/canaryHelper.ts [193:243]
async function cleanUpCanary(
kubectl: Kubectl,
files: string[],
includeServices: boolean
): Promise<string[]> {
const deleteObject = async function (
kind: string,
name: string,
namespace: string | undefined
) {
try {
const result = await kubectl.delete([kind, name], namespace)
checkForErrors([result])
} catch (ex) {
// Ignore failures of delete if it doesn't exist
}
}
const deletedFiles: string[] = []
for (const filePath of files) {
try {
const fileContents = fs.readFileSync(filePath).toString()
const parsedYaml: any[] = yaml.loadAll(fileContents)
for (const inputObject of parsedYaml) {
const name = inputObject.metadata.name
const kind = inputObject.kind
const namespace: string | undefined =
inputObject?.metadata?.namespace
if (
isDeploymentEntity(kind) ||
(includeServices && isServiceEntity(kind))
) {
deletedFiles.push(filePath)
const canaryObjectName = getCanaryResourceName(name)
const baselineObjectName = getBaselineResourceName(name)
await deleteObject(kind, canaryObjectName, namespace)
await deleteObject(kind, baselineObjectName, namespace)
}
}
} catch (error) {
core.error(`Failed to process file ${filePath}: ${error.message}`)
throw error
}
}
return deletedFiles
}