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.
This commit is contained in:
Kubernetes Submit Queue 2017-11-09 06:31:45 -08:00 committed by GitHub
commit e1b72cb444
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -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`.

View File

@ -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: