From d9b7205fa18102c581522dc190d31cf3ade899af Mon Sep 17 00:00:00 2001 From: Florent Benoit Date: Wed, 3 Jul 2019 11:01:41 +0200 Subject: [PATCH] Handle deleted state of che helm chart by rollbacking or purging the charts based on revisions Fix #18 Change-Id: I30a7e4462d5c10219c216ee528e73f2853aeaba5 Signed-off-by: Florent Benoit --- src/installers/helm.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/installers/helm.ts b/src/installers/helm.ts index f0c8af41a..d3d7c209d 100644 --- a/src/installers/helm.ts +++ b/src/installers/helm.ts @@ -163,7 +163,28 @@ error: E_COMMAND_FAILED`) } let command = `helm upgrade --install che --force --namespace ${flags.chenamespace} --set global.ingressDomain=${flags.domain} --set cheImage=${flags.cheimage} --set global.cheWorkspacesNamespace=${flags.chenamespace} ${multiUserFlag} ${tlsFlag} ${destDir}` - await execa.shell(command, { timeout: execTimeout }) + let {code} = await execa.shell(command, { timeout: execTimeout, reject: false }) + // if process failed, check the following + // if revision=1, purge and retry command else rollback + if (code !== 0) { + // get revision + const {stdout} = await execa.shell(`helm history ${flags.chenamespace} --output json`, { timeout: execTimeout }) + let jsonOutput + try { + jsonOutput = JSON.parse(stdout) + } catch (err) { + throw new Error('Unable to grab helm history:' + err) + } + const revision = jsonOutput[0].revision + if (jsonOutput.length > 0 && revision === '1') { + await this.purgeHelmChart(flags.chenamespace) + } else { + await execa('helm', ['rollback', flags.chenamespace, revision], { timeout: execTimeout }) + + } + await execa.shell(command, { timeout: execTimeout }) + + } } async purgeHelmChart(name: string, execTimeout= 30000) {