Checks in annotateNamespace to not error during failed annotation

This commit is contained in:
Koushik Dey
2020-06-26 00:24:00 +05:30
parent af5108bc1c
commit 7f721770f6
3 changed files with 57 additions and 21 deletions
+15 -9
View File
@@ -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;