Addressed review comments

This commit is contained in:
Koushik Dey 2020-07-02 18:05:13 +05:30
parent 7f721770f6
commit b3381a2f94
2 changed files with 25 additions and 25 deletions

View File

@ -40,7 +40,7 @@ function checkForErrors(execResults, warnIfError) {
} }
}); });
if (stderr.length > 0) { if (stderr.length > 0) {
if (!!warnIfError) { if (warnIfError) {
core.warning(stderr.trim()); core.warning(stderr.trim());
} }
else { else {
@ -56,10 +56,10 @@ function annotateChildPods(kubectl, resourceType, resourceName, allPods) {
if (resourceType.toLowerCase().indexOf('deployment') > -1) { if (resourceType.toLowerCase().indexOf('deployment') > -1) {
owner = kubectl.getNewReplicaSet(resourceName); owner = kubectl.getNewReplicaSet(resourceName);
} }
if (!!allPods && !!allPods.items && allPods.items.length > 0) { if (allPods && allPods.items && allPods.items.length > 0) {
allPods.items.forEach((pod) => { allPods.items.forEach((pod) => {
const owners = pod.metadata.ownerReferences; const owners = pod.metadata.ownerReferences;
if (!!owners) { if (owners) {
owners.forEach(ownerRef => { owners.forEach(ownerRef => {
if (ownerRef.name === owner) { if (ownerRef.name === owner) {
commandExecutionResults.push(kubectl.annotate('pod', pod.metadata.name, constants_1.workflowAnnotations, true)); commandExecutionResults.push(kubectl.annotate('pod', pod.metadata.name, constants_1.workflowAnnotations, true));
@ -73,21 +73,21 @@ function annotateChildPods(kubectl, resourceType, resourceName, allPods) {
exports.annotateChildPods = annotateChildPods; exports.annotateChildPods = annotateChildPods;
function annotateNamespace(kubectl, namespaceName) { function annotateNamespace(kubectl, namespaceName) {
const result = kubectl.getResource('namespace', namespaceName); const result = kubectl.getResource('namespace', namespaceName);
if (result == null) { if (!result) {
return { code: -1, stderr: 'Failed to get resource' }; return { code: -1, stderr: 'Failed to get resource' };
} }
else if (!!result && !!result.stderr) { else if (result && result.stderr) {
return result; return result;
} }
if (!!result && !!result.stdout) { if (result && result.stdout) {
const annotationsSet = JSON.parse(result.stdout).metadata.annotations; const annotationsSet = JSON.parse(result.stdout).metadata.annotations;
if (!!annotationsSet && !!annotationsSet.runUri && annotationsSet.runUri.indexOf(process.env['GITHUB_REPOSITORY']) == -1) { if (annotationsSet && annotationsSet.runUri) {
core.debug(`Skipping 'annotate namespace' as namespace annotated by other workflow`); if (annotationsSet.runUri.indexOf(process.env['GITHUB_REPOSITORY']) == -1) {
return { code: 0, stdout: '' }; 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);
} }
return kubectl.annotate('namespace', namespaceName, constants_1.workflowAnnotations, true);
} }
} }
exports.annotateNamespace = annotateNamespace; exports.annotateNamespace = annotateNamespace;

View File

@ -41,7 +41,7 @@ export function checkForErrors(execResults: IExecSyncResult[], warnIfError?: boo
} }
}); });
if (stderr.length > 0) { if (stderr.length > 0) {
if (!!warnIfError) { if (warnIfError) {
core.warning(stderr.trim()); core.warning(stderr.trim());
} else { } else {
throw new Error(stderr.trim()); throw new Error(stderr.trim());
@ -57,10 +57,10 @@ export function annotateChildPods(kubectl: Kubectl, resourceType: string, resour
owner = kubectl.getNewReplicaSet(resourceName); owner = kubectl.getNewReplicaSet(resourceName);
} }
if (!!allPods && !!allPods.items && allPods.items.length > 0) { if (allPods && allPods.items && allPods.items.length > 0) {
allPods.items.forEach((pod) => { allPods.items.forEach((pod) => {
const owners = pod.metadata.ownerReferences; const owners = pod.metadata.ownerReferences;
if (!!owners) { if (owners) {
owners.forEach(ownerRef => { owners.forEach(ownerRef => {
if (ownerRef.name === owner) { if (ownerRef.name === owner) {
commandExecutionResults.push(kubectl.annotate('pod', pod.metadata.name, workflowAnnotations, true)); commandExecutionResults.push(kubectl.annotate('pod', pod.metadata.name, workflowAnnotations, true));
@ -75,22 +75,22 @@ export function annotateChildPods(kubectl: Kubectl, resourceType: string, resour
export function annotateNamespace(kubectl: Kubectl, namespaceName: string): IExecSyncResult { export function annotateNamespace(kubectl: Kubectl, namespaceName: string): IExecSyncResult {
const result = kubectl.getResource('namespace', namespaceName); const result = kubectl.getResource('namespace', namespaceName);
if (result == null) { if (!result) {
return <IExecSyncResult>{ code: -1, stderr: 'Failed to get resource' }; return { code: -1, stderr: 'Failed to get resource' } as IExecSyncResult;
} }
else if (!!result && !!result.stderr) { else if (result && result.stderr) {
return result; return result;
} }
if (!!result && !!result.stdout) { if (result && result.stdout) {
const annotationsSet = JSON.parse(result.stdout).metadata.annotations; const annotationsSet = JSON.parse(result.stdout).metadata.annotations;
if (!!annotationsSet && !!annotationsSet.runUri && annotationsSet.runUri.indexOf(process.env['GITHUB_REPOSITORY']) == -1) { if (annotationsSet && annotationsSet.runUri) {
core.debug(`Skipping 'annotate namespace' as namespace annotated by other workflow`); if (annotationsSet.runUri.indexOf(process.env['GITHUB_REPOSITORY']) == -1) {
return <IExecSyncResult>{ code: 0, stdout: '' }; core.debug(`Skipping 'annotate namespace' as namespace annotated by other workflow`);
} return { code: 0, stdout: '' } as IExecSyncResult;
else { }
return kubectl.annotate('namespace', namespaceName, workflowAnnotations, true);
} }
return kubectl.annotate('namespace', namespaceName, workflowAnnotations, true);
} }
} }