|
| 1 | +{% panel style="info", title="Under Development" %} |
| 2 | +This book is being actively developed. |
| 3 | +{% endpanel %} |
| 4 | + |
| 5 | +# Generating API Documentation |
| 6 | + |
| 7 | +Kubebuilder will generate API reference documentation for your APIs with `kubebuilder docs`. The |
| 8 | +reference documentation will be built under `docs/reference/build/index.html` and can be opened |
| 9 | +directly in a web browser. |
| 10 | + |
| 11 | +- Use `--docs-copyright` to set the copyright footer |
| 12 | +- Use `--title` to set the title |
| 13 | + |
| 14 | +{% panel style="info", title="Non-Kubebuilder Projects" %} |
| 15 | +Kubebuilder can also be used to generate API reference documentation for non-kubebuilder projects, as long as the |
| 16 | +resources are annotated with `// +kubebuilder:resource` the same as they are in kubebuilder projects. |
| 17 | +{% endpanel %} |
| 18 | + |
| 19 | +## Creating Examples |
| 20 | + |
| 21 | +Users can provide resource examples by running |
| 22 | +`kubebuilder create example --kind <kind> --group <group> --version <version> `. This will create an example |
| 23 | +file under `docs/reference/kind/kind.yaml` for the user to edit. The contents of this file will appear |
| 24 | +next to the API reference documentation after rerunning `kubebuilder docs`. |
| 25 | + |
| 26 | +- `note:` description that will appear directly above the example |
| 27 | +- `sample:` example yaml that will be displayed |
| 28 | + |
| 29 | +## Editing Overview and API Group Documentation |
| 30 | + |
| 31 | +Users can modify documentation of the overview and API *groups* by editing the files under |
| 32 | +`docs/reference/static_includes`. |
| 33 | + |
| 34 | +- Edit `_overview.md` to provide documentation for the full set of APIs. |
| 35 | +- Edit `_<group>.md` to provide documentation for a specific API group. |
| 36 | + |
| 37 | +## Customizing the API documentation |
| 38 | + |
| 39 | +The generated documentation is controller by the `docs/reference/config.yaml` file generated by kubebuilder. This |
| 40 | +file may be manually changed by users to customize the appearance of the documentation. |
| 41 | + |
| 42 | +{% panel style="warning", title="Modifying config.yaml" %} |
| 43 | +When manually modifying config.yaml, users must run `kubebuilder docs` with `--generate-config=false` to |
| 44 | +prevent the file from being rewritten. |
| 45 | +{% endpanel %} |
| 46 | + |
| 47 | +#### Table of Contents |
| 48 | + |
| 49 | +{% method %} |
| 50 | + |
| 51 | +`docs/reference/config.yaml` is automatically generated to create a section for each API group including |
| 52 | +the APIs in the group, and to show the most mature versions of each API. Both the API sections and |
| 53 | +displayed API versions may be manually controlled. |
| 54 | + |
| 55 | +{% sample lang="yaml" %} |
| 56 | +> generated config.yaml for `kubebuilder create resource --kind Bee --group insect --version v1beta1` |
| 57 | +
|
| 58 | +```yaml |
| 59 | +example_location: "examples" |
| 60 | +api_groups: |
| 61 | + - "Insect" |
| 62 | +resource_categories: |
| 63 | +- name: "Insect" |
| 64 | + include: "insect" |
| 65 | + resources: |
| 66 | + - name: "Bee" |
| 67 | + version: "v1beta1" |
| 68 | + group: "insect" |
| 69 | +``` |
| 70 | +{% endmethod %} |
| 71 | +
|
| 72 | +#### Adding Notes and Warnings to APIs |
| 73 | +
|
| 74 | +{% method %} |
| 75 | +
|
| 76 | +- Add a note to include more information about a particular resource by providing html in a `description_note:`. |
| 77 | +- Add a warning about a particular resource by providing html in a `description_warning:`. |
| 78 | +- Inline field definitions beneath the Resource (the same way they are done for Spec and Status) by adding a |
| 79 | + `inline_definitions:` section. |
| 80 | + - `name:` the display name of the Section |
| 81 | + - `match:` the naming pattern of fields to inline, where `${resource}` is the name of the resource. |
| 82 | + |
| 83 | +{% sample lang="yaml" %} |
| 84 | +> modified config.yaml for `kubebuilder create resource --kind Bee --group insect --version v1beta1` |
| 85 | + |
| 86 | +```yaml |
| 87 | +example_location: "examples" |
| 88 | +api_groups: |
| 89 | + - "Insect" |
| 90 | +inline_definitions: |
| 91 | + - name: Something |
| 92 | + match: ${resource}Something |
| 93 | +resource_categories: |
| 94 | +- name: "Insect" |
| 95 | + include: "insect" |
| 96 | + resources: |
| 97 | + - name: "Bee" |
| 98 | + version: "v1beta1" |
| 99 | + group: "insect" |
| 100 | + description_note: "More information <a href=\"link to info\">here</a>" |
| 101 | + description_warning: "Warning about this. <a href=\"link to info\">More information.</a>" |
| 102 | +``` |
| 103 | +{% endmethod %} |
| 104 | + |
| 105 | + |
| 106 | + |
0 commit comments