|
1 | | -## Code Generators for KCP-aware informers and listers |
| 1 | +## Code Generators for KCP-aware clients, informers and listers |
2 | 2 |
|
3 | | -### Usage: |
| 3 | +This repository contains code generation tools analogous to the Kubernetes |
| 4 | +code-generator. It contains: |
4 | 5 |
|
5 | | -``` |
6 | | -code-generator <command> [input-flags] |
7 | | -``` |
8 | | - |
9 | | -where `<command>` can be one of: |
10 | | -- lister |
11 | | -- informer |
| 6 | +* `cluster-client-gen` to generate a cluster-aware clientset, |
| 7 | +* `cluster-informer-gen` to generate cluster-aware informers and |
| 8 | +* `cluster-lister-gen` to do the same for listers. |
12 | 9 |
|
13 | | -It is possible to run the code generation for multiple components at once `code-generator lister,informer [input-flags]` |
| 10 | +Note that you need to have generated the versioned Kubernetes clientset and |
| 11 | +applyconfiguration packages already in order to generate and use cluster-aware |
| 12 | +code. Single-cluster listers and informers however are optional and the |
| 13 | +generator here can generate the necessary interfaces itself. |
14 | 14 |
|
15 | | -#### Input flags: |
| 15 | +### Usage |
16 | 16 |
|
17 | | -1. `--input-dir` - The directory path where APIs are defined. Make sure that the types are defined in `<inputDir>/pkg/apis/{$GROUP}/{$VERSION}`. For example, if your input apis are defined in `types.go` inside `examples/pkg/apis/apps/v1/types.go`, the input directory should be specified as `examples/pkg`. `{$GROUP}/{$VERSION}` is appended in the input path. |
18 | | -**Note**: This is the relative path to the input directory where APIs live. |
| 17 | +It is strongly recommended to use the provided `cluster_codegen.sh`, which works |
| 18 | +very much like Kubernetes' `kube_codegen.sh`. A common way to acquire it is to |
| 19 | +have a synthetic Go dependency on `github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen` |
| 20 | +(often done in a `hack/tools.go`) and then call it like so in your project: |
19 | 21 |
|
20 | | -2. `--output-dir` - The directory where output clients are to be generated. It defaults to the `output` folder under current working directory. |
21 | | - - Listers are output to `<outputDir>/listers/${GROUP}/${VERSION}/${TYPE}.go` |
22 | | - - Individual informers are output to `<outputDir>/informers/externalversions/${GROUP}/${VERSION}/${TYPE}.go` |
| 22 | +```bash |
| 23 | +# Often you would want to generate both the regular Kubernetes clientset and |
| 24 | +# the cluster-aware clienset. |
23 | 25 |
|
24 | | -3. `--clientset-api-path` - The path to where `clientset` generated by `k8s.io/code-gen` is present. |
| 26 | +CODEGEN_PKG="$(go list -f '{{.Dir}}' -m k8s.io/code-generator)" |
| 27 | +CLUSTER_CODEGEN_PKG="$(go list -f '{{.Dir}}' -m github.com/kcp-dev/code-generator/v3)" |
25 | 28 |
|
26 | | -4. `--group-versions` - List of group versions in the format `group:version`. Define multiple groups by specifying the flag again. For example, the inputs can be: |
27 | | - - `--group-version="apps:v1"` |
28 | | - - `--group-versions="rbac:v1" --group-versions="apps:v1"` |
29 | | - - `--group-version="rbac:v1,v2"` |
| 29 | +source "$CODEGEN_PKG/kube_codegen.sh" |
| 30 | +source "$CLUSTER_CODEGEN_PKG/cluster_codegen.sh" |
30 | 31 |
|
31 | | -5. `--go-header-file` - Path to the header file. |
| 32 | +# Now you can call kube::codegen:: and cluster::codegen:: functions. |
32 | 33 |
|
33 | | -Example: |
34 | | -To run it locally and see how it works, use the following command: |
| 34 | +kube::codegen::gen_client \ |
| 35 | + --boilerplate hack/boilerplate/examples/boilerplate.generatego.txt \ |
| 36 | + --output-dir pkg/generated \ |
| 37 | + --output-pkg acme.corp/pkg/generated \ |
| 38 | + --with-applyconfig \ |
| 39 | + --applyconfig-name applyconfigurations \ |
| 40 | + --with-watch \ |
| 41 | + ./pkg/apis |
35 | 42 |
|
| 43 | +cluster::codegen::gen_client \ |
| 44 | + --boilerplate hack/boilerplate/examples/boilerplate.generatego.txt \ |
| 45 | + --output-dir pkg/clients \ |
| 46 | + --output-pkg acme.corp/pkg/clients \ |
| 47 | + --with-watch \ |
| 48 | + --single-cluster-versioned-clientset-pkg acme.corp/pkg/generated/clientset/versioned \ |
| 49 | + --single-cluster-applyconfigurations-pkg acme.corp/pkg/generated/applyconfigurations \ |
| 50 | + --single-cluster-listers-pkg acme.corp/pkg/generated/listers \ |
| 51 | + --single-cluster-informers-pkg acme.corp/pkg/generated/informers/externalversions \ |
| 52 | + pkg/apis |
36 | 53 | ``` |
37 | | -go run main.go informer,lister --go-header-file testdata/header.txt |
38 | | - --clientset-api-path=github.com/kcp-dev/code-generator/testdata/pkg/generated/clientset/versioned |
39 | | - --input-dir testdata/pkg/apis |
40 | | - --output-dir testdata/pkg --group-versions example:v1 |
41 | | -``` |
42 | 54 |
|
43 | | -creates output folders in `testdata/pkg/informers` and `testdata/pkg/listers`. |
| 55 | +Please refer to the [cluster_codegen.sh](./cluster_codegen.sh) for more information |
| 56 | +on the available command line flags. |
| 57 | + |
| 58 | +## Contributing |
| 59 | + |
| 60 | +We ❤️ our contributors! If you're interested in helping us out, please check out [contributing to kcp](https://docs.kcp.io/kcp/main/contributing/). |
| 61 | + |
| 62 | +This community has a [Code of Conduct](./code-of-conduct.md). Please make sure to follow it. |
| 63 | + |
| 64 | +## Getting in touch |
| 65 | + |
| 66 | +There are several ways to communicate with us: |
| 67 | + |
| 68 | +- The [`#kcp-dev` channel](https://app.slack.com/client/T09NY5SBT/C021U8WSAFK) in the [Kubernetes Slack workspace](https://slack.k8s.io). |
| 69 | +- Our mailing lists: |
| 70 | + - [kcp-dev](https://groups.google.com/g/kcp-dev) for development discussions. |
| 71 | + - [kcp-users](https://groups.google.com/g/kcp-users) for discussions among users and potential users. |
| 72 | +- By joining the kcp-dev mailing list, you should receive an invite to our bi-weekly community meetings. |
| 73 | +- See recordings of past community meetings on [YouTube](https://www.youtube.com/channel/UCfP_yS5uYix0ppSbm2ltS5Q). |
| 74 | +- The next community meeting dates are available via our [CNCF community group](https://community.cncf.io/kcp/). |
| 75 | +- Check the [community meeting notes document](https://docs.google.com/document/d/1PrEhbmq1WfxFv1fTikDBZzXEIJkUWVHdqDFxaY1Ply4) for future and past meeting agendas. |
| 76 | +- Browse the [shared Google Drive](https://drive.google.com/drive/folders/1FN7AZ_Q1CQor6eK0gpuKwdGFNwYI517M?usp=sharing) to share design docs, notes, etc. |
| 77 | + - Members of the kcp-dev mailing list can view this drive. |
0 commit comments