-
Notifications
You must be signed in to change notification settings - Fork 39.8k
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
use specified discovery information if possible #50012
Conversation
Is this easily unit testable? |
// TODO only do this if it supports listing | ||
versionMapper.Add(gv.WithKind(resource.Kind+"List"), scope) | ||
versionMapper.AddSpecific(gv.WithKind(resource.Kind+"List"), plural, singular, scope) |
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.
What if ListKind
is not Kind
+ "List"? Looks like APIResource
struct does not expose this information so we cannot use it here.
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.
What if ListKind is not Kind + "List"? Looks like APIResource struct does not expose this information so we cannot use it here.
Hrm. Not fixable in this pull.
I delegated one to the other, so the existing callers test the core functionality. The actual discovery bits? Not easily. An integration test can't, an e2e test maybe, but it would be a disruptive one (affects global discovery). |
You don't think you could unit test NewRESTMapper? |
/assign mbohlool |
@ironcladlou has an integration test that could be made to exercise this :) |
Here's an integration test that exercises discovery and which will fail whenever the generated CRD's singular name ends with an "s". |
// TODO only do this if it supports listing | ||
versionMapper.Add(gv.WithKind(resource.Kind+"List"), scope) | ||
versionMapper.AddSpecific(gv.WithKind(resource.Kind+"List"), plural, singular, scope) |
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.
adding the Kind+List to the non-list singular/plural resources doesn't look right... the Add of the Kind+"List"
previously did the following:
Add(schema.GroupVersionKind{Group:"mygroup.example.com", Version:"v1beta1", Kind:"MyObj"})
m.singularToPlural[{mygroup.example.com v1beta1 myobj}] = {mygroup.example.com v1beta1 myobjs}
m.pluralToSingular[{mygroup.example.com v1beta1 myobjs}] = {mygroup.example.com v1beta1 myobj}
m.resourceToKind[{mygroup.example.com v1beta1 myobj}] = mygroup.example.com/v1beta1, Kind=MyObj
m.resourceToKind[{mygroup.example.com v1beta1 myobjs}] = mygroup.example.com/v1beta1, Kind=MyObj
m.kindToPluralResource[mygroup.example.com/v1beta1, Kind=MyObj] = {mygroup.example.com v1beta1 myobjs}
m.kindToScope[mygroup.example.com/v1beta1, Kind=MyObj] = namespace
Add(schema.GroupVersionKind{Group:"mygroup.example.com", Version:"v1beta1", Kind:"MyObjList"})
m.singularToPlural[{mygroup.example.com v1beta1 myobjlist}] = {mygroup.example.com v1beta1 myobjlists}
m.pluralToSingular[{mygroup.example.com v1beta1 myobjlists}] = {mygroup.example.com v1beta1 myobjlist}
m.resourceToKind[{mygroup.example.com v1beta1 myobjlist}] = mygroup.example.com/v1beta1, Kind=MyObjList
m.resourceToKind[{mygroup.example.com v1beta1 myobjlists}] = mygroup.example.com/v1beta1, Kind=MyObjList
m.kindToPluralResource[mygroup.example.com/v1beta1, Kind=MyObjList] = {mygroup.example.com v1beta1 myobjlists}
m.kindToScope[mygroup.example.com/v1beta1, Kind=MyObjList] = namespace
with this change, it does:
Add(schema.GroupVersionKind{Group:"mygroup.example.com", Version:"v1beta1", Kind:"MyObj"})
m.singularToPlural[{mygroup.example.com v1beta1 myobj}] = {mygroup.example.com v1beta1 myobjs}
m.pluralToSingular[{mygroup.example.com v1beta1 myobjs}] = {mygroup.example.com v1beta1 myobj}
m.resourceToKind[{mygroup.example.com v1beta1 myobj}] = mygroup.example.com/v1beta1, Kind=MyObj
m.resourceToKind[{mygroup.example.com v1beta1 myobjs}] = mygroup.example.com/v1beta1, Kind=MyObj
m.kindToPluralResource[mygroup.example.com/v1beta1, Kind=MyObj] = {mygroup.example.com v1beta1 myobjs}
m.kindToScope[mygroup.example.com/v1beta1, Kind=MyObj] = namespace
Add(schema.GroupVersionKind{Group:"mygroup.example.com", Version:"v1beta1", Kind:"MyObjList"})
m.singularToPlural[{mygroup.example.com v1beta1 myobj}] = {mygroup.example.com v1beta1 myobjs}
m.pluralToSingular[{mygroup.example.com v1beta1 myobjs}] = {mygroup.example.com v1beta1 myobj}
m.resourceToKind[{mygroup.example.com v1beta1 myobj}] = mygroup.example.com/v1beta1, Kind=MyObjList
m.resourceToKind[{mygroup.example.com v1beta1 myobjs}] = mygroup.example.com/v1beta1, Kind=MyObjList
m.kindToPluralResource[mygroup.example.com/v1beta1, Kind=MyObjList] = {mygroup.example.com v1beta1 myobjs}
m.kindToScope[mygroup.example.com/v1beta1, Kind=MyObjList] = namespace
so it's overwriting the resourceToKind maps to point to the List kinds, which is not right.
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.
I'm actually not sure what the purpose of adding the Kind+"List" was previously, given that the resource names it guessed were so wrong. the only thing correct was the scope
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.
@deads2k would be good to get this fixed for 1.8 (the plural thing, not necessarily the list bit)
Automatic merge from submit-queue Change test to work around restmapper pluralization bug Fixes kubernetes#50022 Works around the pluralization bug to unblock the queue. Once the restmapper bug is fixed in kubernetes#50012, we should add tests specifically for unconventional singular/plural word endings.
Are we still shooting for 1.7 here? I also have the same question about If we don't want to merge this for 1.7 please remove it from v1.7 milestone. |
Adding do-not-merge/release-note-label-needed because the release note process has not been followed. |
|
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: deads2k, liggitt Associated issue: 49948 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
verified by making NewRandomNameCustomResourceDefinition return a resource with unconventional pluralization and running
would like to see a follow up that exercises unconventional pluralization in a test |
/retest Review the full test history for this PR. |
/retest |
1 similar comment
/retest |
/retest |
/retest Review the full test history for this PR. |
/test all [submit-queue is verifying that this PR is safe to merge] |
Automatic merge from submit-queue |
@deads2k: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
picked to 1.7 in #52545 |
Commit found in the "release-1.7" branch appears to be this PR. Removing the "cherrypick-candidate" label. If this is an error find help to get your PR picked. |
Fixes #49948
This uses the available discovery information if available, but it seems we never updated "normal" resources to show the singular name, so its often not available. I've left this code compatible.
@enisoc @ash2k
@kubernetes/sig-api-machinery-misc