Skip to content

Commit 2a82a3f

Browse files
authored
Switch ran eco gotests version comparison to semver CNF-20904 (#1322)
* cnf/ran: implement SemVer for RAN version gate checks Replace ad hoc major/minor version checks with github.com/Masterminds/semver/v3. - Add semver_range.go with IsVersionStringInRange (minimum <= v < exclusive maximum), including two-segment X.Y maximum as whole minor line; document 4.N.0-0 lower bounds. - Add table-driven unit tests (document UNIT_TEST=true for local runs without kubeconfig). - Declare github.com/Masterminds/semver/v3 in the primary go.mod require block. - Update RAN call sites (GitOps/ZTP, TALM, PTP, power management) to use 4.N.0-0 minimums. * cnf/ran: address PR 1322 review (semver gates) - Reject two-segment maximum strings that include a prerelease or build suffix; propagate NewVersion errors when constructing the implicit upper bound. - Move IsVersionStringInRange helpers into version.go and remove semver_range.go. - Treat explicit multi-segment maximum as the exclusive upper bound (half-open interval); keep plain X.Y shorthand for the next-minor exclusive bound; update tests plus TALM backup and PTP event-consumer call sites. * unify semver maximum parsing with minimum - Add parseSemverGateBound and route minimum/maximum through the same trim + coerceSemverCore + NewVersion path; drop two-segment maximum shorthand. - Document that non-empty maximum must be an explicit semver exclusive bound. - Update version_test table maxima to explicit exclusives (e.g. 4.21.0-0 for the old "4.20" shorthand); remove the redundant 4.15-rc.1 error case. Made-with: Cursor * cnf/ptp: fix ptp-interfaces per CodeRabbit review - Restore AssertWithTimeout to 3m alongside the 30s stable window for clock-state Prometheus assertions (45s was too tight for scrape + stabilize). - Use GetProfileByDaemonName for HA profile lookups so daemon-qualified names (ConfigName_ProfileName) resolve. Made-with: Cursor * chore: satisfy golangci-lint for cnf/ran version (scoped) - Allow github.com/Masterminds/semver/v3 in .golangci.yml depguard main list. - Fix lll (wrap version_test package comment), nilnil nolints for empty bounds, varnamelen (parsedVersion, splitSemverCore param), and wsl spacing. Made-with: Cursor * cnf/talm: restore precache Eventually timeout to 30 minutes Revert the precache status poll duration from 20m to 30m so this line is not altered by the RAN semver workstream. Matches maintainer feedback on #1322. Made-with: Cursor * cnf/ran: parse version gate bounds with semver only Drop coerceSemverCore and related helpers; parse minimum and maximum the same way as the subject version (trimSemverVPrefix + semver.NewVersion). Call sites already pass full semver strings (e.g. X.Y.0-0). Addresses review feedback on #1322. Made-with: Cursor * cnf/ran: log unparsable version in IsVersionStringInRange legacy path When maximum is empty and the subject version is not valid semver, preserve (true, nil) for legacy callers but emit klog.V(ranparam.LogLevel) diagnostics. Addresses CodeRabbit feedback on #1322. Made-with: Cursor
1 parent 4a7d570 commit 2a82a3f

27 files changed

Lines changed: 170 additions & 174 deletions

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ linters:
6464
- github.com/openshift
6565
- github.com/nmstate/kubernetes-nmstate
6666
- github.com/hashicorp/go-version
67+
- github.com/Masterminds/semver/v3
6768
- github.com/cavaliergopher/grab/v3
6869
- github.com/k8snetworkplumbingwg
6970
- github.com/metallb/metallb-operator

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ toolchain go1.26.0
77
require (
88
github.com/BurntSushi/toml v1.6.0
99
github.com/Juniper/go-netconf v0.3.1
10+
github.com/Masterminds/semver/v3 v3.4.0
1011
github.com/Masterminds/sprig/v3 v3.3.0
1112
github.com/NVIDIA/gpu-operator v1.11.1
1213
github.com/cavaliergopher/cpio v1.0.1
@@ -80,7 +81,6 @@ require (
8081
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c // indirect
8182
github.com/MakeNowJust/heredoc v1.0.0 // indirect
8283
github.com/Masterminds/goutils v1.1.1 // indirect
83-
github.com/Masterminds/semver/v3 v3.4.0 // indirect
8484
github.com/Microsoft/go-winio v0.6.2 // indirect
8585
github.com/PaesslerAG/gval v1.0.0 // indirect
8686
github.com/PaesslerAG/jsonpath v0.1.1 // indirect

tests/cnf/ran/gitopsztp/tests/ztp-argocd-acm-crs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var _ = Describe("ZTP Argo CD ACM CR Tests", Label(tsparams.LabelArgoCdAcmCrsTes
3030
BeforeEach(func() {
3131
By("verifying that ZTP meets the minimum version")
3232

33-
versionInRange, err := version.IsVersionStringInRange(RANConfig.ZTPVersion, "4.12", "")
33+
versionInRange, err := version.IsVersionStringInRange(RANConfig.ZTPVersion, "4.12.0-0", "")
3434
Expect(err).ToNot(HaveOccurred(), "Failed to compare ZTP version string")
3535

3636
if !versionInRange {

tests/cnf/ran/gitopsztp/tests/ztp-argocd-clusters-app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var _ = Describe("ZTP Argo CD Clusters Tests", Label(tsparams.LabelArgoCdCluster
2626
BeforeEach(func() {
2727
By("verifying that ZTP meets the minimum version")
2828

29-
versionInRange, err := version.IsVersionStringInRange(RANConfig.ZTPVersion, "4.11", "")
29+
versionInRange, err := version.IsVersionStringInRange(RANConfig.ZTPVersion, "4.11.0-0", "")
3030
Expect(err).ToNot(HaveOccurred(), "Failed to compare ZTP version string")
3131

3232
if !versionInRange {

tests/cnf/ran/gitopsztp/tests/ztp-argocd-hub-templating.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var _ = Describe("ZTP Argo CD Hub Templating Tests", Label(tsparams.LabelArgoCdH
3737
BeforeEach(func() {
3838
By("checking the ZTP version")
3939

40-
versionInRange, err := version.IsVersionStringInRange(RANConfig.ZTPVersion, "4.12", "")
40+
versionInRange, err := version.IsVersionStringInRange(RANConfig.ZTPVersion, "4.12.0-0", "")
4141
Expect(err).ToNot(HaveOccurred(), "Failed to check if ZTP version is in range")
4242

4343
if !versionInRange {
@@ -116,7 +116,7 @@ var _ = Describe("ZTP Argo CD Hub Templating Tests", Label(tsparams.LabelArgoCdH
116116
It("should create the policy successfully with a valid template", reportxml.ID("54240"), func() {
117117
By("checking the ZTP version")
118118

119-
versionInRange, err := version.IsVersionStringInRange(RANConfig.ZTPVersion, "4.16", "")
119+
versionInRange, err := version.IsVersionStringInRange(RANConfig.ZTPVersion, "4.16.0-0", "")
120120
Expect(err).ToNot(HaveOccurred(), "Failed to check if ZTP version is in range")
121121

122122
validTestPath := tsparams.ZtpTestPathTemplatingValid

tests/cnf/ran/gitopsztp/tests/ztp-argocd-node-delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var _ = Describe("ZTP Argo CD Node Deletion Tests", Label(tsparams.LabelArgoCdNo
3131
BeforeEach(func() {
3232
By("checking the ZTP version")
3333

34-
versionInRange, err := version.IsVersionStringInRange(RANConfig.ZTPVersion, "4.14", "")
34+
versionInRange, err := version.IsVersionStringInRange(RANConfig.ZTPVersion, "4.14.0-0", "")
3535
Expect(err).ToNot(HaveOccurred(), "Failed to check if ZTP version is in range")
3636

3737
if !versionInRange {

tests/cnf/ran/gitopsztp/tests/ztp-argocd-policies-app.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var _ = Describe("ZTP Argo CD Policies Tests", Label(tsparams.LabelArgoCdPolicie
3535
BeforeEach(func() {
3636
By("checking the ZTP version")
3737

38-
versionInRange, err := version.IsVersionStringInRange(RANConfig.ZTPVersion, "4.10", "")
38+
versionInRange, err := version.IsVersionStringInRange(RANConfig.ZTPVersion, "4.10.0-0", "")
3939
Expect(err).ToNot(HaveOccurred(), "Failed to check if ZTP version is in range")
4040

4141
if !versionInRange {
@@ -315,7 +315,7 @@ var _ = Describe("ZTP Argo CD Policies Tests", Label(tsparams.LabelArgoCdPolicie
315315
"the same file name", reportxml.ID("62260"), func() {
316316
By("checking the ZTP version")
317317

318-
versionInRange, err := version.IsVersionStringInRange(RANConfig.ZTPVersion, "4.14", "")
318+
versionInRange, err := version.IsVersionStringInRange(RANConfig.ZTPVersion, "4.14.0-0", "")
319319
Expect(err).ToNot(HaveOccurred(), "Failed to check if ZTP version is in range")
320320

321321
if !versionInRange {
@@ -355,7 +355,7 @@ var _ = Describe("ZTP Argo CD Policies Tests", Label(tsparams.LabelArgoCdPolicie
355355
"source-cr is used in PGT", reportxml.ID("63516"), func() {
356356
By("checking the ZTP version")
357357

358-
versionInRange, err := version.IsVersionStringInRange(RANConfig.ZTPVersion, "4.14", "")
358+
versionInRange, err := version.IsVersionStringInRange(RANConfig.ZTPVersion, "4.14.0-0", "")
359359
Expect(err).ToNot(HaveOccurred(), "Failed to check if ZTP version is in range")
360360

361361
if !versionInRange {
@@ -388,7 +388,7 @@ var _ = Describe("ZTP Argo CD Policies Tests", Label(tsparams.LabelArgoCdPolicie
388388
It("verifies custom and default source CRs can be included in the same policy", reportxml.ID("64407"), func() {
389389
By("checking the ZTP version")
390390

391-
versionInRange, err := version.IsVersionStringInRange(RANConfig.ZTPVersion, "4.14", "")
391+
versionInRange, err := version.IsVersionStringInRange(RANConfig.ZTPVersion, "4.14.0-0", "")
392392
Expect(err).ToNot(HaveOccurred(), "Failed to check if ZTP version is in range")
393393

394394
if !versionInRange {

tests/cnf/ran/gitopsztp/tests/ztp-bios-day-zero.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var _ = Describe("ZTP BIOS Configuration Tests", Label(tsparams.LabelBiosDayZero
2525

2626
// 75196 - Check if spoke has required BIOS setting values applied
2727
It("Verifies SNO spoke has required BIOS setting values applied", reportxml.ID("75196"), func() {
28-
versionInRange, err := version.IsVersionStringInRange(RANConfig.ZTPVersion, "4.17", "")
28+
versionInRange, err := version.IsVersionStringInRange(RANConfig.ZTPVersion, "4.17.0-0", "")
2929
Expect(err).ToNot(HaveOccurred(), "Failed to check if ZTP version is in range")
3030

3131
if !versionInRange {

tests/cnf/ran/gitopsztp/tests/ztp-cluster-instance-delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var _ = Describe("ZTP Siteconfig Operator's Cluster Instance Delete Tests",
3838
BeforeEach(func() {
3939
By("verifying that ZTP meets the minimum version")
4040

41-
versionInRange, err := version.IsVersionStringInRange(RANConfig.ZTPVersion, "4.17", "")
41+
versionInRange, err := version.IsVersionStringInRange(RANConfig.ZTPVersion, "4.17.0-0", "")
4242
Expect(err).ToNot(HaveOccurred(), "Failed to compare ZTP version string")
4343

4444
if !versionInRange {

tests/cnf/ran/gitopsztp/tests/ztp-siteconfig-day-two.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var _ = Describe("ZTP Siteconfig Operator's Day 2 configuration Test",
2828
BeforeEach(func() {
2929
By("verifying that ZTP meets the minimum version")
3030

31-
versionInRange, err := version.IsVersionStringInRange(RANConfig.ZTPVersion, "4.17", "")
31+
versionInRange, err := version.IsVersionStringInRange(RANConfig.ZTPVersion, "4.17.0-0", "")
3232
Expect(err).ToNot(HaveOccurred(), "Failed to compare ZTP version string")
3333

3434
if !versionInRange {

0 commit comments

Comments
 (0)