From 31f442029a050b539b369c2869a28894652337f7 Mon Sep 17 00:00:00 2001 From: Vladimir Vagaytsev Date: Fri, 27 Oct 2023 13:51:44 +0200 Subject: [PATCH] fix(helm): handle missing (null) values in version check (#5307) * fix(helm): handle missing (null) values in version check * chore: improve log message Co-authored-by: Anna Mager <78752267+twelvemo@users.noreply.github.com> * chore: more precise deployment status handling * chore: print log statement in the proper place --------- Co-authored-by: Anna Mager <78752267+twelvemo@users.noreply.github.com> --- core/src/plugins/kubernetes/helm/status.ts | 36 +++++++++++++--------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/core/src/plugins/kubernetes/helm/status.ts b/core/src/plugins/kubernetes/helm/status.ts index edf3e83cdc..92e7b7db70 100644 --- a/core/src/plugins/kubernetes/helm/status.ts +++ b/core/src/plugins/kubernetes/helm/status.ts @@ -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