From 2fb58a472331bf4e07b1a24279a29e0a697f80f3 Mon Sep 17 00:00:00 2001 From: Richard Gee Date: Thu, 8 Aug 2024 17:28:35 +0100 Subject: [PATCH] Change upgradeable logic based on feedback Signed-off-by: Richard Gee --- cmd/chart/upgrade.go | 2 +- cmd/chart/upgrade_test.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/cmd/chart/upgrade.go b/cmd/chart/upgrade.go index 22ba99bb1..fca0e8cb4 100644 --- a/cmd/chart/upgrade.go +++ b/cmd/chart/upgrade.go @@ -207,6 +207,6 @@ func tagIsUpgradeable(currentTag, latestTag string) bool { currentSemVer, _ := semver.NewVersion(currentTag) latestSemVer, _ := semver.NewVersion(latestTag) - return latestTag != currentTag && len(latestSemVer.Prerelease()) == 0 && len(currentSemVer.Prerelease()) == 0 + return latestSemVer.Compare(currentSemVer) == 1 && latestSemVer.Prerelease() == currentSemVer.Prerelease() } diff --git a/cmd/chart/upgrade_test.go b/cmd/chart/upgrade_test.go index 22dbaf152..a50ba3541 100644 --- a/cmd/chart/upgrade_test.go +++ b/cmd/chart/upgrade_test.go @@ -53,6 +53,42 @@ func Test_tagIsUpgradable(t *testing.T) { latest: "1.0.0", expected: false, }, + { + title: "both are rootless different version'", + current: "1.0.0-rootless", + latest: "1.0.1-rootless", + expected: true, + }, + { + title: "both are rootless same version'", + current: "1.0.0-rootless", + latest: "1.0.0-rootless", + expected: false, + }, + { + title: "both are rc same version'", + current: "1.0.0-rc", + latest: "1.0.0-rc", + expected: false, + }, + { + title: "both are rc different version'", + current: "1.0.0-rc", + latest: "1.0.1-rc", + expected: true, + }, + { + title: "both are rc with suffix & same version'", + current: "1.0.0-rc1", + latest: "1.0.0-rc2", + expected: false, + }, + { + title: "both are rc with suffix & different version'", + current: "1.0.0-rc1", + latest: "1.0.1-rc2", + expected: false, + }, } for _, tc := range tests {