Repository: knative/pkg
Pull request #1944 (2020-12-07 14:35:05)

Default to the lowest pre-release version to be the minimum
As per title.

Several users have hit this inconvience already (pre-release versions are by definition smaller than "normal" versions) and we've added a more verbose log message in the past to accomodate.

I can't think of a situation where you would not want to actually allow a pre-release version of a specific Major.Minor.Patch level, if you do not specify a very specific pre-build number, so this always assumes "-0" if no other pre-release version is specified.

/assign @vagababov 

markusthoemmes: /assign @mattmoor 
knative-prow-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/knative/pkg/pull/1944#" title="Author self-approved">markusthoemmes</a>*

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

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

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

- ~~[OWNERS](https://github.com/knative/pkg/blob/master/OWNERS)~~ [markusthoemmes]

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":[]} -->
codecov[bot]: # [Codecov](https://codecov.io/gh/knative/pkg/pull/1944?src=pr&el=h1) Report
> Merging [#1944](https://codecov.io/gh/knative/pkg/pull/1944?src=pr&el=desc) (9fb9745) into [master](https://codecov.io/gh/knative/pkg/commit/beabf446d6e8f9a8021f1ec2a2660c9596de90f9?el=desc) (beabf44) will **decrease** coverage by `0.07%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/knative/pkg/pull/1944/graphs/tree.svg?width=650&height=150&src=pr&token=rlqpDnfxbO)](https://codecov.io/gh/knative/pkg/pull/1944?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #1944      +/-   ##
==========================================
- Coverage   68.93%   68.86%   -0.08%     
==========================================
  Files         208      208              
  Lines        8753     8755       +2     
==========================================
- Hits         6034     6029       -5     
- Misses       2446     2450       +4     
- Partials      273      276       +3     
```


| [Impacted Files](https://codecov.io/gh/knative/pkg/pull/1944?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [version/version.go](https://codecov.io/gh/knative/pkg/pull/1944/diff?src=pr&el=tree#diff-dmVyc2lvbi92ZXJzaW9uLmdv) | `87.50% <100.00%> (-12.50%)` | :arrow_down: |
| [test/gcs/mock/mock.go](https://codecov.io/gh/knative/pkg/pull/1944/diff?src=pr&el=tree#diff-dGVzdC9nY3MvbW9jay9tb2NrLmdv) | `90.32% <0.00%> (-2.16%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/knative/pkg/pull/1944?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/knative/pkg/pull/1944?src=pr&el=footer). Last update [beabf44...8ee2b48](https://codecov.io/gh/knative/pkg/pull/1944?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/version/version.go b/version/version.go
index 9e13c1d19..cac1399a4 100644
--- a/version/version.go
+++ b/version/version.go
@@ -61,6 +61,12 @@ func CheckMinimumVersion(versioner discovery.ServerVersionInterface) error {
 		return err
 	}
 
+	// 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.
+	if len(minimumVersion.Pre) == 0 {
+		minimumVersion.Pre = []semver.PRVersion{{VersionNum: 0}}
+	}
+
 	// Compare returns 1 if the first version is greater than the
 	// second version.
 	if currentVersion.LT(minimumVersion) {


Test patch:
diff --git a/version/version_test.go b/version/version_test.go
index a2b9070be..d3ac416fc 100644
--- a/version/version_test.go
+++ b/version/version_test.go
@@ -52,7 +52,6 @@ func TestVersionCheck(t *testing.T) {
 		name:            "greater version (patch), pre-release, envvar override",
 		actualVersion:   &testVersioner{version: "1.15.11-kpn-065dce"},
 		versionOverride: "1.15.11",
-		wantError:       true,
 	}, {
 		name:            "greater version (patch), pre-release, envvar override, -0 hack",
 		actualVersion:   &testVersioner{version: "1.15.11-kpn-065dce"},
@@ -69,7 +68,6 @@ func TestVersionCheck(t *testing.T) {
 	}, {
 		name:          "same version with pre-release",
 		actualVersion: &testVersioner{version: "v1.17.0-k3s.1"},
-		wantError:     true,
 	}, {
 		name:          "smaller version",
 		actualVersion: &testVersioner{version: "v1.14.3"},