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

Match GroupVersionKind against specific version #34010

Merged
merged 1 commit into from
Oct 10, 2016

Conversation

soltysh
Copy link
Contributor

@soltysh soltysh commented Oct 4, 2016

Currently when multiple GVK match a specific kind in KindForGroupVersionKinds only the first will be matched, which not necessarily will be the correct one. I'm proposing to extend this to pick the best match, instead.

Here's my problematic use-case, of course it involves ScheduledJobs 😉:
I have a GroupVersions with batch/v1 and batch/v2alpha1 in that order. I'm calling KindForGroupVersionKinds with kind batch/v2alpha1 ScheduledJob and that currently results this matching first GroupVersion, instead of picking more concrete one. There's a clear description why it is on single GroupVersion, but GroupVersions should pick this more carefully.

@deads2k this is your baby, wdyt?

Match GroupVersionKind against specific version

This change is Reviewable

@soltysh soltysh added area/apiserver release-note-none Denotes a PR that doesn't merit a release note. labels Oct 4, 2016
@k8s-github-robot k8s-github-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 4, 2016
@deads2k
Copy link
Contributor

deads2k commented Oct 4, 2016

Looks reasonable to me, but this is definitely @smarterclayton's baby. :)

@deads2k deads2k assigned smarterclayton and unassigned deads2k Oct 4, 2016
@@ -268,13 +268,30 @@ type GroupVersions []GroupVersion

