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

OpenAPI: Investigate kubernetes model code generation #6080

Closed
manusa opened this issue Jun 26, 2024 · 2 comments
Closed

OpenAPI: Investigate kubernetes model code generation #6080

manusa opened this issue Jun 26, 2024 · 2 comments
Assignees
Labels
component/kubernetes-model Deals with the kubernetes-model
Milestone

Comments

@manusa
Copy link
Member

manusa commented Jun 26, 2024

Description

Investigate possible improvements to the way we generate code today.

For example, a combination of Go type-inference plus OpenAPI processing would allow to include JavaDoc to the current types.
Further exploration might also allow to use OpenAPI exclusively to improve generation performance.

@manusa
Copy link
Member Author

manusa commented Jul 11, 2024

Status update

Kubernetes types

Generation from OpenAPI/Swagger JSON works and generates almost identical models for all of the Kubernetes types.

OpenShift types

Generation works, however models differ especially in class names.

The JSON produced by the OpenShift cluster contains mostly inlined schema definitions (as opposed to the Kubernetes one which has Component schema definitions for every class).
The generator PoC uses a customized InlineModelResolver that concatenates the parent field class with the field name, this means that several layers down we can get classes named such as ControlPlaneMachineSetSpecTemplateMachinesV1beta1MachineOpenshiftIoSpecMetadataOwnerReferences.

This poses 2 main problems:

  • Common API machinery Kubernetes classes are not referenced from the OpenShift ones (since they are inlined) -> duplication
  • Builder from the root classes be compatible with the legacy ones, since fields are initialized using withNewXxx, so this is not a problem.
    However, if the fluent builder API is not used from the root element, and approach such as . withXxx(new XxxBuilder()./*...*/.build()) is used, then this is not compatible with the previous models.

Blocker

kube-schema.json / validation-schema.json files can be used downstream to verify YAMLs and JSONs provided by users, we need to find a way to generate those with the current approach

Opinion

Even if there are going to be some breakages for users, this will be released in a major version.
If well documented, this shouldn't be that big of a problem

Generation using this approach is extremely easy and has a very low maintenance cost.

I'd seriously consider for the migration to the new approach.

@manusa manusa changed the title Investiage kubernetes model code generation Investigate kubernetes model code generation Jul 12, 2024
@manusa manusa changed the title Investigate kubernetes model code generation OpenAPI: Investigate kubernetes model code generation Jul 12, 2024
@manusa manusa added this to the 7.0.0 milestone Jul 12, 2024
@manusa manusa added the component/kubernetes-model Deals with the kubernetes-model label Jul 17, 2024
@manusa
Copy link
Member Author

manusa commented Jul 17, 2024

After internal discussion, it seems clear that we should go forward with this initiative.
I'm working #6130 to reflect all of the required stories and tasks.
This issue can be closed now.

@manusa manusa closed this as completed Jul 17, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in Eclipse JKube Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/kubernetes-model Deals with the kubernetes-model
Projects
None yet
Development

No branches or pull requests

1 participant