Skip to content

Commit 126a1bc

Browse files
authored
Merge pull request #111 from ntnn/code-gen-fixes
✨ Add things for kcp-dev/client-go
2 parents e635c8b + 88add97 commit 126a1bc

File tree

5 files changed

+28
-7
lines changed

5 files changed

+28
-7
lines changed

cluster_codegen.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ function cluster::codegen::internal::grep() {
126126
# --plural-exceptions <string = "">
127127
# An optional list of comma separated plural exception definitions in Type:PluralizedType form.
128128
#
129+
# --exclude-group-versions <string = "">
130+
# An optional list of comma separate group versions to exclude from
131+
# client generation.
132+
#
129133
function cluster::codegen::gen_client() {
130134
local in_dir=""
131135
local one_input_api=""
@@ -144,6 +148,7 @@ function cluster::codegen::gen_client() {
144148
local single_cluster_listers_pkg=""
145149
local watchable="false"
146150
local plural_exceptions=""
151+
local exclude_group_versions=""
147152
local v="${KUBE_VERBOSE:-0}"
148153

149154
while [ "$#" -gt 0 ]; do
@@ -212,6 +217,10 @@ function cluster::codegen::gen_client() {
212217
plural_exceptions="$2"
213218
shift 2
214219
;;
220+
"--exclude-group-versions")
221+
exclude_group_versions="$2"
222+
shift 2
223+
;;
215224
*)
216225
if [[ "$1" =~ ^-- ]]; then
217226
echo "unknown argument: $1" >&2
@@ -265,7 +274,13 @@ function cluster::codegen::gen_client() {
265274

266275
dir2="$(dirname "${dir}")"
267276
leaf2="$(basename "${dir2}")"
268-
group_versions+=("${leaf2}/${leaf}")
277+
gv="${leaf2}/${leaf}"
278+
279+
if [[ " ${exclude_group_versions} " == *" ${gv} "* ]]; then
280+
continue
281+
fi
282+
283+
group_versions+=("${gv}")
269284
fi
270285
done < <(
271286
( cluster::codegen::internal::grep -l --null \

cmd/cluster-client-gen/generators/client_generator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func targetForGroup(gv clientgentypes.GroupVersion, typeList []*types.Type, clie
203203

204204
func targetForClientset(args *args.Args, clientsetDir, clientsetPkg string, groupGoNames map[clientgentypes.GroupVersion]string, boilerplate []byte) generator.Target {
205205
return &generator.SimpleTarget{
206-
PkgName: "clientset",
206+
PkgName: path.Base(clientsetPkg),
207207
PkgPath: clientsetPkg,
208208
PkgDir: clientsetDir,
209209
HeaderComment: boilerplate,

cmd/cluster-client-gen/generators/generator_for_type.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,12 @@ func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w i
144144
sw.Do(nonNamespacedClusterInterfaceImpl, m)
145145
}
146146

147-
if !tags.NoVerbs {
148-
sw.Do(clusterInterfaceVerbs, m)
147+
if !tags.NoVerbs && tags.HasVerb("list") {
148+
sw.Do(listClusterInterfaceImpl, m)
149+
}
150+
151+
if !tags.NoVerbs && tags.HasVerb("watch") {
152+
sw.Do(watchClusterInterfaceImpl, m)
149153
}
150154

151155
if !tags.NonNamespaced {
@@ -228,12 +232,14 @@ func (c *$.type|privatePlural$ClusterInterface) Cluster(clusterPath logicalclust
228232
}
229233
`
230234

231-
var clusterInterfaceVerbs = `
235+
var listClusterInterfaceImpl = `
232236
// List returns the entire collection of all $.type|publicPlural$ across all clusters.
233237
func (c *$.type|privatePlural$ClusterInterface) List(ctx context.Context, opts $.ListOptions|raw$) (*$.resultType|raw$List, error) {
234238
return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).$.type|publicPlural$($if .namespaced$$.NamespaceAll|raw$$end$).List(ctx, opts)
235239
}
240+
`
236241

242+
var watchClusterInterfaceImpl = `
237243
// Watch begins to watch all $.type|publicPlural$ across all clusters.
238244
func (c *$.type|privatePlural$ClusterInterface) Watch(ctx context.Context, opts $.ListOptions|raw$) (watch.Interface, error) {
239245
return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).$.type|publicPlural$($if .namespaced$$.NamespaceAll|raw$$end$).Watch(ctx, opts)

examples/pkg/kcp/clients/clientset/versioned/clientset.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/pkg/kcpexisting/clients/clientset/versioned/clientset.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)