// KindForGroupVersionKinds identifies the preferred GroupVersionKind out of a list. It returns ok false
// if none of the options match the group.
func (gvs GroupVersions) KindForGroupVersionKinds(kinds []GroupVersionKind) (target GroupVersionKind, ok bool) {
func (gvs GroupVersions) KindForGroupVersionKinds(kinds []GroupVersionKind) (GroupVersionKind, bool) {
targets := []GroupVersionKind{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Always do var targets []GroupVersionKind

Copy link
Contributor

Choose a reason for hiding this comment

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

Always do var targets []GroupVersionKind

Not obvious to me. Why?

input: []GroupVersionKind{{Group: "policy", Version: "v1alpha1", Kind: "PodDisruptionBudget"}},
target: GroupVersionKind{Group: "policy", Version: "v1alpha1", Kind: "PodDisruptionBudget"},
ok: 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 all the other scenarios to this test.

}
if len(targets) == 1 {
return targets[0], true
} else if len(targets) > 1 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not an else

for _, k := range kinds {
if k == gvk {
return k, true
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem logically equivalent to what we had before - if no exact match exists, you need to pick the first target.

Copy link
Contributor

@smarterclayton smarterclayton left a comment

Choose a reason for hiding this comment

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

Requested changes

@soltysh
Copy link
Contributor Author

soltysh commented Oct 4, 2016

@smarterclayton all comments addressed ptal

@k8s-ci-robot
Copy link
Contributor

Jenkins unit/integration failed for commit 0d3ff1d3bac292b9830613df0ebfb968e70d4507. Full PR test history.

The magic incantation to run this job again is @k8s-bot unit test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@smarterclayton
Copy link
Contributor

Only allocate if you need it. This is a hot code path.

On Oct 4, 2016, at 1:54 PM, David Eads notifications@github.com wrote:

@deads2k commented on this pull request.

In pkg/api/unversioned/group_version.go
#34010:

@@ -268,13 +268,30 @@ type GroupVersions []GroupVersion

// KindForGroupVersionKinds identifies the preferred GroupVersionKind
out of a list. It returns ok false
// if none of the options match the group.
-func (gvs GroupVersions) KindForGroupVersionKinds(kinds
[]GroupVersionKind) (target GroupVersionKind, ok bool) {
+func (gvs GroupVersions) KindForGroupVersionKinds(kinds
[]GroupVersionKind) (GroupVersionKind, bool) {

  • targets := []GroupVersionKind{}

Always do var targets []GroupVersionKind

Not obvious to me. Why?


You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
#34010, or mute the thread
https://github.com/notifications/unsubscribe-auth/ABG_p1t1Igstl97b7OESIpnmi66qTNkRks5qwpLBgaJpZM4KNmXk
.

@soltysh
Copy link
Contributor Author

soltysh commented Oct 5, 2016

I had to drop one test case from pkg/runtime/scheme_test.go which was explicitly relying on picking the first object from GroupVersionKinds list, instead of the most matching one, @smarterclayton ptal

@@ -602,13 +602,6 @@ func TestConvertToVersion(t *testing.T) {
gv: unversioned.GroupVersion{Version: "__internal"},
out: &TestType1{A: "test"},
},
// prefers the first group version in the list
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't remove the test, change the output and then add a second test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

2nd test is not needed since the previous one is touching the conversion from external to internal if such GV is passed. I'll fix the output for this test, only.

@soltysh
Copy link
Contributor Author

soltysh commented Oct 5, 2016

Updated with reverted and fixed tests. @smarterclayton ptal

@soltysh
Copy link
Contributor Author

soltysh commented Oct 10, 2016

@smarterclayton bump, I'm blocked with this downstream, ptal

@deads2k deads2k added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 10, 2016
@k8s-github-robot
Copy link

@k8s-bot test this [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit 049ad98 into kubernetes:master Oct 10, 2016
@soltysh soltysh deleted the fix_edit_sj branch October 11, 2016 06:28
@flavianmissi
Copy link
Contributor

I see this didn't make it to v1.4.1, any idea of when we'll have a v1.4.2? (sorry if this is the wrong channel to ask, please do redirect me if there's a better one:)

@soltysh soltysh added this to the v1.4 milestone Oct 12, 2016
@soltysh
Copy link
Contributor Author

soltysh commented Oct 12, 2016

@jessfraz any chance to have this cherry-picked for 1.4.2?

@jessfraz jessfraz added the cherry-pick-approved Indicates a cherry-pick PR into a release branch has been approved by the release branch manager. label Oct 12, 2016
@jessfraz
Copy link
Contributor

will do!

@jessfraz jessfraz 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 Oct 12, 2016
@soltysh
Copy link
Contributor Author

soltysh commented Oct 12, 2016

Thank you!

k8s-github-robot pushed a commit that referenced this pull request Oct 13, 2016
#34468-#34416-#34010-origin-release-1.4

Automatic merge from submit-queue

Automated cherry pick of #33147 #34468 #34416 #34010 origin release 1.4

Cherry pick of #33147 #34468 #34416 #34010 on release-1.4.

#33147: fix base image pinning during upgrades via
#34468: Fix upgrade.sh image setup
#34416: hyperkube image: add cifs-utils
#34010: Match GroupVersionKind against specific version
@k8s-cherrypick-bot
Copy link

Commit found in the "release-1.4" branch appears to be this PR. Removing the "cherrypick-candidate" label. If this is an error find help to get your PR picked.

@flavianmissi
Copy link
Contributor

Looking forward to see this on GKE, thank you! o/

shyamjvs pushed a commit to shyamjvs/kubernetes that referenced this pull request Dec 1, 2016
…ck-of-#33147-kubernetes#34468-kubernetes#34416-kubernetes#34010-origin-release-1.4

Automatic merge from submit-queue

Automated cherry pick of kubernetes#33147 kubernetes#34468 kubernetes#34416 kubernetes#34010 origin release 1.4

Cherry pick of kubernetes#33147 kubernetes#34468 kubernetes#34416 kubernetes#34010 on release-1.4.

kubernetes#33147: fix base image pinning during upgrades via
kubernetes#34468: Fix upgrade.sh image setup
kubernetes#34416: hyperkube image: add cifs-utils
kubernetes#34010: Match GroupVersionKind against specific version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/apiserver cherry-pick-approved Indicates a cherry-pick PR into a release branch has been approved by the release branch manager. 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/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants