code-generator

module
v3.29.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2025 License: Apache-2.0

README

[!WARNING] This is an automatically published staged repository for kcp.

Contributions, including issues and pull requests, should be made to the main kcp repository: https://github.com/kcp-dev/kcp.

This repository is read-only for importing, and not used for direct contributions.
See the monorepo structure document for more details.

Code Generators for KCP-aware clients, informers and listers

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 and
  • cluster-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.

Usage

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.

Contributing

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.

Getting in touch

There are several ways to communicate with us:

Directories

Path Synopsis
cmd
cluster-client-gen command
client-gen makes the individual typed clients using gengo.
client-gen makes the individual typed clients using gengo.
cluster-client-gen/generators
Package generators has the generators for the client-gen utility.
Package generators has the generators for the client-gen utility.
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL