Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion cluster_codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ function cluster::codegen::internal::grep() {
# --plural-exceptions <string = "">
# An optional list of comma separated plural exception definitions in Type:PluralizedType form.
#
# --exclude-group-versions <string = "">
# 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=""
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion cmd/cluster-client-gen/generators/client_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Copy link
Member Author

Choose a reason for hiding this comment

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

Could also make this an input, e.g. clientsetPkgName but imho thats just another possible error source and path.Base should always return the correct value.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just make sure this works both in the code-generator's examples and for kcp itself. Both have widely different directory structures, so assumptions are difficult to make here 😁

Copy link
Member Author

Choose a reason for hiding this comment

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

I had only noticed this because the tests in kcp were complaining about the mismatch :D

PkgPath: clientsetPkg,
PkgDir: clientsetDir,
HeaderComment: boilerplate,
Expand Down
12 changes: 9 additions & 3 deletions cmd/cluster-client-gen/generators/generator_for_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion examples/pkg/kcp/clients/clientset/versioned/clientset.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.