Skip to content

Commit

Permalink
fix(helm): handle missing (null) values in version check (#5307)
Browse files Browse the repository at this point in the history
* fix(helm): handle missing (null) values in version check

* chore: improve log message

Co-authored-by: Anna Mager <[email protected]>

* chore: more precise deployment status handling

* chore: print log statement in the proper place

---------

Co-authored-by: Anna Mager <[email protected]>
  • Loading branch information
vvagaytsev and twelvemo authored Oct 27, 2023
1 parent 6c18b6d commit 31f4420
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions core/src/plugins/kubernetes/helm/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,22 +205,28 @@ export async function getReleaseStatus({

if (state === "ready") {
// Make sure the right version is deployed
values = JSON.parse(
await helm({
ctx,
log,
namespace,
args: ["get", "values", releaseName, "--output", "json"],
// do not send JSON output to Garden Cloud or CLI verbose log
emitLogEvents: false,
})
)

const deployedVersion = values[".garden"]?.version
deployedMode = values[".garden"]?.mode

if (action.mode() !== deployedMode || !deployedVersion || deployedVersion !== action.versionString()) {
const helmResponse = await helm({
ctx,
log,
namespace,
args: ["get", "values", releaseName, "--output", "json"],
// do not send JSON output to Garden Cloud or CLI verbose log
emitLogEvents: false,
})
values = JSON.parse(helmResponse)

let deployedVersion: string | undefined = undefined
// JSON.parse can return null
if (values === null) {
log.verbose(`No helm values returned for release ${releaseName}. Is this release managed outside of garden?`)
state = "outdated"
} else {
deployedVersion = values[".garden"]?.version
deployedMode = values[".garden"]?.mode

if (action.mode() !== deployedMode || !deployedVersion || deployedVersion !== action.versionString()) {
state = "outdated"
}
}

// If ctx.cloudApi is defined, the user is logged in and they might be trying to deploy to an environment
Expand Down

0 comments on commit 31f4420

Please sign in to comment.