|
1 | | -# The Table Generator: Generate Documentation Tables Automatically from CRDs |
| 1 | +# Table Generator: Autogenerate CRD Documentation Tables |
2 | 2 |
|
3 | 3 | ## Overview |
4 | 4 |
|
5 | 5 | This package contains a tool that automatically generates a documentation table documenting a CRD, and writes it to specified `.md` files. |
6 | 6 |
|
7 | | -## Parameters |
| 7 | +## Generate Tables |
8 | 8 |
|
9 | | -You must specify the following parameters: |
| 9 | +You can run the table generator in two ways: |
10 | 10 |
|
11 | | -- `crd-filename` - full or relative path to the `.yaml` file containing the CRD |
12 | | -- `md-filename` - full or relative path to the `.md` file in which to insert the table rows |
| 11 | +- [Use Makefile (Recommended)](#use-makefile-recommended): Configure your CRD once and generate tables with simple `make` commands. |
| 12 | +- [Run from command line](#use-command-line): Execute directly with `go run` for quick testing or ad-hoc documentation. |
13 | 13 |
|
14 | | -## Set Up the Table Generator |
| 14 | +### Use Makefile (Recommended) |
| 15 | +Follow the steps: |
15 | 16 |
|
16 | | -Open the `.md` file you want to generate table in, and in the place where you want to insert a table, enter the tags `TABLE-START` and `TABLE-END`. |
| 17 | +1. Prepare the parameters' descriptions in the CR's specification file. For example, for the Telemetry CR, prepare the description in [`operator.kyma-project.io_telemetries.yaml`](https://github.com/kyma-project/telemetry-manager/blob/main/helm/charts/default/templates/operator.kyma-project.io_telemetries.yaml). |
17 | 18 |
|
18 | | -``` |
19 | | - <!-- TABLE-START --> |
| 19 | +2. Set up the table generator in the `.md` file in which you want to generate the table. Add the `TABLE-START` and `TABLE-END` tags in the exact place in the document where you want to generate the table. |
20 | 20 |
|
21 | | - <!-- TABLE-END --> |
22 | | -``` |
| 21 | + ```bash |
| 22 | + <!-- TABLE-START --> |
| 23 | + |
| 24 | + <!-- TABLE-END --> |
| 25 | + ``` |
23 | 26 |
|
24 | | -### Call the Table Generator |
| 27 | +3. Build the table generator as a binary named `table-gen`, and add a new target to your module's Makefile that calls this binary. See the following example: |
25 | 28 |
|
26 | | -You can call the table generator either from the command line, or with the makefile: |
| 29 | + ```makefile |
| 30 | + .PHONY: crd-docs-gen |
| 31 | + crd-docs-gen: |
| 32 | + table-gen --crd-filename ./path/to/your-crd.yaml --md-filename ./docs/user/your-doc.md |
| 33 | + table-gen --crd-filename ./path/to/your-crd-2.yaml --md-filename ./docs/user/your-doc-2.md |
| 34 | + ... |
| 35 | + ``` |
| 36 | + |
| 37 | + Use the following parameters: |
| 38 | + - **--crd-filename**: Path to the CRD YAML file |
| 39 | + - **--md-filename**: Path to the Markdown file where the table will be inserted |
| 40 | + |
| 41 | + For a complete example, see the [Telemetry module's Makefile](https://github.com/kyma-project/telemetry-manager/blob/main/Makefile#L185). |
27 | 42 |
|
28 | | -- If you want to call the table generator from the command line, you can either build it and start it, or use `go run`. See the following example: |
29 | | - `go run main.go --crd-filename ../../installation/resources/crds/telemetry/logpipelines.crd.yaml --md-filename ../../docs/05-technical-reference/00-custom-resources/telemetry-01-logpipeline.md` |
| 43 | +4. In the terminal, run the following command from root: |
30 | 44 |
|
31 | | -- If you update a CRD that is already present in the makefile, you can just call `make generate`. |
| 45 | + ```bash |
| 46 | + make crd-docs-gen |
| 47 | + ``` |
| 48 | + To verify the result, go to the `.md` files and check that the table has been generated as specified. |
32 | 49 |
|
33 | | - If you want to compare only a particular operator or a specific CRD, specify the label you need while calling `make`; for example, `make telemetry-docs`. |
34 | 50 |
|
35 | | - To update the makefile, just introduce a new label for your CRD, and then add it to the `generate`. |
36 | | - Alternatively, if you want to group your `go run` commands, you can create different labels, group them under the one, and include it to the `generate`, the same way as with `make telemetry-docs`. |
| 51 | +### Use Command Line |
37 | 52 |
|
38 | | -## Verifying the Result |
39 | | - |
40 | | -Go to the `.md` files and check that the table has been generated as specified. |
| 53 | +You can also call the table generator from the command line, without needing to add it to the Makefile. To do this, you can either build it and start it, or use `go run`. See the following example: |
| 54 | + ```bash |
| 55 | + go run main.go --crd-filename ../../installation/resources/crds/telemetry/logpipelines.crd.yaml --md-filename ../../docs/05-technical-reference/00-custom-resources/telemetry-01-logpipeline.md |
| 56 | + ``` |
0 commit comments