From 3ac18bd60a84088756f9cc1080516585085dc3aa Mon Sep 17 00:00:00 2001 From: Vitalii Valkov Date: Wed, 19 Aug 2026 02:52:36 +0100 Subject: [PATCH] What is installed is what deployed An upgrade that fails still records the version it was reaching for, and helm list reports that as the release's chart. A release left failed at the version being upgraded to therefore answered "already at" and was skipped -- the upgrade that would repair it is the one being refused, so the VM stayed on the release that actually deployed with no way forward through the CLI. installed_version now reads the newest revision that deployed, falling back to helm list where none has, so a release that has only ever failed still reports something. --- internal/local/scripts/upgrade-platform.sh | 17 ++++++++++++ internal/local/upgrade_script_test.go | 32 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/internal/local/scripts/upgrade-platform.sh b/internal/local/scripts/upgrade-platform.sh index 6f3e7e3..1048bb9 100755 --- a/internal/local/scripts/upgrade-platform.sh +++ b/internal/local/scripts/upgrade-platform.sh @@ -129,7 +129,24 @@ release_status() { } || true } +# The version actually serving, which is the newest revision that deployed -- +# not the newest revision. An upgrade that failed still records its target, and +# `helm list` reports that: a release left failed at the version being upgraded +# to would answer "already at" forever and never be repaired. Falls back to +# `helm list` where no revision deployed, so a release that has only ever failed +# still reports something. installed_version() { + deployed="$( + { + helm history "${1}" -n "${NAMESPACE}" -o json 2>/dev/null | + tr '{' '\n' | grep '"status":"deployed"' | tail -1 | + sed -n 's/.*"chart":"[^"]*-\([0-9][^"]*\)".*/\1/p' | head -1 + } || true + )" + if [ -n "${deployed}" ]; then + printf '%s' "${deployed}" + return 0 + fi { helm list -n "${NAMESPACE}" --filter "^${1}\$" -o json 2>/dev/null | sed -n 's/.*"chart":"[^"]*-\([0-9][^"]*\)".*/\1/p' | head -1 diff --git a/internal/local/upgrade_script_test.go b/internal/local/upgrade_script_test.go index 620e0f7..bfe9069 100644 --- a/internal/local/upgrade_script_test.go +++ b/internal/local/upgrade_script_test.go @@ -134,3 +134,35 @@ func stubLog(t *testing.T) string { } return string(data) } + +// A failed upgrade still records the version it was reaching for, and +// `helm list` reports that version as the installed one. Read that way, a +// release left failed at the target answers "already at" and is never +// repaired -- the upgrade that would fix it is the one being skipped. What is +// installed is the newest revision that actually deployed. +func TestUpgradeScriptRetriesAReleaseLeftFailedAtTheTargetVersion(t *testing.T) { + out, err := runUpgradeScriptWithStubs(t, map[string]string{ + "helm": `case "$1" in + status) echo '{"info":{"status":"failed"}}' ;; + list) echo '[{"name":"agyn-platform","chart":"agyn-platform-0.70.3"}]' ;; + history) echo '[{"revision":23,"status":"superseded","chart":"agyn-platform-0.70.1"},{"revision":24,"status":"deployed","chart":"agyn-platform-0.70.2"},{"revision":25,"status":"failed","chart":"agyn-platform-0.70.3"}]' ;; + show) echo "version: 0.70.3" ;; + upgrade) echo "upgraded" ;; + *) exit 0 ;; + esac`, + "kubectl": `case "$*" in + *readyz*) echo ok ;; + *) exit 0 ;; + esac`, + }) + + if err != nil { + t.Fatalf("expected the script to succeed, got %v:\n%s", err, out) + } + if strings.Contains(out, "already at 0.70.3") { + t.Fatalf("a release left failed at the target was treated as installed:\n%s", out) + } + if !strings.Contains(out, "0.70.2 → 0.70.3") { + t.Fatalf("expected an upgrade from the deployed version, got:\n%s", out) + } +}