From 34af3cd57421ebb9e057e77fa947126c71b2a12f Mon Sep 17 00:00:00 2001 From: "Nelo-T. Wallus" Date: Mon, 16 Jun 2025 13:45:01 +0200 Subject: [PATCH 1/4] Check list/watch verbs on types Signed-off-by: Nelo-T. Wallus --- .../generators/generator_for_type.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cmd/cluster-client-gen/generators/generator_for_type.go b/cmd/cluster-client-gen/generators/generator_for_type.go index 2896b00e..dff988ff 100644 --- a/cmd/cluster-client-gen/generators/generator_for_type.go +++ b/cmd/cluster-client-gen/generators/generator_for_type.go @@ -144,8 +144,12 @@ func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w i sw.Do(nonNamespacedClusterInterfaceImpl, m) } - if !tags.NoVerbs { - sw.Do(clusterInterfaceVerbs, m) + if !tags.NoVerbs && tags.HasVerb("list") { + sw.Do(listClusterInterfaceImpl, m) + } + + if !tags.NoVerbs && tags.HasVerb("watch") { + sw.Do(watchClusterInterfaceImpl, m) } if !tags.NonNamespaced { @@ -228,12 +232,14 @@ func (c *$.type|privatePlural$ClusterInterface) Cluster(clusterPath logicalclust } ` -var clusterInterfaceVerbs = ` +var listClusterInterfaceImpl = ` // List returns the entire collection of all $.type|publicPlural$ across all clusters. func (c *$.type|privatePlural$ClusterInterface) List(ctx context.Context, opts $.ListOptions|raw$) (*$.resultType|raw$List, error) { return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).$.type|publicPlural$($if .namespaced$$.NamespaceAll|raw$$end$).List(ctx, opts) } +` +var watchClusterInterfaceImpl = ` // Watch begins to watch all $.type|publicPlural$ across all clusters. func (c *$.type|privatePlural$ClusterInterface) Watch(ctx context.Context, opts $.ListOptions|raw$) (watch.Interface, error) { return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).$.type|publicPlural$($if .namespaced$$.NamespaceAll|raw$$end$).Watch(ctx, opts) From 82f9e9b40f2bcd9d3188a42ea6af6f7e3dc7efc1 Mon Sep 17 00:00:00 2001 From: "Nelo-T. Wallus" Date: Tue, 17 Jun 2025 13:20:29 +0200 Subject: [PATCH 2/4] Add --exclude-group-versions Signed-off-by: Nelo-T. Wallus --- cluster_codegen.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/cluster_codegen.sh b/cluster_codegen.sh index ead34bba..bb9e2847 100755 --- a/cluster_codegen.sh +++ b/cluster_codegen.sh @@ -126,6 +126,10 @@ function cluster::codegen::internal::grep() { # --plural-exceptions # An optional list of comma separated plural exception definitions in Type:PluralizedType form. # +# --exclude-group-versions +# An optional list of comma separate group versions to exclude from +# client generation. +# function cluster::codegen::gen_client() { local in_dir="" local one_input_api="" @@ -144,6 +148,7 @@ function cluster::codegen::gen_client() { local single_cluster_listers_pkg="" local watchable="false" local plural_exceptions="" + local exclude_group_versions="" local v="${KUBE_VERBOSE:-0}" while [ "$#" -gt 0 ]; do @@ -212,6 +217,10 @@ function cluster::codegen::gen_client() { plural_exceptions="$2" shift 2 ;; + "--exclude-group-versions") + exclude_group_versions="$2" + shift 2 + ;; *) if [[ "$1" =~ ^-- ]]; then echo "unknown argument: $1" >&2 @@ -265,7 +274,13 @@ function cluster::codegen::gen_client() { dir2="$(dirname "${dir}")" leaf2="$(basename "${dir2}")" - group_versions+=("${leaf2}/${leaf}") + gv="${leaf2}/${leaf}" + + if [[ " ${exclude_group_versions} " == *" ${gv} "* ]]; then + continue + fi + + group_versions+=("${gv}") fi done < <( ( cluster::codegen::internal::grep -l --null \ From 33f747c69d92b12c7c28af61c4d5aa636951e090 Mon Sep 17 00:00:00 2001 From: "Nelo-T. Wallus" Date: Tue, 17 Jun 2025 13:21:33 +0200 Subject: [PATCH 3/4] Set package name based off of clientsetPkg Signed-off-by: Nelo-T. Wallus --- cmd/cluster-client-gen/generators/client_generator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/cluster-client-gen/generators/client_generator.go b/cmd/cluster-client-gen/generators/client_generator.go index fd909b64..b39b3842 100644 --- a/cmd/cluster-client-gen/generators/client_generator.go +++ b/cmd/cluster-client-gen/generators/client_generator.go @@ -203,7 +203,7 @@ func targetForGroup(gv clientgentypes.GroupVersion, typeList []*types.Type, clie func targetForClientset(args *args.Args, clientsetDir, clientsetPkg string, groupGoNames map[clientgentypes.GroupVersion]string, boilerplate []byte) generator.Target { return &generator.SimpleTarget{ - PkgName: "clientset", + PkgName: path.Base(clientsetPkg), PkgPath: clientsetPkg, PkgDir: clientsetDir, HeaderComment: boilerplate, From 88add97b1718d28c550bf762580104906655872b Mon Sep 17 00:00:00 2001 From: "Nelo-T. Wallus" Date: Tue, 17 Jun 2025 13:43:45 +0200 Subject: [PATCH 4/4] codegen Signed-off-by: Nelo-T. Wallus --- examples/pkg/kcp/clients/clientset/versioned/clientset.go | 2 +- .../pkg/kcpexisting/clients/clientset/versioned/clientset.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/pkg/kcp/clients/clientset/versioned/clientset.go b/examples/pkg/kcp/clients/clientset/versioned/clientset.go index 5330b2f5..f2bb5c71 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/clientset.go +++ b/examples/pkg/kcp/clients/clientset/versioned/clientset.go @@ -16,7 +16,7 @@ limitations under the License. // Code generated by cluster-client-gen. DO NOT EDIT. -package clientset +package versioned import ( fmt "fmt" diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/clientset.go b/examples/pkg/kcpexisting/clients/clientset/versioned/clientset.go index 3f9b2cc2..0ff22d75 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/clientset.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/clientset.go @@ -16,7 +16,7 @@ limitations under the License. // Code generated by cluster-client-gen. DO NOT EDIT. -package clientset +package versioned import ( fmt "fmt"