Skip to content

Commit

Permalink
Replace versioncheck.Version with semver.ParseTolerant
Browse files Browse the repository at this point in the history
ParseCiliumVersion uses versioncheck.Version from Cilium's versioncheck
package ([1]), which ignores certain pre-release identifiers. Silently
ignoring certain pre-release identifiers can be confusing since you
might end up installing a different version of Cilium than what you
specified.

This commit replaces versioncheck.Version with semver.ParseTolerant ([2])
in ParseCiliumVersion function so that cilium-cli interprets the version
provided via the --version flag as is.

[1]: https://pkg.go.dev/github.com/cilium/cilium/pkg/versioncheck#Version
[2]: https://pkg.go.dev/github.com/blang/semver#ParseTolerant

Signed-off-by: Michi Mutsuzaki <[email protected]>
  • Loading branch information
michi-covalent authored and tklauser committed May 3, 2023
1 parent e1d57b3 commit b5fff0b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 1 addition & 3 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"time"

"github.com/blang/semver/v4"
"github.com/cilium/cilium/pkg/versioncheck"

"github.com/cilium/cilium-cli/defaults"
)
Expand All @@ -26,8 +25,7 @@ func CheckVersion(version string) error {
}

func ParseCiliumVersion(version string) (semver.Version, error) {
ersion := strings.TrimPrefix(version, "v")
return versioncheck.Version(ersion)
return semver.ParseTolerant(version)
}

type ImagePathMode int
Expand Down
13 changes: 13 additions & 0 deletions internal/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ func TestParseCiliumVersion(t *testing.T) {
version: "v1.9.99",
want: semver.Version{Major: 1, Minor: 9, Patch: 99},
},
{
name: "valid-pre-release-version",
version: "1.13.90-dev.1234-main-5678abcd",
want: semver.Version{
Major: 1,
Minor: 13,
Patch: 90,
Pre: []semver.PRVersion{
{VersionStr: "dev", IsNum: false},
{VersionStr: "1234-main-5678abcd", IsNum: false},
},
},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit b5fff0b

Please sign in to comment.