Skip to content

Commit 3d06cfe

Browse files
clientset: configure output directory nicer
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
1 parent ee6387b commit 3d06cfe

4 files changed

Lines changed: 16 additions & 6 deletions

File tree

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.

hack/update-codegen.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ ${KUBE_INFORMER_GEN} \
7070

7171
# Generate cluster-aware clients, informers and listers using generated single-cluster code
7272
./../bin/code-generator \
73-
"client:name=versioned,outputPackagePath=acme.corp/pkg/kcpexisting/clients,apiPackagePath=acme.corp/pkg/apis,singleClusterClientPackagePath=acme.corp/pkg/generated/clientset/versioned,singleClusterApplyConfigurationsPackagePath=acme.corp/pkg/generated/applyconfigurations,headerFile=./../hack/boilerplate/boilerplate.go.txt" \
73+
"client:name=clientset,outputPackagePath=acme.corp/pkg/kcpexisting/clients,apiPackagePath=acme.corp/pkg/apis,singleClusterClientPackagePath=acme.corp/pkg/generated/clientset/versioned,singleClusterApplyConfigurationsPackagePath=acme.corp/pkg/generated/applyconfigurations,headerFile=./../hack/boilerplate/boilerplate.go.txt" \
7474
"lister:apiPackagePath=acme.corp/pkg/apis,singleClusterListerPackagePath=acme.corp/pkg/generated/listers,headerFile=./../hack/boilerplate/boilerplate.go.txt" \
7575
"informer:outputPackagePath=acme.corp/pkg/kcpexisting/clients,apiPackagePath=acme.corp/pkg/apis,singleClusterListerPackagePath=acme.corp/pkg/generated/listers,singleClusterInformerPackagePath=acme.corp/pkg/generated/informers/externalversions,headerFile=./../hack/boilerplate/boilerplate.go.txt" \
7676
"paths=./pkg/apis/..." \
7777
"output:dir=./pkg/kcpexisting/clients"
7878

7979
# Generate cluster-aware clients, informers and listers assuming no single-cluster listers or informers
8080
./../bin/code-generator \
81-
"client:name=versioned,outputPackagePath=acme.corp/pkg/kcp/clients,apiPackagePath=acme.corp/pkg/apis,singleClusterClientPackagePath=acme.corp/pkg/generated/clientset/versioned,singleClusterApplyConfigurationsPackagePath=acme.corp/pkg/generated/applyconfigurations,headerFile=./../hack/boilerplate/boilerplate.go.txt" \
81+
"client:name=clientset,outputPackagePath=acme.corp/pkg/kcp/clients,apiPackagePath=acme.corp/pkg/apis,singleClusterClientPackagePath=acme.corp/pkg/generated/clientset/versioned,singleClusterApplyConfigurationsPackagePath=acme.corp/pkg/generated/applyconfigurations,headerFile=./../hack/boilerplate/boilerplate.go.txt" \
8282
"lister:apiPackagePath=acme.corp/pkg/apis,headerFile=./../hack/boilerplate/boilerplate.go.txt" \
8383
"informer:outputPackagePath=acme.corp/pkg/kcp/clients,apiPackagePath=acme.corp/pkg/apis,headerFile=./../hack/boilerplate/boilerplate.go.txt" \
8484
"paths=./pkg/apis/..." \

pkg/generators/clientgen/clientgen.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ import (
3434

3535
type Generator struct {
3636
// Name is the name of this client-set, e.g. "kubernetes"
37-
Name string `marker:""`
37+
Name string `marker:",optional"`
38+
39+
// ExternalOnly toggles the creation of a "versioned" sub-directory.
40+
ExternalOnly bool `marker:",optional"`
3841

3942
// HeaderFile specifies the header text (e.g. license) to prepend to generated files.
4043
HeaderFile string `marker:",optional"`
@@ -88,14 +91,21 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error {
8891
}
8992
headerText = strings.ReplaceAll(headerText, " YEAR", replacement)
9093

94+
if g.Name == "" {
95+
g.Name = "clientset"
96+
}
97+
9198
groupVersionKinds, err := parser.CollectKinds(ctx)
9299
if err != nil {
93100
return err
94101
}
95102

96103
groupInfo := toGroupVersionInfos(groupVersionKinds)
97104

98-
clientsetDir := filepath.Join("clientset", "versioned")
105+
clientsetDir := g.Name
106+
if !g.ExternalOnly {
107+
clientsetDir = filepath.Join(clientsetDir, "versioned")
108+
}
99109
clientsetFile := filepath.Join(clientsetDir, "clientset.go")
100110
logger := klog.Background().WithValues("clientset", g.Name)
101111
logger.WithValues("path", clientsetFile).Info("generating clientset")

0 commit comments

Comments
 (0)