[Backport release-1.6] fix(api): declare OpenAPIModelName for core and sdn types - #3812
Merged
Merged
Conversation
The aggregated apiserver publishes the core.cozystack.io and sdn.cozystack.io models under their Go import path, so a $ref to any of them does not resolve and client-side validation fails on every resource of those groups, not only the one named in the error: error validating data: SchemaError(…core/v1alpha1.Option.spec): unknown model in reference: "github.com~1cozystack~1…v1alpha1.OptionSpec" Since Kubernetes 0.35 the apiserver's DefinitionNamer.GetDefinitionName returns the model name it is handed verbatim; it no longer converts the Go import-path form into the "friendly" reversed-path form. Whatever name the generated openapi map uses therefore becomes both the published definition key and, JSON pointer escaped, the $ref pointing at it. A name containing "/" ships as a definition keyed on the raw path while every reference to it spells each slash "~1", and clients resolve a $ref by trimming "#/definitions/" without unescaping (kube-openapi pkg/util/proto/document.go). The two spellings never meet, the reference dangles, and validation of the whole document fails. Mirror b916d74, which fixed the same disagreement for apps: add the +k8s:openapi-model-package marker to each doc.go and declare OpenAPIModelName for all 11 core and 9 sdn types, so GetCanonicalTypeName, Scheme.ToOpenAPIDefinitionName and the generated map key all agree on a slash-free dotted name. That takes the number of slash-bearing definition names in the published document from 20 to 0. The methods are hand-written rather than emitted by openapi-gen's --output-model-name-file because that flag also rewrites zz_generated.model_name.go inside the read-only apimachinery and apiextensions module-cache packages the shared gen_openapi helper always passes as inputs, which fails on any consumer including CI that vendors deps from the cache. With the marker in place openapi-gen emits Type{}.OpenAPIModelName() for every type it references, so a future type without a method fails the build instead of silently reintroducing a Go-path name. The generated openapi is the output of the root `make generate`; nothing else in the generated tree moved. kubectl apply --validate has been broken against any cozystack-api built after 2026-07-21 on every resource, and this shipped in v1.6.0 and v1.6.1. In e2e it surfaces as the platform install hanging on cozy-backup-controller/backupstrategy-controller, which takes tenant-root and everything behind cozystack-basics with it. Refs: #3806 Assisted-By: Claude <noreply@anthropic.com> Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com> (cherry picked from commit 5f3ad9c)
Nothing asserted that a published definition name contains no slash, which is why the core and sdn groups shipped as Go import paths in v1.6.0 and v1.6.1 without anyone noticing. The same omission on a future group would be just as invisible. TestDefinitionNamesAreDottedModelNames fails on any definition name containing "/", names the offender and points at the fix (the +k8s:openapi-model-package marker plus an OpenAPIModelName method). TestDefinitionRefsResolve is the failure mode itself: it builds each $ref the way kube-openapi's builder does, JSON pointer escaped, then resolves it the way a client does, trimming "#/definitions/" with no unescaping, and reports any that dangles. It also checks the declared Dependencies against the published names, which catches a group whose types disagree with each other rather than uniformly. Both assert the invariant instead of listing today's 20 names, so a new group that omits the marker is caught rather than a changed count, and both guard against going vacuous if the definition map is ever emptied or stops covering cozystack's own types. Both fail on the pre-fix tree: the first names all 20 offending definitions, and the second reproduces the reported error verbatim, down to "github.com~1cozystack~1cozystack~1pkg~1apis~1core~1v1alpha1.OptionSpec". Refs: #3806 Assisted-By: Claude <noreply@anthropic.com> Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com> (cherry picked from commit cea1703)
1 task
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Backport of #3808 to
release-1.6.