Skip to content

Commit e1b72cb

Browse files
author
Kubernetes Submit Queue
authored
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 kubernetes/kubernetes#54950.
2 parents 0d5be61 + 2918c4d commit e1b72cb

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

contributors/devel/api_changes.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ run it several times to ensure there are no incompletely calculated fields.
524524

525525
`client-gen` is a tool to generate clientsets for top-level API objects.
526526

527-
`client-gen` requires the `// +genclient=true` annotation on each
527+
`client-gen` requires the `// +genclient` annotation on each
528528
exported type in both the internal `pkg/apis/<group>/types.go` as well as each
529529
specifically versioned `staging/src/k8s.io/api/<group>/<version>/types.go`.
530530

@@ -542,21 +542,25 @@ Once you added the annotations, generate the client with
542542
hack/update-codegen.sh
543543
```
544544

545+
Note that you can use the optional `// +groupGoName=` to specify a CamelCase
546+
custom Golang identifier to de-conflict e.g. `policy.authorization.k8s.io` and
547+
`policy.k8s.io`. These two would both map to `Policy()` in clientsets.
548+
545549
client-gen is flexible. See [this document](generating-clientset.md) if you need
546550
client-gen for non-kubernetes API.
547551

548552
### Generate Listers
549553

550554
`lister-gen` is a tool to generate listers for a client. It reuses the
551-
`//+genclient=true` and the `// +groupName=` annotations, so you do not need to
555+
`//+genclient` and the `// +groupName=` annotations, so you do not need to
552556
specify extra annotations.
553557

554558
Your previous run of `hack/update-codegen.sh` has invoked `lister-gen`.
555559

556560
### Generate Informers
557561

558562
`informer-gen` generates the very useful Informers which watch API
559-
resources for changes. It reuses the `//+genclient=true` and the
563+
resources for changes. It reuses the `//+genclient` and the
560564
`//+groupName=` annotations, so you do not need to specify extra annotations.
561565

562566
Your previous run of `hack/update-codegen.sh` has invoked `informer-gen`.

contributors/devel/generating-clientset.md

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ In some cases you want to generate non-standard verbs (eg. for sub-resources). T
2020

2121
- `// +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.
2222

23+
In addition, the following optional tags influence the client generation:
24+
25+
- `// +groupName=policy.authorization.k8s.io` – used in the fake client as the full group name (defaults to the package name),
26+
- `// +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).
27+
2328
**2a.** If you are developing in the k8s.io/kubernetes repository, you just need to run hack/update-codegen.sh.
2429

2530
**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:

0 commit comments

Comments
 (0)