fabric8io / kubernetes-client

Java client for Kubernetes & OpenShift
http://fabric8.io
Apache License 2.0
3.39k stars 1.46k forks source link

Expose method that computes the default plural form for a given kind #6313

Open metacosm opened 3 weeks ago

metacosm commented 3 weeks ago

Is your enhancement related to a problem? Please describe

While there already is Pluralize.toPlural, this actually isn't enough since the kind should also be converted to lower case. It would be nice not to have to bother with knowing that detail.

Describe the solution you'd like

A getDefaultPluralFor(String kind) method on HasMetadata

Describe alternatives you've considered

No response

Additional context

No response

manusa commented 3 weeks ago

In general, I'd try to move away from Pluralize and rely on the real API plural which differs from the output of Pluralize.toPlural on many occasions.

metacosm commented 3 weeks ago

In general, I'd try to move away from Pluralize and rely on the real API plural which differs from the output of Pluralize.toPlural on many occasions.

I agree but there are cases where you don't get a choice and you'd still want to get the default plural version that is computed by Fabric8, without having to know how it's done. That's why it's called default, btw, not simply plural because it might indeed differ from the actual plural form.

manusa commented 3 weeks ago

I agree but there are cases where you don't get a choice and you'd still want to get the default plural version that is computed by Fabric8, without having to know how it's done. That's why it's called default, btw, not simply plural because it might indeed differ from the actual plural form.

What we want is precisely to get which cases are these so that we can avoid them altogether. For v7, it would be nice if we could get rid of all of this.

Do you have any examples of which cases might these be?

metacosm commented 3 weeks ago

I agree but there are cases where you don't get a choice and you'd still want to get the default plural version that is computed by Fabric8, without having to know how it's done. That's why it's called default, btw, not simply plural because it might indeed differ from the actual plural form.

Do you have any examples of which cases might these be?

When you're dealing with GenericKubernetesResource and need to get the plural form associated with the GVK to deal with RBACs for example. Ideally, you'd get the plural from the resource class but you might not have the resource class, only the GVK.

manusa commented 3 weeks ago

Ideally, you'd get the plural from the resource class but you might not have the resource class, only the GVK.

Right now we should be doing that by querying the cluster for the exposed resources just like kubectl does.

metacosm commented 3 weeks ago

Ideally, you'd get the plural from the resource class but you might not have the resource class, only the GVK.

Right now we should be doing that by querying the cluster for the exposed resources just like kubectl does.

I agree that would be the appropriate solution but it's just not possible when you perform that processing at build time and/or you might not be connected to the target cluster.

manusa commented 3 weeks ago

but it's just not possible when you perform that processing at build time and/or you might not be connected to the target cluster.

Why would you need the plural at build time or when not having direct access to the cluster?

From an operator generation context you should have that already available in the CRD. From any other context, I can't think of why would you need the plural.

metacosm commented 3 weeks ago

but it's just not possible when you perform that processing at build time and/or you might not be connected to the target cluster.

Why would you need the plural at build time or when not having direct access to the cluster?

To generate RBACs which happens at build time. More specifically, when the user is using GenericKubernetesResource for secondary resources, the processor might only get the GVK for the resource, in that case, the plural needs to be inferred from the kind only.

manusa commented 3 weeks ago

To generate RBACs which happens at build time. More specifically, when the user is using GenericKubernetesResource for secondary resources, the processor might only get the GVK for the resource, in that case, the plural needs to be inferred from the kind only.

Do you have an example or test in the JOSDK repo(s). For me it's still hard to see how the user might have (and provide) the info for the external resources and not be able to manage the plural (how is this dealt with in the regular OSDK? and so on)

metacosm commented 3 weeks ago

To generate RBACs which happens at build time. More specifically, when the user is using GenericKubernetesResource for secondary resources, the processor might only get the GVK for the resource, in that case, the plural needs to be inferred from the kind only.

Do you have an example or test in the JOSDK repo(s). For me it's still hard to see how the user might have (and provide) the info for the external resources and not be able to manage the plural (how is this dealt with in the regular OSDK? and so on)

For some more context, see the discussions at https://github.com/operator-framework/java-operator-sdk/pull/2515. For QOSDK, more specifically, see https://github.com/quarkiverse/quarkus-operator-sdk/pull/937/files#diff-b780cb662fc5c0a824655ac29ced7dca9efd35a33f771cd3f3a84a46f21b7cebR134-R147. When QOSDK processes the dependent resources (secondary resources), it's at a point where the user might not have provided the plural form (if they even knew about it) and since happens at build time, checking the API server would be meaningless.