diff --git a/src/installers/helm.ts b/src/installers/helm.ts index f0c8af41a..7ec782458 100644 --- a/src/installers/helm.ts +++ b/src/installers/helm.ts @@ -163,7 +163,21 @@ 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} | tail -1 | head -1 | awk '{print $1}'`, { timeout: execTimeout }) + if (stdout === '1') { + await this.purgeHelmChart(flags.chenamespace) + } else { + await execa('helm', ['rollback', flags.chenamespace, stdout], { timeout: execTimeout }) + + } + await execa.shell(command, { timeout: execTimeout }) + + } } async purgeHelmChart(name: string, execTimeout= 30000) {