Skip to content

Add model name generator - #563

Merged
k8s-ci-robot merged 2 commits into
kubernetes:masterfrom
jpbetz:named-model-gen
Sep 9, 2025
Merged

k8s-ci-robot merged 2 commits into
kubernetes:masterfrom
jpbetz:named-model-gen

Conversation

@jpbetz

@jpbetz jpbetz commented Sep 8, 2025 •

Copy link
Copy Markdown
Contributor

This moves from a reflection based approach to OpenAPI model naming to a declarative approach.

OpenAPIModelName() receiver functions to access OpenAPI model names of API types are generated into zz_generated.model_name.go files. This allows API authors to declare the desired OpenAPI model packages when the model name derived from the go package path is not desirable.

This PR also migrates the kubernetes API to use this generator (all OpenAPI model names remain the same).

For example:

// doc.go

// +k8s:openapi-gen=true
// +k8s:deepcopy-gen=package
// +k8s:protobuf-gen=package
// +k8s:prerelease-lifecycle-gen=true
// +k8s:openapi-model-package=io.k8s.api.core.v1

// +groupName=
package v1

Generates:

// zz_generated.model_name.go
func (in Pod) OpenAPIModelName() string {
	return "io.k8s.api.core.v1.Pod"
}

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 8, 2025
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 8, 2025
@jpbetz
jpbetz force-pushed the named-model-gen branch 2 times, most recently from 052f613 to 9ea3e5e Compare September 8, 2025 22:06
@jpbetz
jpbetz force-pushed the named-model-gen branch 3 times, most recently from 6572856 to d411358 Compare September 9, 2025 15:11
@jpbetz

jpbetz commented Sep 9, 2025

Copy link
Copy Markdown
Contributor Author

@BenTheElder @Jefftree @thockin

I've moved the codegen part of this into openapi-gen. This is a backward compatible change that enables us to switch away from go package name reflection in k8s.

Signed-off-by: Joe Betz <jpbetz@google.com>
Signed-off-by: Joe Betz <jpbetz@google.com>

@thockin thockin left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

I am not intimately familair with this generator but this PR all seems reasonable to me :)

"the base Go import-path under which to generate results")
fs.StringVar(&args.OutputFile, "output-file", "generated.openapi.go",
"the name of the file to be generated")
fs.StringVar(&args.OutputModelNameFile, "output-model-name-file", "",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not output to the same file?

EDIT: Oh I see. 1 Generator -> 1 file. Probably not worth changing, but IMO outputting to a single file would be cleaner, if we run across similar things in other generators. Unless there's a reason this is better that I am missing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one file for the generated openapi definition, and there are N files for all the zz_geneated.model_name.go files, one for each package containing types that need this function added. Those files are very similar to deep copy generated files.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OH RIGHT. Nevermind me :)

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 9, 2025
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jpbetz, thockin

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot
k8s-ci-robot merged commit d67c058 into kubernetes:master Sep 9, 2025
timuthy added a commit to timuthy/gardener that referenced this pull request Feb 4, 2026
The generation needs to be adapted due to kubernetes/kube-openapi#563
timuthy added a commit to timuthy/gardener that referenced this pull request Feb 6, 2026
The generation needs to be adapted due to kubernetes/kube-openapi#563
timuthy added a commit to timuthy/gardener that referenced this pull request Feb 6, 2026
The generation needs to be adapted due to kubernetes/kube-openapi#563
timuthy added a commit to timuthy/gardener that referenced this pull request Feb 11, 2026
The generation needs to be adapted due to kubernetes/kube-openapi#563
gardener-prow Bot pushed a commit to gardener/gardener that referenced this pull request Feb 13, 2026
…`v0.23.1`, `sigs.k8s.io/controller-tools` to `v0.20.0` (#13982)

* `make tidy && make generate`

* Solve `OpenTelemetry-Operator` dependency issue

The `OpenTelemetry-Operator` includes dependencies to an older version of `sigs.k8s.io/controller-runtime` which is incompatible with the version (v0.23) used in Gardener.
Copying the API packages solves the dependency conflict for now.
See open-telemetry/opentelemetry-operator#4667 for more information.

* Adapt to incompatible changes

* Adapt `OpenAPI` generation

The generation needs to be adapted due to kubernetes/kube-openapi#563

* Migrate to `k8s.io/client-go/tools/events`

Motivated by kubernetes-sigs/controller-runtime#3262

* Refactor: Remove obsolete `rest.Config` constructor

* Add `ReconciliationTimeout` panel

Add `ReconciliationTimeout` panel to the controller details dashboard. The uses the newly introduced `controller_runtime_reconcile_timeouts_total metric` metric (see kubernetes-sigs/controller-runtime#3382).

* Change `NodeAgentAuthorizer` integration test

Don't use the event recorder to test patch permissions.
We've seen cases where the event recorder drops events if they are recorded too quickly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants