Chore: swtich between old and new registry in vela install (#6173)

* Chore: swtich between old and new registry in vela install

Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>

* add comments

Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>

* minor fix

Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>

---------

Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
This commit is contained in:
qiaozp
2023-07-04 12:15:30 +08:00
committed by GitHub
parent 64e4ab813d
commit dabaf03e73
5 changed files with 94 additions and 13 deletions

View File

@@ -44,3 +44,22 @@ func GetOfficialKubeVelaVersion(versionStr string) (string, error) {
}
return v[:len(v)-len(metadata)], nil
}
// ShouldUseLegacyHelmRepo checks whether the provided version should use the legacy helm repo
func ShouldUseLegacyHelmRepo(ver *version.Version) bool {
if ver.LessThan(version.Must(version.NewVersion("1.8.2"))) {
return true
}
if ver.GreaterThanOrEqual(version.Must(version.NewVersion("1.9.0"))) {
return false
}
// After v1.9.0-beta.1.post1, we use the new helm repo
switch ver.Prerelease() {
case "beta.1.post1", "beta.2", "beta.3":
return false
default:
return true
}
}

View File

@@ -19,6 +19,7 @@ package version
import (
"testing"
"github.com/hashicorp/go-version"
"github.com/stretchr/testify/assert"
)
@@ -41,3 +42,33 @@ func TestGetVersion(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, "1.2.0", version)
}
func TestShouldUseLegacyHelmRepo(t *testing.T) {
tests := []struct {
ver string
want bool
}{
{
ver: "v1.2.0",
want: true,
},
{
ver: "v1.9.0-beta.1",
want: true,
},
{
ver: "v1.9.0-beta.1.post1",
want: false,
},
{
ver: "v1.9.1",
want: false,
},
}
for _, tt := range tests {
t.Run(tt.ver, func(t *testing.T) {
ver := version.Must(version.NewVersion(tt.ver))
assert.Equalf(t, tt.want, ShouldUseLegacyHelmRepo(ver), "ShouldUseLegacyHelmRepo(%v)", tt.ver)
})
}
}