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

Replace Go model generation for istio #6426

Open
manusa opened this issue Oct 7, 2024 · 1 comment
Open

Replace Go model generation for istio #6426

manusa opened this issue Oct 7, 2024 · 1 comment
Assignees
Labels

Comments

@manusa
Copy link
Member

manusa commented Oct 7, 2024

Description

Part of #6130

Replace model generation for istio module with new OpenAPI approach.

Note

For extension models there are going to be multiple conflicts with the previously generated code.

Tasks

  • Remove build-helper-maven-plugin
  • Remove maven-antrun-plugin from the generate profile
  • Remove jsonschema2pojo-maven-plugin from the generate profile
  • Consolidate all extension models to the same module (certmanager, tekton, and so on all have multiple model generator modules)
  • Configure the openapi-model-generator-maven-plugin plugin to generate the specific classes.
  • Remove the go-related files and directories (Makefile, cmd)
  • Remove invocation from the generateModel.sh script
@manusa
Copy link
Member Author

manusa commented Oct 23, 2024

Difficulties for implementation

Problem 1: proto-go tag mismatch

Istio APIs (https://github.com/istio/api) are generated from protobuf types by using the buf tool.
Some of the APIs have mismatched or inconsistent comment and field tags for patchMergeKey and patchStrategy configurations.
This is the case for example for istio.io/api/meta/v1alpha1.IstioStatus (and others).
When running the Open API code generation this leads to errors such as:

panic: OpenAPI code generation error (generated_istio_openapi): failed executing generator: some targets had errors: Tags in comment and struct should match for member (Conditions) of (istio.io/api/meta/v1alpha1.IstioStatus)

The problem is not easy to address.
Under the hood, buff (in this case v1) is using protoc-gen-go for the Go code generation.
This plugin does not offer any way to configure the generated Go field tags, which are mostly hard-coded (as can be seen in the following line: https://github.com/golang/protobuf/blob/75de7c059e36b64f01d0dd234ff2fff404ec3374/protoc-gen-go/generator/generator.go#L2227)

The only way to fix this is by tampering with the parsed gen-go types and fix the error manually.

Problem 2: Customized CRD generation using their own fork of protoc-gen-crd

https://github.com/istio/tools/blob/83e015b9f4d9b5107bf76e8bbf683385190294c8/cmd/protoc-gen-crd

The generated types xxx.pb.go in https://github.com/istio/api/ don't match the structure of the OpenAPI defined in the CRDs.

The CRDs are generated their customized protoc-gen-crd buf plugin.

In order to have proper OpenAPI types, we need to use the types that are available in the https://github.com/istio/client-go/ repository instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant