Skip to content

Commit a81a1cc

Browse files
author
Phillip Wittrock
authored
Merge pull request #178 from pwittrock/docs-gen
Update GitBook doc generation page
2 parents fbeb436 + 9c1a6bf commit a81a1cc

File tree

1 file changed

+60
-44
lines changed

1 file changed

+60
-44
lines changed

docs/book/beyond_basics/generating_documentation.md

Lines changed: 60 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,34 @@ defining the resource. No blank lines may appear between the annotation and the
2222

2323
## Creating Examples
2424

25+
{% method %}
26+
2527
Users can provide resource examples by running
2628
`kubebuilder create example --kind <kind> --group <group> --version <version> `. This will create an example
27-
file under `docs/reference/kind/kind.yaml` for the user to edit. The contents of this file will appear
29+
file under `docs/reference/examples/<kind>/<kind>.yaml` for the user to edit. The contents of this file will appear
2830
next to the API reference documentation after rerunning `kubebuilder docs`.
2931

3032
- `note:` description that will appear directly above the example
3133
- `sample:` example yaml that will be displayed
3234

35+
{% sample lang="code" %}
36+
37+
> $ kubebuilder create example --kind Frigate --version v1beta1 --group ships
38+
39+
```yaml
40+
# docs/reference/examples/frigate/frigate.yaml
41+
note: frigate example
42+
sample: |
43+
apiVersion: v1beta1
44+
kind: frigate
45+
metadata:
46+
name: frigate
47+
spec:
48+
todo: "write me"
49+
```
50+
{% endmethod %}
51+
52+
3353
## Editing Overview and API Group Documentation
3454
3555
Users can modify documentation of the overview and API *groups* by editing the files under
@@ -38,10 +58,39 @@ Users can modify documentation of the overview and API *groups* by editing the f
3858
- Edit `_overview.md` to provide documentation for the full set of APIs.
3959
- Edit `_<group>.md` to provide documentation for a specific API group.
4060

61+
## Adding Notes and Warnings for APIs
62+
63+
{% method %}
64+
65+
It is possible to add *notes* and *warnings* to APIs in the reference documentation by annotating
66+
the go struct with `// +kubebuilder:doc:note=` or `// +kubebuilder:doc:warning=`. These will
67+
show up in *blue* and *orange* boxes.
68+
69+
{% sample lang="code" %}
70+
```go
71+
// Frigate API documentation goes here.
72+
// +kubebuilder:doc:note=this is a note
73+
// +kubebuilder:doc:warning=this is a warning
74+
// +k8s:openapi-gen=true
75+
// +kubebuilder:resource:path=frigates
76+
type Frigate struct {
77+
metav1.TypeMeta `json:",inline"`
78+
metav1.ObjectMeta `json:"metadata,omitempty"`
79+
80+
// Spec field documentation goes here.
81+
Spec FrigateSpec `json:"spec,omitempty"`
82+
83+
// Status field documentation goes here.
84+
Status FrigateStatus `json:"status,omitempty"`
85+
}
86+
```
87+
{% endmethod %}
88+
4189
## Customizing the API documentation
4290

4391
The generated documentation is controller by the `docs/reference/config.yaml` file generated by kubebuilder. This
44-
file may be manually changed by users to customize the appearance of the documentation.
92+
file may be manually changed by users to customize the appearance of the documentation, however this is
93+
discouraged as the user will need to manually managed the config going forward.
4594

4695
{% panel style="warning", title="Modifying config.yaml" %}
4796
When manually modifying config.yaml, users must run `kubebuilder docs` with `--generate-config=false` to
@@ -54,57 +103,24 @@ prevent the file from being rewritten.
54103

55104
`docs/reference/config.yaml` is automatically generated to create a section for each API group including
56105
the APIs in the group, and to show the most mature versions of each API. Both the API sections and
57-
displayed API versions may be manually controlled.
106+
displayed API versions may be manually controlled if needed.
58107

59-
{% sample lang="yaml" %}
108+
{% sample lang="code" %}
60109
> generated config.yaml for `kubebuilder create resource --kind Bee --group insect --version v1beta1`
61110
62111
```yaml
63112
example_location: "examples"
64113
api_groups:
65-
- "Insect"
114+
- "Ship"
66115
resource_categories:
67-
- name: "Insect"
68-
include: "insect"
116+
- name: "Ship"
117+
include: "ship"
69118
resources:
70-
- name: "Bee"
119+
- name: "Frigate"
71120
version: "v1beta1"
72-
group: "insect"
121+
group: "ship"
122+
description_warning: "test warnings message annotations"
123+
description_note: "test notes message annotations"
73124
```
74125
{% endmethod %}
75126
76-
#### Adding Notes and Warnings to APIs
77-
78-
{% method %}
79-
80-
- Add a note to include more information about a particular resource by providing html in a `description_note:`.
81-
- Add a warning about a particular resource by providing html in a `description_warning:`.
82-
- Inline field definitions beneath the Resource (the same way they are done for Spec and Status) by adding a
83-
`inline_definitions:` section.
84-
- `name:` the display name of the Section
85-
- `match:` the naming pattern of fields to inline, where `${resource}` is the name of the resource.
86-
87-
{% sample lang="yaml" %}
88-
> modified config.yaml for `kubebuilder create resource --kind Bee --group insect --version v1beta1`
89-
90-
```yaml
91-
example_location: "examples"
92-
api_groups:
93-
- "Insect"
94-
inline_definitions:
95-
- name: Something
96-
match: ${resource}Something
97-
resource_categories:
98-
- name: "Insect"
99-
include: "insect"
100-
resources:
101-
- name: "Bee"
102-
version: "v1beta1"
103-
group: "insect"
104-
description_note: "More information <a href=\"link to info\">here</a>"
105-
description_warning: "Warning about this. <a href=\"link to info\">More information.</a>"
106-
```
107-
{% endmethod %}
108-
109-
110-

0 commit comments

Comments
 (0)