Skip to content

Commit

Permalink
Update: Fail job if there are errors (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
alewitt2 authored May 13, 2020
1 parent 8023678 commit 575ac9c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const fs = require('fs-extra');
const axios = require('axios');
const handlebars = require('handlebars');

var success = true;
const argvNamespace = typeof (argv.n || argv.namespace) === 'string' ? argv.n || argv.namespace : 'razeedeploy';

async function main() {
Expand Down Expand Up @@ -97,6 +98,7 @@ async function main() {

let fileSource = typeof (argv.s || argv['file-source']) === 'string' ? argv.s || argv['file-source'] : 'https://github.com/razee-io';
if (!validUrl.isUri(fileSource)) {
success = false;
return log.error(`'${fileSource}' not a valid source url.`);
} else if (fileSource.endsWith('/')) {
fileSource = fileSource.replace(/\/+$/g, '');
Expand Down Expand Up @@ -177,13 +179,15 @@ async function main() {
await crdRegistered('deploy.razee.io/v1alpha2', 'RemoteResource');
await decomposeFile(autoUpdateJson);
} catch (e) {
success = false;
log.error(`${e}.. skipping autoUpdate`);
}
} else if (autoUpdate && !(installAll || resourcesObj.remoteresource.install)) {
log.info('=========== Installing Auto-Update RemoteResource ===========');
log.warn('RemoteResource CRD must be one of the installed resources in order to use autoUpdate. (ie. --rr -a).. Skipping autoUpdate');
}
} catch (e) {
success = false;
log.error(e);
}
}
Expand All @@ -204,6 +208,7 @@ async function crdRegistered(apiVersion, kind, attempts = 5, backoffInterval = 5
log.info(`Found ${apiVersion} ${kind}`);
return krm;
} else if (--attempts <= 0) {
success = false;
throw Error(`Failed to find ${apiVersion} ${kind}`);
} else {
log.warn(`Did not find ${apiVersion} ${kind}.. attempts remaining: ${attempts}`);
Expand Down Expand Up @@ -253,9 +258,11 @@ async function decomposeFile(file, mode = 'replace') {
await replace(krm, file);
}
} catch (e) {
success = false;
log.error(e);
}
} else {
success = false;
log.error(`KubeResourceMeta not found: { kind: ${kind}, apiVersion: ${apiVersion}, name: ${objectPath.get(file, 'metadata.name')}, namespace: ${objectPath.get(file, 'metadata.namespace')} } ... skipping`);
}
}
Expand Down Expand Up @@ -341,4 +348,9 @@ async function ensureExists(krm, file, options = {}) {
return response;
}

main().catch(log.error);
main().then(() => {
success === true ? process.exit(0) : process.exit(1);
}).catch(e => {
log.error(e);
process.exit(1);
});
14 changes: 13 additions & 1 deletion src/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const fs = require('fs-extra');
const axios = require('axios');
const handlebars = require('handlebars');

var success = true;
const argvNamespace = typeof (argv.n || argv.namespace) === 'string' ? argv.n || argv.namespace : 'razeedeploy';

async function main() {
Expand Down Expand Up @@ -77,6 +78,7 @@ async function main() {

let fileSource = typeof (argv.s || argv['file-source']) === 'string' ? argv.s || argv['file-source'] : 'https://github.com/razee-io';
if (!validUrl.isUri(fileSource)) {
success = false;
return log.error(`'${fileSource}' not a valid source url.`);
} else if (fileSource.endsWith('/')) {
fileSource = fileSource.replace(/\/+$/g, '');
Expand Down Expand Up @@ -132,6 +134,7 @@ async function main() {
await crdDeleted(objectPath.get(crd, 'metadata.name'), attempts, backoff);
}
} catch (e) {
success = false;
log.error(`Timed out trying to safely clean up crd ${objectPath.get(crd, 'metadata.name')}.. use option '-f, --force' to force clean up (note: child resources wont be cleaned up)`);
}
}
Expand All @@ -152,6 +155,7 @@ async function main() {
}

} catch (e) {
success = false;
log.error(e);
}
}
Expand Down Expand Up @@ -187,6 +191,7 @@ async function crdDeleted(name, attempts = 5, backoffInterval = 3750) {
log.info(`Successfully deleted ${name}`);
return;
} else if (--attempts <= 0) {
success = false;
throw Error(`Failed to delete ${name}`);
} else {
log.warn(`CRD ${name} not fully removed.. re-checking in: ${backoffInterval/1000} sec, attempts remaining: ${attempts}`);
Expand Down Expand Up @@ -246,9 +251,11 @@ async function deleteFile(file, force = false) {
try {
await deleteResource(krm, file, { force: force });
} catch (e) {
success = false;
log.error(e);
}
} else {
success = false;
log.error(`KubeResourceMeta not found: { kind: ${kind}, apiVersion: ${apiVersion}, name: ${objectPath.get(file, 'metadata.name')}, namespace: ${objectPath.get(file, 'metadata.namespace')} } ... skipping`);
}
}
Expand Down Expand Up @@ -287,4 +294,9 @@ async function deleteResource(krm, file, options = {}) {
}
}

main().catch(log.error);
main().then(() => {
success === true ? process.exit(0) : process.exit(1);
}).catch(e => {
log.error(e);
process.exit(1);
});

0 comments on commit 575ac9c

Please sign in to comment.