Repository: knative/pkg
Pull request #2288 (2021-09-16 03:29:07)

Add IsNum to true when set `-0` to minimumVersion.Pre
This patch adds IsNum to true when set `-0` to minimumVersion.Pre.

For example, the version (`1.20.0-1095+9689d22dc3121e-dirty`) is not compared correctly:

```
2021/09/16 01:33:33 Failed to get k8s version kubernetes version "1.20.0-1095+9689d22dc3121e-dirty" is not compatible, need at least "1.20.0-" (this can be overridden with the env var "KUBERNETES_MIN_VERSION")
```

/cc @markusthoemmes @dprotaso 

knative-prow-robot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/knative/pkg/pull/2288#" title="Author self-approved">nak3</a>*
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please assign **rhuss** after the PR has been reviewed.
You can assign the PR to them by writing `/assign @rhuss` in a comment when ready.

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=knative%2Fpkg).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/knative/pkg/blob/main/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["rhuss"]} -->

Patch:
diff --git a/OWNERS_ALIASES b/OWNERS_ALIASES
index ec77fa987..cb55efa81 100644
--- a/OWNERS_ALIASES
+++ b/OWNERS_ALIASES
@@ -89,30 +89,6 @@ aliases:
   - spencerdillard
   - thisisnotapril
   - vaikas
-  knative-milestone-maintainers:
-  - ImJasonH
-  - ZhiminXiang
-  - andrew-su
-  - aslom
-  - chaodaiG
-  - chizhg
-  - csantanapr
-  - dprotaso
-  - evankanderson
-  - igsong
-  - julz
-  - lionelvillard
-  - markusthoemmes
-  - matzew
-  - n3wscott
-  - nak3
-  - navidshaikh
-  - rhuss
-  - shashwathi
-  - tanzeeb
-  - tcnghia
-  - vagababov
-  - vaikas
   knative-release-leads:
   - ZhiminXiang
   - evankanderson
diff --git a/version/version.go b/version/version.go
index 3cbd846ea..56b7ae958 100644
--- a/version/version.go
+++ b/version/version.go
@@ -66,8 +66,9 @@ func CheckMinimumVersion(versioner discovery.ServerVersionInterface) error {
 
 	// If no specific pre-release requirement is set, we default to "-0" to always allow
 	// pre-release versions of the same Major.Minor.Patch version.
+	// Set IsNum to true otherwise currentVersion.LT() below always returns true.
 	if len(minimumVersion.Pre) == 0 {
-		minimumVersion.Pre = []semver.PRVersion{{VersionNum: 0}}
+		minimumVersion.Pre = []semver.PRVersion{{VersionNum: 0, IsNum: true}}
 	}
 
 	// Return error if the current version is less than the minimum version required.


Test patch:
diff --git a/version/version_test.go b/version/version_test.go
index 6e18f3a5c..8d4cf3735 100644
--- a/version/version_test.go
+++ b/version/version_test.go
@@ -41,13 +41,16 @@ func TestVersionCheck(t *testing.T) {
 		wantError       bool
 	}{{
 		name:          "greater version (patch)",
-		actualVersion: &testVersioner{version: "v1.20.2"},
+		actualVersion: &testVersioner{version: "v1.20.0"},
 	}, {
 		name:          "greater version (patch), no v",
-		actualVersion: &testVersioner{version: "1.20.2"},
+		actualVersion: &testVersioner{version: "1.20.0"},
 	}, {
 		name:          "greater version (patch), pre-release",
-		actualVersion: &testVersioner{version: "1.20.2-kpn-065dce"},
+		actualVersion: &testVersioner{version: "1.20.0-kpn-065dce"},
+	}, {
+		name:          "greater version (patch), pre-release with build",
+		actualVersion: &testVersioner{version: "1.20.0-1095+9689d22dc3121e-dirty"},
 	}, {
 		name:            "greater version (patch), pre-release, envvar override",
 		actualVersion:   &testVersioner{version: "1.15.11-kpn-065dce"},