Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort API Services by Kube-Version order #64004

Merged
merged 2 commits into from May 21, 2018

Conversation

mbohlool
Copy link
Contributor

@mbohlool mbohlool commented May 18, 2018

Sort API services based on kube-version format. If the version does not have kube-version format.

kube-version format: v[MajorVersion]((alpha|beta)[minorVersion])?
e.g. v1alpha1, v4, v21beta12

Sort base on:
Version type first: GA>Beta>Alpha
Major version then Minor version (if exists).

APIServices with kube-like versions (e.g. v1, v2beta1, etc.) will be sorted appropriately within each group. 

@k8s-ci-robot k8s-ci-robot added do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 18, 2018
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 18, 2018
@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels May 18, 2018
@mbohlool
Copy link
Contributor Author


func parseKubeVersion(v string) (majorVersion int, vType versionType, minorVersion int, ok bool) {
var err error
re := regexp.MustCompile("^v([\\d]+)(?:(alpha|beta)([\\d]+))?$")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move compile out to a package var and reuse

func parseKubeVersion(v string) (majorVersion int, vType versionType, minorVersion int, ok bool) {
var err error
re := regexp.MustCompile("^v([\\d]+)(?:(alpha|beta)([\\d]+))?$")
submatches := re.FindStringSubmatch(strings.ToLower(v))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't lowercase the string, should match exactly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what should we do if the version is v1Beta1? options: 1. consider it out of format, 2. consider it in-format and put it before v1beta1?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of format

@liggitt
Copy link
Member

liggitt commented May 18, 2018

need to update the docs on the version priority field in APIService

@liggitt
Copy link
Member

liggitt commented May 18, 2018

a few nits, lgtm otherwise


func parseKubeVersion(v string) (majorVersion int, vType versionType, minorVersion int, ok bool) {
var err error
re := regexp.MustCompile("^v([\\d]+)(?:(alpha|beta)([\\d]+))?$")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about rc releases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is to support kubernetes like versioning. I don't think we have rc in our API object's versioning.

@mbohlool mbohlool force-pushed the apiservice_order branch 2 times, most recently from 11ef8c6 to 1187391 Compare May 18, 2018 06:15
@mbohlool
Copy link
Contributor Author

/test pull-kubernetes-kubemark-e2e-gce

@mbohlool
Copy link
Contributor Author

/test pull-kubernetes-e2e-gce


const (
// Bigger the version type number, higher priority it is
versionTypeAlpha versionType = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be all iota, not zero: http://programming.guide/go/iota.html. Otherwise, alpha and beta are both zero.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvmd. iota is the index of the const declaration in the const block.

case ok1 && !ok2:
return 1
}
if v1type != v2type {
Copy link
Contributor

@sttts sttts May 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: confusing logic. Why not simple as:

if v1type != v2type { return int(v1type) - int(v2type) } 
if v1major != v2major { return v1major - v2major }
return v1minor - v2minor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that works too and simpler. fixed.

@@ -68,6 +68,11 @@ type APIServiceSpec struct {
// The primary sort is based on VersionPriority, ordered highest to lowest (20 before 10).
// The secondary sort is based on the alphabetical comparison of the name of the object. (v1.bar before v1.foo)
// Since it's inside of a group, the number can be small, probably in the 10s.
// In case of equal (or lack of) version priorities, the version string will be used to compute the order inside a group.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is "lack of" ? It default to zero.

@sttts
Copy link
Contributor

sttts commented May 18, 2018

Only a doc nit. Otherwise lgtm.

{"v1alpha2", "v1alpha1", true},
{"v1beta1", "v2alpha3", true},
{"v1alpha10", "v1alpha2", true},
{"v1beta10", "v1beta2", true},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add cases comparing kubversion against unformatted string and two unformatted strings please.

@deads2k
Copy link
Contributor

deads2k commented May 18, 2018

Just a request for a missing test case. lgtm

@mbohlool
Copy link
Contributor Author

Thanks @deads2k @sttts @liggitt. I addressed your comments. PTAL.

Copy link
Member

@lavalamp lavalamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few nits, sorry!

// Bigger the version type number, higher priority it is
versionTypeAlpha versionType = iota
versionTypeBeta versionType = iota
versionTypeGA versionType = iota
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Omit the second two iotas?

{"v1beta10", "v1beta2", true},
{"foo", "v1beta2", false},
{"bar", "foo", true},
{"version1", "version2", true}, // Non kube-like versions are sorted alphabetically
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add foo10 and foo1 or something else to demonstrate that it's lexicographic.

{
name: "case4",
versions: []string{"v1", "v2", "test", "final"},
expected: []string{"v2", "v1", "final", "test"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and maybe one here that also demonstrates lexicographic ordering.

@@ -68,6 +68,11 @@ type APIServiceSpec struct {
// The primary sort is based on VersionPriority, ordered highest to lowest (20 before 10).
// The secondary sort is based on the alphabetical comparison of the name of the object. (v1.bar before v1.foo)
// Since it's inside of a group, the number can be small, probably in the 10s.
// In case of equal version priorities, the version string will be used to compute the order inside a group.
// If the version string is kube-like, it will be used for ordering otherwise lexical order will be used.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the version string is "kube-like", it will sort above non "kube-like" version strings, which are ordered lexicographically. "Kube-like" versions start with a "v", then are followed by a number (the major version), then optionally the string "alpha" or "beta" and another number (the minor version). These are sorted first by GA > beta > alpha, and then within each group by comparing major version, then minor version. An example sorted list of versions: v10, v2, v1, v11beta2, v10beta3, v3beta1, v12alpha1, v11alpha2, foo1, foo10.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 18, 2018
@lavalamp
Copy link
Member

/approve

If we could get one last set of eyes to review the comment wording I proposed before we merge this that would be great (@liggitt?).

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 18, 2018
@mbohlool
Copy link
Contributor Author

/retest

@mbohlool
Copy link
Contributor Author

/retest

@@ -68,6 +68,12 @@ type APIServiceSpec struct {
// The primary sort is based on VersionPriority, ordered highest to lowest (20 before 10).
// The secondary sort is based on the alphabetical comparison of the name of the object. (v1.bar before v1.foo)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop this line, the adjusted secondary sort behavior is described below

// If the version string is "kube-like", it will sort above non "kube-like" version strings, which are ordered
// lexicographically. "Kube-like" versions start with a "v", then are followed by a number (the major version),
// then optionally the string "alpha" or "beta" and another number (the minor version). These are sorted first
// by GA > beta > alpha, and then within each group by comparing major version, then minor version. An example
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“group” in this context means ga/beta/alpha, but is easily confused with API group. Maybe just drop “within each group”?

@liggitt
Copy link
Member

liggitt commented May 19, 2018

If we could get one last set of eyes to review the comment wording I proposed before we merge this that would be great (@liggitt?).

one bit of the old field doc needs removing, one bit of the new I found confusing but don’t feel strongly about

@mbohlool
Copy link
Contributor Author

/test pull-kubernetes-e2e-kops-aws

@mbohlool
Copy link
Contributor Author

@liggitt Please take another look.

@liggitt
Copy link
Member

liggitt commented May 20, 2018

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 20, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lavalamp, liggitt, mbohlool

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel comment for consistent failures.

2 similar comments
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel comment for consistent failures.

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel comment for consistent failures.

@mbohlool
Copy link
Contributor Author

/test pull-kubernetes-e2e-gce

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels May 21, 2018
@mbohlool
Copy link
Contributor Author

/retest

@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit b87105a into kubernetes:master May 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants