Skip to content

Commit 9654d7d

Browse files
authored
Update kubebuilder_annotation.md
1 parent 535677e commit 9654d7d

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

docs/kubebuilder_annotation.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# Kubebuilder Annotation
22

3-
If you have been using Kubebuilder, you must have seen comments such as `// +kubebuilder:rbac: ....` , `// +kubebuilder:resource:...` in scaffolder Go files. These special comments are used by kubebuilder tools (controller-tools) to generate CRD, RBAC, webhook manifests. In kubebuilder, these special comments are `Kubebuilder Annotation`, a.k.a `annotation`. It is designed for this kind of use case: To use kubebuilder tools, all you have to do is focus on writing your code, and put instructions with parameters as annotations along with your code, so that everything will be handled based on these annotations instructions by kubebuilder. This document illustrates the syntax of these annotations.
3+
If you have been using Kubebuilder, you must have seen comments such as `// +kubebuilder:rbac: ....` , `// +kubebuilder:resource:...` in the scaffolder Go files. These special comments are used by kubebuilder tools (controller tools) to generate CRD, RBAC, and webhook manifests. In kubebuilder, these special comments are `Kubebuilder Annotation`, a.k.a `annotation`. It is designed for this kind of use case: To use kubebuilder tools, all you have to do is focus on writing your code, and put instructions with parameters as annotations along with your code, so that everything will be handled based on these annotations instructions by kubebuilder. This document illustrates the syntax of these annotations.
44

55
## Kubebuilder Annotation Syntax
66

7-
Kubebuilder Annotation has a series of tokens separated by colons into groups from left to right. Each **Token** is a string identifier in an annotation instance. It has meaning by its position in token slice, in the form of
7+
Kubebuilder Annotation has a series of tokens separated by colons into groups from left to right. Each **Token** is a string identifier in an annotation instance. It has meaning by its position in a token slice, in the form of
88
**+[header]:[module]:[submodule]:[key-value elements]**
99
Go Annotation starts with `+` (e.g. `// +kubebuilder`) to differentiate from regular go comments.
1010

1111
## Token types
1212

13-
- **header** is the identifier of a group of annotations. It helps user know which project provides this annotation. For example, in Kubernetes project, headers like `kubebuilder`, `k8s`, `genclient`, etc. are all project identifiers. A header is required for all annotations, since you may use multiple annotations from different projects in the same codebase.
13+
- **header** is the identifier of a group of annotations. It helps the user know which project provides this annotation. For example, in the Kubernetes project, headers like `kubebuilder`, `k8s`, `genclient`, etc. are all project identifiers. A header is required for all annotations, since you may use multiple annotations from different projects in the same codebase.
1414

15-
- **module** is the identifier of functional module in an annotation. An annotation may have a group of modules, each of which performs a particular function.
15+
- **module** is the identifier of a functional module in an annotation. An annotation may have a group of modules, each of which performs a particular function.
1616

17-
- **submodule** (optional) In some cases, the module has a big functional scope, split into fine-grained sub modules, which provide the flexibility of extending module functionality. For example: **module:submodule1:submodule2:submodule3** submodule can be multiple following one by one.
17+
- **submodule** (optional) In some cases, the module has a big functional scope, split into fine-grained sub-modules, which provide the flexibility of extending module functionality. For example: **module:submodule1:submodule2:submodule3** submodule can be multiple following one by one.
1818

1919
## Levels of symbols
2020

@@ -26,7 +26,7 @@ Delimiter symbols are distinguished to work in different levels from top-down fo
2626

2727
- **Comma**
2828

29-
Comma `,` is the 2nd level delimiter (to annotation) for splitting key-value pairs in **key-value elements** which is normally the last token in annotation. e.g. `+kubebuilder:printcolumn:name=<name>,type=<type>,description=<desc>,JSONPath:<.spec.Name>,priority=<int32>,format=<format>` It works within token which is the 2nd level of annotation, so it is called "2nd level delimiter"
29+
Comma `,` is the 2nd level delimiter (to annotation) for splitting key-value pairs in **key-value elements** which is normally the last token in the annotation. e.g. `+kubebuilder:printcolumn:name=<name>,type=<type>,description=<desc>,JSONPath:<.spec.Name>,priority=<int32>,format=<format>` It works within token which is the 2nd level of annotation, so it is called "2nd level delimiter"
3030

3131
- **Equal sign**
3232

@@ -57,17 +57,17 @@ Delimiter symbols are distinguished to work in different levels from top-down fo
5757
**Notes:**
5858

5959
1. Separate two `submodule` (categories) under `webhook`: 1) `admission`and 2) `serveroption`, handling webhookTags and serverTags separately.
60-
2. For each submodule, all key-values should put in the same comment line.
61-
3. using `|` for splitting key-value of `lables`
60+
2. For each submodule, all key values should put in the same comment line.
61+
3. using `|` for splitting key value of `lables`
6262

6363
#### RBAC Annotation examples
6464

6565
**[header]** is `kubebuilder`
6666
**[module]** is `rbac`
67-
No submodule at this moment, support annotations like : `// +rbac`, `// +kubebuilder:rbac`
67+
No submodule at this moment, support annotations like: `// +rbac`, `// +kubebuilder:rbac`
6868

6969
```golang
7070
// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;delete
7171

7272
// +rbac:groups=apps,resources=deployments,verbs=get;list;watch;delete
73-
```
73+
```

0 commit comments

Comments
 (0)