Skip to content

Commit f77a528

Browse files
committed
rpk: fix version check logic for semver
Fixes a bug in the rpk version comparison logic to correctly account for the logic of semantic versioning.
1 parent d14536e commit f77a528

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/go/rpk/pkg/redpanda/version.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ func (v Version) Less(b Version) bool {
4747

4848
// IsAtLeast returns true if the version is greater than or equal to the passed version.
4949
func (v Version) IsAtLeast(b Version) bool {
50-
if v.Major >= b.Major {
51-
if v.Feature >= b.Feature {
52-
return v.Patch >= b.Patch
53-
}
50+
if v.Major != b.Major {
51+
return v.Major > b.Major
52+
}
53+
if v.Feature != b.Feature {
54+
return v.Feature > b.Feature
5455
}
55-
return false
56+
return v.Patch >= b.Patch
5657
}
5758

5859
func (v Version) String() string {

src/go/rpk/pkg/redpanda/version_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func TestVersion_IsAtLeast(t *testing.T) {
7979
{"lower year", Version{23, 1, 1}, Version{22, 1, 1}, true},
8080
{"lower feature", Version{22, 3, 23}, Version{22, 2, 23}, true},
8181
{"lower patch", Version{23, 4, 23}, Version{23, 4, 22}, true},
82+
{"next major with lower minor and patch", Version{26, 1, 1}, Version{25, 3, 2}, true},
8283
} {
8384
t.Run(test.name, func(t *testing.T) {
8485
require.Equal(t, test.a.IsAtLeast(test.b), test.exp)

0 commit comments

Comments
 (0)