mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-06-29 00:09:28 +08:00
Checks in annotateNamespace to not error during failed annotation
This commit is contained in:
@@ -30,7 +30,7 @@ function checkForErrors(execResults, warnIfError) {
|
||||
if (execResults.length !== 0) {
|
||||
let stderr = '';
|
||||
execResults.forEach(result => {
|
||||
if (result.stderr) {
|
||||
if (result && result.stderr) {
|
||||
if (result.code !== 0) {
|
||||
stderr += result.stderr + '\n';
|
||||
}
|
||||
@@ -72,16 +72,22 @@ function annotateChildPods(kubectl, resourceType, resourceName, allPods) {
|
||||
}
|
||||
exports.annotateChildPods = annotateChildPods;
|
||||
function annotateNamespace(kubectl, namespaceName) {
|
||||
let annotate = true;
|
||||
const result = kubectl.getResource('namespace', namespaceName);
|
||||
this.checkForErrors([result]);
|
||||
const annotationsSet = JSON.parse(result.stdout).metadata.annotations;
|
||||
if (!!annotationsSet && !!annotationsSet.runUri && annotationsSet.runUri.indexOf(process.env['GITHUB_REPOSITORY']) == -1) {
|
||||
annotate = false;
|
||||
core.debug(`Skipping 'annotate namespace' as namespace annotated by other workflow`);
|
||||
if (result == null) {
|
||||
return { code: -1, stderr: 'Failed to get resource' };
|
||||
}
|
||||
if (annotate) {
|
||||
return kubectl.annotate('namespace', namespaceName, constants_1.workflowAnnotations, true);
|
||||
else if (!!result && !!result.stderr) {
|
||||
return result;
|
||||
}
|
||||
if (!!result && !!result.stdout) {
|
||||
const annotationsSet = JSON.parse(result.stdout).metadata.annotations;
|
||||
if (!!annotationsSet && !!annotationsSet.runUri && annotationsSet.runUri.indexOf(process.env['GITHUB_REPOSITORY']) == -1) {
|
||||
core.debug(`Skipping 'annotate namespace' as namespace annotated by other workflow`);
|
||||
return { code: 0, stdout: '' };
|
||||
}
|
||||
else {
|
||||
return kubectl.annotate('namespace', namespaceName, constants_1.workflowAnnotations, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.annotateNamespace = annotateNamespace;
|
||||
|
||||
Reference in New Issue
Block a user