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

Kubernetes and Kubebuilder use different mechanisms to generate plurals #3402

Closed
mrueg opened this issue May 10, 2023 · 11 comments
Closed

Kubernetes and Kubebuilder use different mechanisms to generate plurals #3402

mrueg opened this issue May 10, 2023 · 11 comments
Assignees
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/bug Categorizes issue or PR as related to a bug. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Milestone

Comments

@mrueg
Copy link
Member

mrueg commented May 10, 2023

What broke? What's expected?

Kubernetes uses a custom mechanism to guess and generate plurals for CRDs in https://github.com/kubernetes/apimachinery/blob/master/pkg/api/meta/restmapper.go#L126

Kubebuilder uses https://github.com/gobuffalo/flect which has its own custom set of rules.

return flect.Pluralize(strings.ToLower(singular))

Although one could argue that the method kubernetes uses is broken and not ideal, it would be great if kubebuilder could apply the same default mechanism to generate plurals so it is easier for kubernetes clients to resolve a resourceplural from a GroupVersionKind mapping.

Reproducing this issue

No response

KubeBuilder (CLI) Version

3.10.0

PROJECT version

No response

Plugin versions

No response

Other versions

No response

Extra Labels

No response

@camilamacedo86
Copy link
Member

camilamacedo86 commented May 23, 2023

It has a proposed solution in : #3408
It seems very reasonable ask.

So, I am adding triage accepted.

@camilamacedo86 camilamacedo86 added help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. triage/accepted Indicates an issue or PR is ready to be actively worked on. labels May 23, 2023
@lauchokyip
Copy link
Contributor

There are still some discussions happening on this thread kubernetes/kube-state-metrics#2065, should we wait until the consensus is made ?

@rexagod
Copy link
Member

rexagod commented May 27, 2023

Boiling down that thread, the overall ask is to have a de-facto way of pluralizing that helps keep the resource names consistent throughout the ecosystem. I believe using the same logic as apimachinery should allow us to achieve that.

@lauchokyip
Copy link
Contributor

/assign

@Kavinjsir
Copy link
Contributor

Hey @mrueg @rexagod , would you provide some cases/code snippets that come with such an attempt to make the plural consistent? I'm trying to understand how the consistent plural system can help kubernetes clients to resolve a resourceplural from a GroupVersionKind mapping.

@rexagod
Copy link
Member

rexagod commented May 31, 2023

We've had to extract and match plurals to avoid instances where there may be discrepancies between the expected and actual plurals.

@rexagod
Copy link
Member

rexagod commented May 31, 2023

Enforcing a common "de-facto" standard through kubebuilder will solve such cases to a great extent.

@ashutosh887
Copy link
Contributor

Should I take this up? @Kavinjsir @varshaprasad96 @camilamacedo86

@Sajiyah-Salat
Copy link
Contributor

Hello @camilamacedo86 It looks like code issue. Should I work on this?
I have gone through the pr. understood somewhat maybe. I would give it a try if possibe.
If there is anything else I should know or refer to let me know.

@camilamacedo86 camilamacedo86 removed the good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. label Nov 14, 2023
@camilamacedo86 camilamacedo86 added this to the priority milestone Nov 14, 2023
@joelanford
Copy link
Member

I'm -1 on this change. From an objective grammatical perspective, Kubebuilder's implementation is clearly better than apimachinery's based on the test case changes in the PR. If I'm a kubebuilder user and I see Kubebuilder generate an incorrect plural, I would expect to either notice and fix it myself OR have a reviewer notice it and ask me to fix it, thus adding friction that just gets us back to where things are now.

The GoDoc for the apimachinery function says:

// UnsafeGuessKindToResource converts Kind to a resource name.
// Broken. This method only "sort of" works when used outside of this package. It assumes that Kinds and Resources match
// and they aren't guaranteed to do so.

So "Unsafe" is in the name of the function, and "Broken" is in the GoDoc. It also admits that the function only sort of works when used outside that package. Kubebuilder is outside that package. Why would we want to use it?

Although one could argue that the method kubernetes uses is broken and not ideal, it would be great if kubebuilder could apply the same default mechanism to generate plurals so it is easier for kubernetes clients to resolve a resourceplural from a GroupVersionKind mapping.

But that function is unsafe and broken. Kubebuilder has been in the wild for years generating different plurals. IMO no client should ever expect to correctly resolve a resourceplural from a GVK unless they are using a REST mapper.

@camilamacedo86
Copy link
Member

camilamacedo86 commented May 21, 2024

+1000 for @joelanford comments
I think we can convey in defer this one and the requested change could either be proposed to apimachinery.
Why not change there and to do as Kubebuiler does?
It take a while for we end up the plural mechanism which seems more accurate and better then the one used in apimachinery.

On top of that as I raised concerns before it will be a significant breaking change for the users.
So, I am closing this one as reject but if you see that it should be re-opened please feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/bug Categorizes issue or PR as related to a bug. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
8 participants