Skip to content

Commit

Permalink
Handle deleted state of che helm chart by rollbacking or purging the …
Browse files Browse the repository at this point in the history
…charts based on revisions

Fix #18

Change-Id: I30a7e4462d5c10219c216ee528e73f2853aeaba5
Signed-off-by: Florent Benoit <fbenoit@redhat.com>
  • Loading branch information
benoitf committed Jul 3, 2019
1 parent 8139730 commit d9b7205
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/installers/helm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d9b7205

Please sign in to comment.