Skip to content

Commit

Permalink
Ignore latest tags in chart upgrade
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Gee <[email protected]>
  • Loading branch information
rgee0 authored and alexellis committed Jun 13, 2024
1 parent b1ebb19 commit 0bea295
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 59 deletions.
8 changes: 7 additions & 1 deletion cmd/chart/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func updateImages(iName string, v bool) (bool, string, error) {
laterVersionB := false

// AE: Don't upgrade to an RC tag, even if it's newer.
if latestTag != tag && !strings.Contains(latestTag, "-rc") {
if tagIsUpgradeable(tag, latestTag) {

laterVersionB = true

Expand All @@ -197,3 +197,9 @@ func updateImages(iName string, v bool) (bool, string, error) {

return laterVersionB, iName, nil
}

func tagIsUpgradeable(currentTag, latestTag string) bool {

return latestTag != currentTag && !strings.Contains(strings.ToLower(latestTag), "-rc") && !strings.EqualFold(currentTag, "latest")

}
57 changes: 57 additions & 0 deletions cmd/chart/upgrade_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package chart

import (
"testing"
)

func Test_tagIsUpgradable(t *testing.T) {
tests := []struct {
title string
current string
latest string
expected bool
}{
{
title: "Upgradeable",
current: "1.0.0",
latest: "1.1.0",
expected: true,
},
{
title: "Same version",
current: "1.0.0",
latest: "1.0.0",
expected: false,
},
{
title: "latest is RC",
current: "1.0.0",
latest: "1.0.0-RC",
expected: false,
},
{
title: "latest is rc",
current: "1.0.0",
latest: "1.0.0-rc",
expected: false,
},
{
title: "current is 'latest'",
current: "latest",
latest: "1.0.0",
expected: false,
},
}

for _, tc := range tests {

t.Run(tc.title, func(t *testing.T) {

upgradeableRes := tagIsUpgradeable(tc.current, tc.latest)

if upgradeableRes != tc.expected {
t.Fatalf("want: %t\n got: %t\n", tc.expected, upgradeableRes)
}
})
}
}
35 changes: 0 additions & 35 deletions pkg/get/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3351,41 +3351,6 @@ func Test_DownloadKubestr(t *testing.T) {
}
}

//(Temporarily disable k10multicluster as the binaries are not available at v7.0.0)
/*func Test_DownloadK10multicluster(t *testing.T) {
tools := MakeTools()
name := "k10multicluster"
v := "4.0.6"
tool := getTool(name, tools)
tests := []test{
{
os: "darwin",
arch: arch64bit,
version: v,
url: `https://github.com/kastenhq/external-tools/releases/download/4.0.6/k10multicluster_4.0.6_macOS_amd64.tar.gz`,
},
{
os: "linux",
arch: arch64bit,
version: v,
url: `https://github.com/kastenhq/external-tools/releases/download/4.0.6/k10multicluster_4.0.6_linux_amd64.tar.gz`,
},
}
for _, tc := range tests {
t.Run(tc.os+" "+tc.arch+" "+tc.version, func(r *testing.T) {
got, err := tool.GetURL(tc.os, tc.arch, tc.version, false)
if err != nil {
t.Fatal(err)
}
if got != tc.url {
t.Errorf("want: %s, got: %s", tc.url, got)
}
})
}
}*/

func Test_DownloadK10tools(t *testing.T) {
tools := MakeTools()
name := "k10tools"
Expand Down
23 changes: 0 additions & 23 deletions pkg/get/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -2032,29 +2032,6 @@ https://github.com/{{.Owner}}/{{.Repo}}/releases/download/{{.Version}}/{{.Repo}}
BinaryTemplate: `{{.Name}}`,
})

//(Temporarily disable k10multicluster as the binaries are not available at v7.0.0)
/* tools = append(tools,
Tool{
Owner: "kastenhq",
Repo: "external-tools",
Name: "k10multicluster",
Description: "Multi-cluster support for K10.",
BinaryTemplate: `
{{ $osStr := "linux" }}
{{ $archStr := "amd64" }}
{{- if eq .Arch "aarch64" -}}
{{ $archStr = "arm64" }}
{{- end -}}
{{- if eq .OS "darwin" -}}
{{ $osStr = "macOS" }}
{{- end -}}
{{.Name}}_{{.Version}}_{{$osStr}}_{{$archStr}}.tar.gz`,
})
*/
tools = append(tools,
Tool{
Owner: "kastenhq",
Expand Down

0 comments on commit 0bea295

Please sign in to comment.