From 933272d3333c0fff1c5fd3e01cf5383332fcca37 Mon Sep 17 00:00:00 2001 From: Maciej Szulik Date: Tue, 12 Mar 2024 11:31:47 +0100 Subject: [PATCH 1/2] kube_codegen: expose applyconfig-openapi-schema flag for client generation --- staging/src/k8s.io/code-generator/kube_codegen.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/staging/src/k8s.io/code-generator/kube_codegen.sh b/staging/src/k8s.io/code-generator/kube_codegen.sh index 1f3f83abadd..6ca83a6c5d3 100755 --- a/staging/src/k8s.io/code-generator/kube_codegen.sh +++ b/staging/src/k8s.io/code-generator/kube_codegen.sh @@ -443,6 +443,7 @@ function kube::codegen::gen_client() { local applyconfig="false" local applyconfig_subdir="applyconfiguration" local applyconfig_external="" + local applyconfig_openapi_schema="" local watchable="false" local listers_subdir="listers" local informers_subdir="informers" @@ -488,6 +489,10 @@ function kube::codegen::gen_client() { applyconfig_external="$2" shift 2 ;; + "--applyconfig-openapi-schema") + applyconfig_openapi_schema="$2" + shift 2 + ;; "--with-watch") watchable="true" shift @@ -594,6 +599,7 @@ function kube::codegen::gen_client() { --output-dir "${out_dir}/${applyconfig_subdir}" \ --output-pkg "${applyconfig_pkg}" \ --external-applyconfigurations "${applyconfig_external}" \ + --openapi-schema "${applyconfig_openapi_schema}" \ "${input_pkgs[@]}" fi From 4d1dd9cd07912190cffc68c54c17395391c8b4d1 Mon Sep 17 00:00:00 2001 From: Maciej Szulik Date: Fri, 5 Apr 2024 13:17:08 +0200 Subject: [PATCH 2/2] Update applyconfig-gen for pacakges where group and dir differ in name It is possible that package paths might differ from the group name, see https://github.com/openshift/api/blob/master/operatorcontrolplane/v1alpha1/doc.go notice that pacakge name is `operatorcontrolplane` whereas the group is `controlplane.operator...`. This confuses the generator since it tries to extrapolate the name of the package based on the group name. Whereas the ImportTracker can properly recognize the import path. This leads to cyclical imports in packages where the group name is different from the actual import path. --- .../applyconfiguration-gen/generators/applyconfiguration.go | 6 +++--- .../cmd/applyconfiguration-gen/generators/targets.go | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/staging/src/k8s.io/code-generator/cmd/applyconfiguration-gen/generators/applyconfiguration.go b/staging/src/k8s.io/code-generator/cmd/applyconfiguration-gen/generators/applyconfiguration.go index eb885a5901b..ee4743aa279 100644 --- a/staging/src/k8s.io/code-generator/cmd/applyconfiguration-gen/generators/applyconfiguration.go +++ b/staging/src/k8s.io/code-generator/cmd/applyconfiguration-gen/generators/applyconfiguration.go @@ -35,6 +35,7 @@ type applyConfigurationGenerator struct { generator.GoGenerator // outPkgBase is the base package, under which the "internal" and GV-specific subdirs live outPkgBase string // must be a Go import-path + localPkg string groupVersion clientgentypes.GroupVersion applyConfig applyConfig imports namer.ImportTracker @@ -49,9 +50,8 @@ func (g *applyConfigurationGenerator) Filter(_ *generator.Context, t *types.Type } func (g *applyConfigurationGenerator) Namers(*generator.Context) namer.NameSystems { - localPkg := path.Join(g.outPkgBase, g.groupVersion.Group.PackageName(), g.groupVersion.Version.PackageName()) return namer.NameSystems{ - "raw": namer.NewRawNamer(localPkg, g.imports), + "raw": namer.NewRawNamer(g.localPkg, g.imports), "singularKind": namer.NewPublicNamer(0), } } @@ -336,7 +336,7 @@ func (b *$.ApplyConfig.ApplyConfiguration|public$) ensure$.MemberType.Elem|publi var clientgenTypeConstructorNamespaced = ` // $.ApplyConfig.Type|public$ constructs an declarative configuration of the $.ApplyConfig.Type|public$ type for use with -// apply. +// apply. func $.ApplyConfig.Type|public$(name, namespace string) *$.ApplyConfig.ApplyConfiguration|public$ { b := &$.ApplyConfig.ApplyConfiguration|public${} b.WithName(name) diff --git a/staging/src/k8s.io/code-generator/cmd/applyconfiguration-gen/generators/targets.go b/staging/src/k8s.io/code-generator/cmd/applyconfiguration-gen/generators/targets.go index 7fc624d67bc..debab90e115 100644 --- a/staging/src/k8s.io/code-generator/cmd/applyconfiguration-gen/generators/targets.go +++ b/staging/src/k8s.io/code-generator/cmd/applyconfiguration-gen/generators/targets.go @@ -185,6 +185,7 @@ func targetForApplyConfigurationsPackage(outputDirBase, outputPkgBase, pkgSubdir OutputFilename: strings.ToLower(toGenerate.Type.Name.Name) + ".go", }, outPkgBase: outputPkgBase, + localPkg: outputPkg, groupVersion: gv, applyConfig: toGenerate, imports: generator.NewImportTracker(),