-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
The java generator produces a new for each type occurrence #5619
Comments
Hi @iocanel , and thanks for opening this super interesting discussion. The big show-stopper for me has been forward compatibility, imagine the following scenario.
This is nice from the deduplication POV, code size etc. etc. Your proposal is interesting, as it means that the user is still in control of "what to reuse", although it potentially has the same drawback explained above. For completeness, at some point, I have prototyped a Maven plugin to do the refactoring as a separate step: wdyt? |
More thoughts ... I think that the are three kinds of duplicates:
The simplest case to deal with is 2 as in most cases we want no reuse. Which brings us down to cross apiGroup (case 3) and beyond the known core model classes. I think that the safest thing to do is to do nothing out of the box but provide users with the ability to define what is meant to be reused via configuration. |
This is interesting, as it's valid reasoning, but based on assumptions. I like the idea of leaving this decision to the user though, and this is probably the deal-breaker for implementing this feature. |
I think that when it comes to core types, it safe enough to assume that if name (e.g. metadata) matches and shape matches then reuse. I really doubt that anyone would replicate them and not reuse them instead. Again, I am not talking about any type, but a handpicked set (like we do for BuildableReferences). As long as there is a way for the user to override our defaults I think it should be fine. |
I'm adding an example I'm aware of: https://github.com/Apicurio/apicurio-registry-operator/blob/94d81decf63b5692bde34a35d8a612caff43933f/api/v1/apicurioregistry_types.go#L291 But I agree with your reasoning @iocanel , I think that the question becomes, should we embed this functionality in the |
I think it needs to be in the |
I think that we need only class names and shapes, and configuring it with the "original" kubernetes |
Unfortunately, I don't have the time needed. |
Something interesting I encountered while playing with kubevirt. I have 17 different implementations for |
Hey @iocanel ! Sorry for the slow response, at the moment I'm pretty busy too 🙁 This way, we can start experimenting with the feature on a real-world use-case. |
This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions! |
Fixed in #5844 |
Describe the bug
It's not exactly a bug, it's more of a usability thing.
Currently, the java generator will produce a new class for each occurrence of a type in the CRD schema. This means that types that are frequently referenced, e.g.
metadata
,selector
and more are added multiple times.One obvious drawback is the size of the generated model (e.g. for kubevrit I got a model of around 3K classes).
Another issue, is that this breaks the visitor concept, since a single visitor is meant to visit all occurrences of type in the hierarchy.
What we could possibly do, is keep track of the name and structure of the objects we create and allow conditional reuse. I could see that working with a config fragment like:
This is just something that just come into my head, there are probably even better ways to approach this.
Fabric8 Kubernetes Client version
SNAPSHOT
Steps to reproduce
mvn clean install -Pgenerate-model
Expected behavior
Types being reused
Runtime
Kubernetes (vanilla)
Kubernetes API Server version
1.25.3@latest
Environment
Linux
Fabric8 Kubernetes Client Logs
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: