Skip to content

Commit 3f24ddf

Browse files
committed
Add markers docs pages
This actually adds marker docs pages, and enables the markderdocs plugin.
1 parent e6efaa1 commit 3f24ddf

File tree

8 files changed

+131
-0
lines changed

8 files changed

+131
-0
lines changed

docs/book/book.toml

+3
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ curly-quotes = true
1010

1111
[preprocessor.literatego]
1212
command = "./litgo.sh"
13+
14+
[preprocessor.markerdocs]
15+
command = "./markerdocs.sh"

docs/book/src/SUMMARY.md

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@
4242
- [Kind cluster](reference/kind.md)
4343
- [What's a webhook?](reference/webhook-overview.md)
4444
- [Admission webhook](reference/admission-webhook.md)
45+
- [Markers for Config/Code Generation](./reference/markers.md)
46+
47+
- [CRD Generation](./reference/markers/crd.md)
48+
- [CRD Validation](./reference/markers/crd-validation.md)
49+
- [Webhook](./reference/markers/webhook.md)
50+
- [Object/DeepCopy](./reference/markers/object.md)
51+
- [RBAC](./reference/markers/rbac.md)
52+
4553
---
4654

4755
[Appendix: The TODO Landing Page](./TODO.md)

docs/book/src/reference/markers.md

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Markers for Config/Code Generation
2+
3+
KubeBuilder makes use of a tool called `controller-gen` (from
4+
[controller-tools](https://godoc.org/sigs.k8s.io/controller-tools)) for
5+
generating utility code and Kubernetes YAML. This code and config
6+
generation is controlled by the presenence of special "marker comments" in
7+
Go code.
8+
9+
Markers are single-line comments that start with a plus, followed by
10+
a marker name, optionally followed by some marker specific configuration:
11+
12+
```go
13+
// +kubebuilder:validation:Optional
14+
// +kubebuilder:validation:MaxItems=2
15+
// +kubebuilder:printcolumn:JSONPath=".status.replicas",name=Replicas,type=string
16+
```
17+
18+
See each subsection for information about different types of code and YAML
19+
generation.
20+
21+
## Generating Code & Artifacts in KubeBuilder
22+
23+
KubeBuilder projects have two `make` targets that make use of
24+
controller-gen:
25+
26+
- `make manifests` generates Kubernetes object YAML, like
27+
[CustomResourceDefinitions](./markers/crd.md),
28+
[WebhookConfigurations](./markers/webhook.md), and [RBAC
29+
roles](./markers/rbac.md).
30+
31+
- `make generate` generates code, like [runtime.Object/DeepCopy
32+
implementations](./markers/object.md).
33+
34+
See [Generating CRDs](./generating-crd.md) for a comprehensive overview.
35+
36+
## Marker Syntax
37+
38+
Exact syntax is described in the [godocs for
39+
controller-tools](https://godoc.org/sigs.k8s.io/controller-tools/pkg/markers).
40+
41+
In general, markers may either be:
42+
43+
- **Empty** (`+kubebuilder:validation:Optional`): empty markers are like boolean flags on the command line
44+
-- just specifying them enables some behavior.
45+
46+
- **Anonymous** (`+kubebuilder:validation:MaxItems=2`): anonymous markers take
47+
a single value as their argument.
48+
49+
- **Multi-option**
50+
(`+kubebuilder:printcolumn:JSONPath=".status.replicas",name=Replicas,type=string`): multi-option
51+
markers take one or more named arguments. The first argument is
52+
separated from the name by a colon, and latter arguments are
53+
comma-separated. Order of arguments doesn't matter. Some arguments may
54+
be optional.
55+
56+
Marker arguments may be strings, ints, bools, or slices thereof. Strings,
57+
ints, and bools follow their Go syntax:
58+
59+
```go
60+
// +kubebuilder:validation:ExclusiveMaximum=false
61+
// +kubebulder:validation:Format="date-time"
62+
// +kubebuilder:validation:Maxium=42
63+
```
64+
65+
For convinience, in simple cases the quotes may be omitted from strings,
66+
although this is not encouraged for anything other than single-word
67+
strings:
68+
69+
```go
70+
// +kubebuilder:validation:Type=string
71+
```
72+
73+
Slices may be specified either by surrounding them with curly braces and
74+
separating with commas:
75+
76+
```go
77+
// +kubebuilder:webhooks:Enum={"crackers, Gromit, we forgot the crackers!","not even wensleydale?"}
78+
```
79+
80+
or, in simple cases, by separating with semicolons:
81+
82+
```go
83+
// +kubebuilder:validation:Enum=Wallace;Gromit;Chicken
84+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# CRD Validation
2+
3+
These markers modify how the CRD validation schema is produced for the
4+
types and fields they modify. Each corresponds roughly to an OpenAPI/JSON
5+
schema option.
6+
7+
{{#markerdocs CRD validation}}
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# CRD Generation
2+
3+
These markers describe how to construct a custom resource definition from
4+
a series of Go types and packages. Generation of the actual validation
5+
schema is described by the [validation markers](./crd-validation.md).
6+
7+
{{#markerdocs CRD}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Object/DeepCopy
2+
3+
These markers control when `DeepCopy` and `runtime.Object` implemention
4+
methods are generated.
5+
6+
{{#markerdocs object}}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# RBAC
2+
3+
These markers cause an [RBAC
4+
ClusterRole](https://kubernetes.io/docs/reference/access-authn-authz/rbac/#role-and-clusterrole)
5+
to be generated. This allows you to describe the permissions that your
6+
controller requires alongside the code that makes use of those
7+
permissions.
8+
9+
{{#markerdocs RBAC}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Webhook
2+
3+
These markers describe how [webhook configuration](/TODO.md) is generated.
4+
Use these to keep the description of your webhooks close to the code that
5+
implements them.
6+
7+
{{#markerdocs Webhook}}

0 commit comments

Comments
 (0)