-
Notifications
You must be signed in to change notification settings - Fork 40.1k
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
Conversation
Looks reasonable to me, but this is definitely @smarterclayton's baby. :) |
@@ -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{} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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, | ||
}, |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requested changes
@smarterclayton all comments addressed ptal |
Jenkins unit/integration failed for commit 0d3ff1d3bac292b9830613df0ebfb968e70d4507. Full PR test history. The magic incantation to run this job again is |
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
// KindForGroupVersionKinds identifies the preferred GroupVersionKind
Always do var targets []GroupVersionKind Not obvious to me. Why? — |
I had to drop one test case from |
@@ -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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Updated with reverted and fixed tests. @smarterclayton ptal |
@smarterclayton bump, I'm blocked with this downstream, ptal |
@k8s-bot test this [submit-queue is verifying that this PR is safe to merge] |
Automatic merge from submit-queue |
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:) |
@jessfraz any chance to have this cherry-picked for 1.4.2? |
will do! |
Thank you! |
#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
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. |
Looking forward to see this on GKE, thank you! o/ |
…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
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
withbatch/v1
andbatch/v2alpha1
in that order. I'm callingKindForGroupVersionKinds
with kindbatch/v2alpha1 ScheduledJob
and that currently results this matching firstGroupVersion
, instead of picking more concrete one. There's a clear description why it is on singleGroupVersion
, butGroupVersions
should pick this more carefully.@deads2k this is your baby, wdyt?
This change is