This repository contains code generation tools analogous to the Kubernetes code-generator. It contains:
cluster-client-gen
to generate a cluster-aware clientset,cluster-informer-gen
to generate cluster-aware informers andcluster-lister-gen
to do the same for listers.
Note that you need to have generated the versioned Kubernetes clientset and applyconfiguration packages already in order to generate and use cluster-aware code. Single-cluster listers and informers however are optional and the generator here can generate the necessary interfaces itself.
It is strongly recommended to use the provided cluster_codegen.sh
, which works
very much like Kubernetes' kube_codegen.sh
. A common way to acquire it is to
have a synthetic Go dependency on github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen
(often done in a hack/tools.go
) and then call it like so in your project:
# Often you would want to generate both the regular Kubernetes clientset and
# the cluster-aware clienset.
CODEGEN_PKG="$(go list -f '{{.Dir}}' -m k8s.io/code-generator)"
CLUSTER_CODEGEN_PKG="$(go list -f '{{.Dir}}' -m github.com/kcp-dev/code-generator/v3)"
source "$CODEGEN_PKG/kube_codegen.sh"
source "$CLUSTER_CODEGEN_PKG/cluster_codegen.sh"
# Now you can call kube::codegen:: and cluster::codegen:: functions.
kube::codegen::gen_client \
--boilerplate hack/boilerplate/examples/boilerplate.generatego.txt \
--output-dir pkg/generated \
--output-pkg acme.corp/pkg/generated \
--with-applyconfig \
--applyconfig-name applyconfigurations \
--with-watch \
./pkg/apis
cluster::codegen::gen_client \
--boilerplate hack/boilerplate/examples/boilerplate.generatego.txt \
--output-dir pkg/clients \
--output-pkg acme.corp/pkg/clients \
--with-watch \
--single-cluster-versioned-clientset-pkg acme.corp/pkg/generated/clientset/versioned \
--single-cluster-applyconfigurations-pkg acme.corp/pkg/generated/applyconfigurations \
--single-cluster-listers-pkg acme.corp/pkg/generated/listers \
--single-cluster-informers-pkg acme.corp/pkg/generated/informers/externalversions \
pkg/apis
Please refer to the cluster_codegen.sh for more information on the available command line flags.
We ❤️ our contributors! If you're interested in helping us out, please check out contributing to kcp.
This community has a Code of Conduct. Please make sure to follow it.
There are several ways to communicate with us:
- The
#kcp-dev
channel in the Kubernetes Slack workspace. - Our mailing lists:
- By joining the kcp-dev mailing list, you should receive an invite to our bi-weekly community meetings.
- See recordings of past community meetings on YouTube.
- The next community meeting dates are available via our CNCF community group.
- Check the community meeting notes document for future and past meeting agendas.
- Browse the shared Google Drive to share design docs, notes, etc.
- Members of the kcp-dev mailing list can view this drive.