Skip to content

Commit b916d74

Browse files
fix(api): declare OpenAPIModelName for apps types so SSA resolves catalog kinds
After the k8s 0.35 bump, server-side apply of any apps.cozystack.io kind (e.g. Bucket) fails at field management with "no corresponding type for apps.cozystack.io/v1alpha1, Kind=Bucket", blocking backupstrategy-controller and the whole install. The apps API multiplexes every catalog kind (Bucket, Postgres, …) onto the single Application Go type via Scheme.AddKnownTypeWithName. The SSA field manager attaches a kind's GroupVersionKind to the Application OpenAPI model only when the model's name matches the name the apiserver's DefinitionNamer computed for it. Since Kubernetes 0.35 the DefinitionNamer keys that lookup by Scheme.ToOpenAPIDefinitionName (the "friendly" reversed-path form, com.github.cozystack…Application) while the model builder still uses the Go import-path form. With no OpenAPIModelName the two disagree, the GVK extension is never attached, and the type converter ends up with no apps kinds at all. Declare OpenAPIModelName on Application/ApplicationList/ApplicationStatus so GetCanonicalTypeName, ToOpenAPIDefinitionName and the generated openapi map key all agree on the friendly form. This is done via the +k8s:openapi-model-package package tag plus hand-written methods rather than code-generator's --output-model-name-file flag, because that flag also rewrites zz_generated.model_name.go inside the read-only apimachinery / 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. Assisted-By: Claude <[email protected]> Signed-off-by: Myasnikov Daniil <[email protected]>
1 parent 1ea4eb4 commit b916d74

3 files changed

Lines changed: 64 additions & 7 deletions

File tree

‎pkg/apis/apps/v1alpha1/doc.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ limitations under the License.
1515
*/
1616

1717
// +k8s:openapi-gen=true
18+
// +k8s:openapi-model-package=com.github.cozystack.cozystack.pkg.apis.apps.v1alpha1
1819
// +k8s:deepcopy-gen=package
1920
// +k8s:conversion-gen=github.com/cozystack/cozystack/pkg/apis/apps
2021
// +k8s:conversion-gen=k8s.io/apiextensions-apiserver/pkg/apis/apiextensions
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Copyright 2025 The Cozystack Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
// OpenAPIModelName pins the OpenAPI model name for the apps.cozystack.io
20+
// types. This is hand-written (not generated) on purpose.
21+
//
22+
// The apps API multiplexes every catalog kind (Bucket, Postgres, …) onto the
23+
// single Application Go type via Scheme.AddKnownTypeWithName. Server-side-apply
24+
// field management resolves a kind by matching the model's OpenAPI name against
25+
// the name the apiserver's DefinitionNamer computed for it. Since Kubernetes
26+
// 0.35 the DefinitionNamer keys that lookup by Scheme.ToOpenAPIDefinitionName
27+
// (the "friendly" reversed-path form, e.g. com.github.cozystack…Application),
28+
// while the model builder still looks it up by the Go import-path form. When a
29+
// type has no OpenAPIModelName the two disagree, the group-version-kind
30+
// extension is never attached to the Application model, and the SSA type
31+
// converter ends up with no entry for any apps kind ("no corresponding type for
32+
// apps.cozystack.io/v1alpha1, Kind=Bucket"). Declaring OpenAPIModelName makes
33+
// GetCanonicalTypeName, ToOpenAPIDefinitionName and the generated openapi map
34+
// key all agree on the friendly form, so the extension attaches again.
35+
//
36+
// code-generator's openapi-gen could emit these via --output-model-name-file,
37+
// but that also rewrites zz_generated.model_name.go in the read-only apimachinery
38+
// / apiextensions module-cache packages the shared gen_openapi helper always
39+
// passes as inputs, which fails on any consumer (including CI) that vendors deps
40+
// from the module cache. Keeping the methods here sidesteps that; add one for
41+
// every new apps.cozystack.io type.
42+
//
43+
// The returned string must match apiPrefix in pkg/cmd/server/openapi.go.
44+
45+
func (in Application) OpenAPIModelName() string {
46+
return "com.github.cozystack.cozystack.pkg.apis.apps.v1alpha1.Application"
47+
}
48+
49+
func (in ApplicationList) OpenAPIModelName() string {
50+
return "com.github.cozystack.cozystack.pkg.apis.apps.v1alpha1.ApplicationList"
51+
}
52+
53+
func (in ApplicationStatus) OpenAPIModelName() string {
54+
return "com.github.cozystack.cozystack.pkg.apis.apps.v1alpha1.ApplicationStatus"
55+
}

‎pkg/generated/openapi/zz_generated.openapi.go‎

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)