Skip to content

Commit c2699c0

Browse files
committed
Add info about markers
1 parent cf1575e commit c2699c0

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

docs/book/src/reference/markers.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ a marker name, optionally followed by some marker specific configuration:
1515
// +kubebuilder:printcolumn:JSONPath=".status.replicas",name=Replicas,type=string
1616
```
1717

18+
<aside class="note">
19+
<h1>difference between `// +optional` and `// +kubebuilder:validation:Optional`</h1>
20+
controller-gen supports both (see the output of `controller-gen crd -www`). `+kubebuilder:validation:Optional` and `+optional` can be applied to fields.
21+
22+
But `+kubebuilder:validation:Optional` can also be applied at the package level such that it applies to every field in the package.
23+
24+
If you're using controller-gen only then they're redundant, but if you're using other generators or you want developers that need to build their own clients for your API, you'll want to also include `+optional`.
25+
26+
The most reliable way in 1.x to get `+optional` is `omitempty`.
27+
</aside>
28+
1829
See each subsection for information about different types of code and YAML
1930
generation.
2031

0 commit comments

Comments
 (0)