Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions internal/local/scripts/upgrade-platform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions internal/local/upgrade_script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Loading