-
Notifications
You must be signed in to change notification settings - Fork 39.9k
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
apimachinery: fix UnsafeGuessKindToResource for some classes of words #110053
apimachinery: fix UnsafeGuessKindToResource for some classes of words #110053
Conversation
Hi @michaelbeaumont. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
/assign @apelisse |
/ok-to-test Not sure if this breaks compatibility with anything. |
The https://github.com/kubernetes/code-generator uses https://pkg.go.dev/k8s.io/gengo/namer#NewAllLowercasePluralNamer so another option might be to use it here or make client-go use it instead of |
FWIW, this affects https://gateway-api.sigs.k8s.io/, which is sort of annoying (spent about 2-3 hours debugging why a test framework using 👍 on this change from me. |
/uncc |
/assign @deads2k |
Also hit this when using Gateway API's objects with dynamic fake client: Any (even rough) ETA for this? Any workarounds before this gets merged? |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
Why would you throw me under the bus? I've lgtm'd 6 months ago! 😄 |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: michaelbeaumont, pmalek The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/assign caesarxuchao |
I think we might have this code locked because changing it could break existing things and pluralizing english is hopeless unless we can call out to GPT-3 anyway. There should be fields to define both in CRDs to avoid this code being invoked, if that's not the case please let us know. |
@@ -137,10 +137,19 @@ func UnsafeGuessKindToResource(kind schema.GroupVersionKind) ( /*plural*/ schema | |||
} | |||
} | |||
|
|||
switch string(singularName[len(singularName)-1]) { | |||
case "s": | |||
switch { |
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.
/hold
This isn't a compatible change to make to this function. Anything using this function to auto-generate plural names from singular names would break when re-generating an existing object that this change impacts.
I think we should remove all non-test in-tree calls to this function (I only see a single call from DefaultRESTMapper#Add
, which I would also consider removing), mark it deprecated, file issues to public callers we find, and consider removing it in a future release.
If we want a new function that takes a singular name and pluralizes it that has this expanded behavior from the start (with a signature like AttemptToPluralize(singular string) (plural string)
), I guess I wouldn't object, but that doesn't need to live in k8s.io/apimachinery
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 believe that the use that bit me was in test code without an apiserver loaded. I can try to dig out the code in question; I believe it tries to pluralize "Gateway" as "Gatewaies", which was very confusing when I finally debugged it.
Removing this function would also be acceptable to me, but it's currently a trap for anyone testing the Gateway API.
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.
@evankanderson Can you dig that test code up? I'm positive I've also encountered this issue recently but can't find the relevant test code that would manifest the problem itself (other than calling UnsafeGuessKindToResource
with Gateway type).
https://grep.app/search?q=.UnsafeGuessKindToResource%28&case=true doesn't show that many public callers 👍
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 believe that we were getting hung up in tracker.Add
from this code:
https://github.com/kubernetes/client-go/blob/master/testing/fixture.go#L341
I also see some questionable usage in https://github.com/knative/pkg/blob/main/resolver/addressable_resolver.go#L167 and https://github.com/knative/pkg/blob/main/kref/knative_reference.go#L53, but the usage of ObjectTracker
from client-go/testing
seems most likely to cause problems, because I'm guessing that package is used many places.
You can see my work-around here:
// The fake tracker's `Add` method incorrectly pluralizes "gatewaies" using UnsafeGuessKindToResource,
// so create this via explicit call (per note in client-go/testing/fixture.go in tracker.Add)
fakeCreates := []runtime.Object{}
for _, x := range tr.Objects {
myGw, ok := x.(*gatewayapi.Gateway)
if ok {
fakegwapiclientset.Get(ctx).GatewayV1beta1().Gateways(myGw.Namespace).Create(ctx, myGw, metav1.CreateOptions{})
tr.SkipNamespaceValidation = true
fakeCreates = append(fakeCreates, myGw)
}
}
tr.WantCreates = append(fakeCreates, tr.WantCreates...)
/close Changing this function is not the right direction. I would be in favor of marking as deprecated and removing all in-tree calls to it, and adding the ability for fake clients to be told the accurate plural/singular mappings if needed. |
@liggitt: Closed this PR. In response to this:
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. |
@liggitt I'd like to move forward with this somehow but I'm having hard time understanding your proposal. E.g. how would you go about removing in-tree calls of this? There are multiple places where it's used in user facing code e.g. kubernetes/staging/src/k8s.io/apimachinery/pkg/api/meta/restmapper.go Lines 99 to 113 in 694698c
Would you suggest to mark |
It seems that using
If this would be accepted and is perceived as the direction that we can move forward with, I can submit a PR replacing usages of |
yes, mark deprecated and mark callers that rely on it as deprecated as well, pointing people to AddSpecific |
What type of PR is this?
/kind bug
What this PR does / why we need it:
Fixes guesses that
apimachinery
makes about resource names from a GVK.Which issue(s) this PR fixes:
Fixes kubernetes/client-go#1082
Special notes for your reviewer:
Does this PR introduce a user-facing change?