diff options
| author | Kubernetes Submit Queue <k8s-merge-robot@users.noreply.github.com> | 2017-11-09 06:31:45 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-11-09 06:31:45 -0800 |
| commit | e1b72cb444ab2a0eb8f936bc1a71ca20169c7522 (patch) | |
| tree | 07a0ecd4a1f75ec1d73069d5dc00d3ec0d419409 | |
| parent | 0d5be6151b90f8c797043683479e37e0c3b6e999 (diff) | |
| parent | 2918c4d153df0e666a97e1e1dfaa8085fec8222a (diff) | |
Merge pull request #1348 from sttts/sttts-group-go-name
Automatic merge from submit-queue.
contributors/devel: document '// +groupGoName' code-generation tag
Documentation counterpart PR for https://github.com/kubernetes/kubernetes/pull/54950.
| -rw-r--r-- | contributors/devel/api_changes.md | 10 | ||||
| -rw-r--r-- | contributors/devel/generating-clientset.md | 5 |
2 files changed, 12 insertions, 3 deletions
diff --git a/contributors/devel/api_changes.md b/contributors/devel/api_changes.md index d592feab..d4fcc322 100644 --- a/contributors/devel/api_changes.md +++ b/contributors/devel/api_changes.md @@ -524,7 +524,7 @@ run it several times to ensure there are no incompletely calculated fields. `client-gen` is a tool to generate clientsets for top-level API objects. -`client-gen` requires the `// +genclient=true` annotation on each +`client-gen` requires the `// +genclient` annotation on each exported type in both the internal `pkg/apis/<group>/types.go` as well as each specifically versioned `staging/src/k8s.io/api/<group>/<version>/types.go`. @@ -542,13 +542,17 @@ Once you added the annotations, generate the client with hack/update-codegen.sh ``` +Note that you can use the optional `// +groupGoName=` to specify a CamelCase +custom Golang identifier to de-conflict e.g. `policy.authorization.k8s.io` and +`policy.k8s.io`. These two would both map to `Policy()` in clientsets. + client-gen is flexible. See [this document](generating-clientset.md) if you need client-gen for non-kubernetes API. ### Generate Listers `lister-gen` is a tool to generate listers for a client. It reuses the -`//+genclient=true` and the `// +groupName=` annotations, so you do not need to +`//+genclient` and the `// +groupName=` annotations, so you do not need to specify extra annotations. Your previous run of `hack/update-codegen.sh` has invoked `lister-gen`. @@ -556,7 +560,7 @@ Your previous run of `hack/update-codegen.sh` has invoked `lister-gen`. ### Generate Informers `informer-gen` generates the very useful Informers which watch API -resources for changes. It reuses the `//+genclient=true` and the +resources for changes. It reuses the `//+genclient` and the `//+groupName=` annotations, so you do not need to specify extra annotations. Your previous run of `hack/update-codegen.sh` has invoked `informer-gen`. diff --git a/contributors/devel/generating-clientset.md b/contributors/devel/generating-clientset.md index 853bd7a1..2ef0ddd5 100644 --- a/contributors/devel/generating-clientset.md +++ b/contributors/devel/generating-clientset.md @@ -20,6 +20,11 @@ In some cases you want to generate non-standard verbs (eg. for sub-resources). T - `// +genclient:method=Scale,verb=update,subresource=scale,input=k8s.io/api/extensions/v1beta1.Scale,result=k8s.io/api/extensions/v1beta1.Scale` - in this case a new function `Scale(string, *v1beta.Scale) *v1beta.Scale` will be added to the default client and the body of the function will be based on the *update* verb. The optional *subresource* argument will make the generated client function use subresource `scale`. Using the optional *input* and *result* arguments you can override the default type with a custom type. If the import path is not given, the generator will assume the type exists in the same package. +In addition, the following optional tags influence the client generation: + +- `// +groupName=policy.authorization.k8s.io` – used in the fake client as the full group name (defaults to the package name), +- `// +groupGoName=AuthorizationPolicy` – a CamelCase Golang identifier to de-conflict groups with non-unique prefixes like `policy.authorization.k8s.io` and `policy.k8s.io`. These would lead to two `Policy()` methods in the clientset otherwise (defaults to the upper-case first segement of the group name). + **2a.** If you are developing in the k8s.io/kubernetes repository, you just need to run hack/update-codegen.sh. **2b.** If you are running client-gen outside of k8s.io/kubernetes, you need to use the command line argument `--input` to specify the groups and versions of the APIs you want to generate clients for, client-gen will then look into `pkg/apis/${GROUP}/${VERSION}/types.go` and generate clients for the types you have marked with the `genclient` tags. For example, to generated a clientset named "my_release" including clients for api/v1 objects and extensions/v1beta1 objects, you need to run: |
