Skip to content

Commit 52f4bc6

Browse files
authored
Merge pull request #59 from norwoodj/auto-find-comments
feat!: Adds the capability to provide comments without the path to th…
2 parents b6ff99b + 4634ab3 commit 52f4bc6

File tree

18 files changed

+682
-176
lines changed

18 files changed

+682
-176
lines changed

README.md

+71-36
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@ The markdown generation is entirely [gotemplate](https://golang.org/pkg/text/tem
1010
from charts and generates a number of sub-templates that can be referenced in a template file (by default `README.md.gotmpl`).
1111
If no template file is provided, the tool has a default internal template that will generate a reasonably formatted README.
1212

13+
In particular, this tool will auto-detect descriptions of fields from comments:
14+
```yaml
15+
controller:
16+
# -- Configure the healthcheck for the ingress controller
17+
livenessProbe:
18+
httpGet:
19+
# -- This is the liveness check endpoint
20+
path: /healthz
21+
```
22+
23+
Resulting in a resulting README section like so:
24+
25+
| Key | Type | Default | Description |
26+
|-----|------|---------|-------------|
27+
| controller.livenessProbe | object | `{"httpGet":{"path":"/healthz","port":8080}}` | Configure the healthcheck for the ingress controller |
28+
| controller.livenessProbe.httpGet.path | string | `"/healthz"` | This is the liveness check endpoint |
29+
1330

1431
## Installation
1532
helm-docs can be installed using [homebrew](https://brew.sh/):
@@ -36,7 +53,20 @@ GO111MODULE=on go get github.com/norwoodj/helm-docs/cmd/helm-docs
3653

3754
## Usage
3855

39-
## Using binary directly
56+
## Pre-commit hook
57+
58+
If you want to automatically generate `README.md` files with a pre-commit hook, make sure you
59+
[install the pre-commit binary](https://pre-commit.com/#install), and add a [.pre-commit-config.yaml file](./.pre-commit-config.yaml)
60+
to your project. Then run:
61+
62+
```bash
63+
pre-commit install
64+
pre-commit install-hooks
65+
```
66+
67+
Future changes to your chart's `requirements.yaml`, `values.yaml`, `Chart.yaml`, or `README.md.gotmpl` files will cause an update to documentation when you commit.
68+
69+
## Running the binary directly
4070

4171
To run and generate documentation into READMEs for all helm charts within or recursively contained by a directory:
4272

@@ -51,22 +81,15 @@ for every chart that it finds.
5181

5282
## Using docker
5383

54-
You can mount directory with charts under `/helm-docs` within container.
55-
56-
Print generated documentation to stdout rather than modifying READMEs:
57-
58-
```bash
59-
docker run --rm -v "$(pwd):/helm-docs" -u $(id -u) jnorwood/helm-docs:latest --dry-run
60-
```
84+
You can mount a directory with charts under `/helm-docs` within the container.
6185

62-
Overwrite READMEs within mounted directory:
86+
Then run:
6387

6488
```bash
65-
docker run --rm -v "$(pwd):/helm-docs" -u $(id -u) jnorwood/helm-docs:latest
89+
docker run --rm --volume "$(pwd):/helm-docs" -u $(id -u) jnorwood/helm-docs:latest
6690
```
6791

6892
# Building from source
69-
7093
Notice that you need to have build chain toolkit for given platform and golang installed.
7194
Next you may need to export some vars to build standalone, non-linked binary for given platform and architecture:
7295

@@ -153,9 +176,10 @@ Chart.yaml file for a chart to skip processing for it.
153176

154177
## values.yaml metadata
155178
This tool can parse descriptions and defaults of values from `values.yaml` files. The defaults are pulled directly from
156-
the yaml in the file. Descriptions can be added for parameters by specifying the full path of the value and
157-
a particular comment format. I invite you to check out the [example-charts](./example-charts) to see how this is done in
158-
practice. In order to add a description for a parameter you need only put a comment somewhere in the file of the format:
179+
the yaml in the file.
180+
181+
It was formerly the case that descriptions had to be specified with the full path of the yaml field. This is no longer
182+
the case, although it is still supported. Where before you would document a values.yaml like so:
159183

160184
```yaml
161185
controller:
@@ -168,8 +192,28 @@ controller:
168192
replicas: 2
169193
```
170194

171-
Note that comments can continue on the next line. In that case leave out the double dash, and the lines will simply be
172-
appended with a space in-between.
195+
You may now equivelantly write:
196+
```yaml
197+
controller:
198+
publishService:
199+
# -- Whether to expose the ingress controller to the public world
200+
enabled: false
201+
202+
# -- Number of nginx-ingress pods to load balance between. Do not set this below 2.
203+
replicas: 2
204+
```
205+
206+
There are a number of limitations to this comment format, the foremost being that they can only comprise a single line and while
207+
the old-style comment for a field could appear anywhere in the file, the new comment must appear **on the line immediately preceding the field being documented.**
208+
209+
Additionally, there are a number of methods for encoding more data in the old comment format, documented later in this guide. These
210+
extensions are largely not supported with the new _auto-detection_ format.
211+
212+
I invite you to check out the [example-charts](./example-charts) to see how this is done in practice. The `but-auto-comments`
213+
examples in particular document the new comment format.
214+
215+
Note that comments of the old form can continue on the next line. In that case leave out the double dash, and the lines
216+
will simply be appended with a space in-between.
173217

174218
The following rules are used to determine which values will be added to the values table in the README:
175219

@@ -185,10 +229,10 @@ e.g. In this case, both `controller.livenessProbe` and `controller.livenessProbe
185229
the values table, but `controller.livenessProbe.httpGet.port` will not
186230
```yaml
187231
controller:
188-
# controller.livenessProbe -- Configure the healthcheck for the ingress controller
232+
# -- Configure the healthcheck for the ingress controller
189233
livenessProbe:
190234
httpGet:
191-
# controller.livenessProbe.httpGet.path -- This is the liveness check endpoint
235+
# -- This is the liveness check endpoint
192236
path: /healthz
193237
port: http
194238
```
@@ -207,7 +251,7 @@ and `controller.livenessProbe.httpGet.port` will be added to the table, with our
207251
controller:
208252
livenessProbe:
209253
httpGet:
210-
# controller.livenessProbe.httpGet.path -- This is the liveness check endpoint
254+
# -- This is the liveness check endpoint
211255
path: /healthz
212256
port: http
213257
```
@@ -222,11 +266,14 @@ Results in:
222266

223267
### nil values
224268
If you would like to define a key for a value, but leave the default empty, you can still specify a description for it
225-
as well as a type. Like so:
269+
as well as a type. This is possible with both the old and the new comment format:
226270
```yaml
227271
controller:
228-
# controller.replicas -- (int) Number of nginx-ingress pods to load balance between
272+
# -- (int) Number of nginx-ingress pods to load balance between
229273
replicas:
274+
275+
# controller.image -- (string) Number of nginx-ingress pods to load balance between
276+
image:
230277
```
231278
This could be useful when wanting to enforce user-defined values for the chart, where there are no sensible defaults.
232279

@@ -242,12 +289,13 @@ service:
242289
```
243290

244291
The order is important. The name must be spelled just like the column heading. The first comment must be the
245-
one specifying the key. The "@default" comment must follow.
292+
one specifying the key. The "@default" comment must follow. This is only possible with the old comment format
246293

247294
See [here](./example-charts/custom-template/values.yaml) for an example.
248295

249296
### Spaces and Dots in keys
250-
If a key name contains any "." or " " characters, that section of the path must be quoted in description comments e.g.
297+
In the old-style comment, if a key name contains any "." or " " characters, that section of the path must be quoted in
298+
description comments e.g.
251299

252300
```yaml
253301
service:
@@ -259,16 +307,3 @@ configMap:
259307
# configMap."not real config param" -- A completely fake config parameter for a useful example
260308
not real config param: value
261309
```
262-
263-
## Pre-commit hook
264-
265-
If you want to automatically generate `README.md` files with a pre-commit hook, make sure you
266-
[install the pre-commit binary](https://pre-commit.com/#install), and add a [.pre-commit-config.yaml file](./.pre-commit-config.yaml)
267-
to your project. Then run:
268-
269-
```bash
270-
pre-commit install
271-
pre-commit install-hooks
272-
```
273-
274-
Future changes to your chart's `requirements.yaml`, `values.yaml`, `Chart.yaml`, or `README.md.gotmpl` files will cause an update to documentation when you commit.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
name: nginx-ingress
3+
description: A simple wrapper around the stable/nginx-ingress chart that adds a few of our conventions
4+
version: "0.2.0"
5+
home: "https://github.com/norwoodj/helm-docs/tree/master/example-charts/nginx-ingress"
6+
sources: ["https://github.com/norwoodj/helm-docs/tree/master/example-charts/nginx-ingress"]
7+
engine: gotpl
8+
maintainers:
9+
10+
name: John Norwood
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# nginx-ingress
2+
3+
![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square)
4+
5+
A simple wrapper around the stable/nginx-ingress chart that adds a few of our conventions
6+
7+
**Homepage:** <https://github.com/norwoodj/helm-docs/tree/master/example-charts/nginx-ingress>
8+
9+
## Maintainers
10+
11+
| Name | Email | Url |
12+
| ---- | ------ | --- |
13+
| John Norwood | [email protected] | |
14+
15+
## Source Code
16+
17+
* <https://github.com/norwoodj/helm-docs/tree/master/example-charts/nginx-ingress>
18+
19+
## Requirements
20+
21+
| Repository | Name | Version |
22+
|------------|------|---------|
23+
| @stable | nginx-ingress | 0.22.1 |
24+
25+
## Values
26+
27+
| Key | Type | Default | Description |
28+
|-----|------|---------|-------------|
29+
| controller.extraVolumes | list | `[{"configMap":{"name":"nginx-ingress-config"},"name":"config-volume"}]` | Additional volumes to be mounted into the ingress controller container |
30+
| controller.image.repository | string | `"nginx-ingress-controller"` | |
31+
| controller.image.tag | string | `"18.0831"` | |
32+
| controller.ingressClass | string | `"nginx"` | Name of the ingress class to route through this controller |
33+
| controller.livenessProbe | object | `{"httpGet":{"path":"/healthz","port":8080}}` | Configure the healthcheck for the ingress controller |
34+
| controller.livenessProbe.httpGet.path | string | `"/healthz"` | This is the liveness check endpoint |
35+
| controller.name | string | `"controller"` | |
36+
| controller.persistentVolumeClaims | list | `[]` | List of persistent volume claims to create |
37+
| controller.podLabels | object | `{}` | The labels to be applied to instances of the controller pod |
38+
| controller.publishService.enabled | bool | `false` | Whether to expose the ingress controller to the public world |
39+
| controller.replicas | int | `nil` | Number of nginx-ingress pods to load balance between |
40+
| controller.service.annotations."external-dns.alpha.kubernetes.io/hostname" | string | `"stupidchess.jmn23.com"` | Hostname to be assigned to the ELB for the service |
41+
| controller.service.type | string | `"LoadBalancer"` | |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dependencies:
2+
- name: nginx-ingress
3+
version: "0.22.1"
4+
repository: "@stable"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
controller:
2+
name: controller
3+
image:
4+
repository: nginx-ingress-controller
5+
tag: "18.0831"
6+
7+
# -- List of persistent volume claims to create
8+
persistentVolumeClaims: []
9+
10+
# -- Additional volumes to be mounted into the ingress controller container
11+
extraVolumes:
12+
- name: config-volume
13+
configMap:
14+
name: nginx-ingress-config
15+
16+
# -- Configure the healthcheck for the ingress controller
17+
livenessProbe:
18+
httpGet:
19+
# -- This is the liveness check endpoint
20+
path: /healthz
21+
port: 8080
22+
23+
# -- Name of the ingress class to route through this controller
24+
ingressClass: nginx
25+
26+
# -- The labels to be applied to instances of the controller pod
27+
podLabels: {}
28+
29+
publishService:
30+
# -- Whether to expose the ingress controller to the public world
31+
enabled: false
32+
33+
# -- (int) Number of nginx-ingress pods to load balance between
34+
replicas:
35+
36+
service:
37+
annotations:
38+
# -- Hostname to be assigned to the ELB for the service
39+
external-dns.alpha.kubernetes.io/hostname: stupidchess.jmn23.com
40+
41+
type: LoadBalancer
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v2
2+
name: special-characters
3+
description: A chart demonstrating handling of special characters in values files
4+
version: "0.2.0"
5+
home: "https://github.com/norwoodj/helm-docs/tree/master/example-charts/special-characters"
6+
sources: ["https://github.com/norwoodj/helm-docs/tree/master/example-charts/special-characters"]
7+
engine: gotpl
8+
type: application
9+
maintainers:
10+
11+
name: John Norwood
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# special-characters
2+
3+
![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)
4+
5+
A chart demonstrating handling of special characters in values files
6+
7+
**Homepage:** <https://github.com/norwoodj/helm-docs/tree/master/example-charts/special-characters>
8+
9+
## Maintainers
10+
11+
| Name | Email | Url |
12+
| ---- | ------ | --- |
13+
| John Norwood | [email protected] | |
14+
15+
## Source Code
16+
17+
* <https://github.com/norwoodj/helm-docs/tree/master/example-charts/special-characters>
18+
19+
## Values
20+
21+
| Key | Type | Default | Description |
22+
|-----|------|---------|-------------|
23+
| elasticsearch.clusterHealthCheckParams | string | `"wait_for_status=yellow&timeout=1s"` | The Elasticsearch cluster health status params that will be used by readinessProbe command |
24+
| elasticsearch.clusterHealthCheckParamsDescription | string | `""` | Now let's put some special characters in the description: wait_for_status=yellow&timeout=1s |
25+
| htmlSnippets.one | string | `"<html>\n <head></head>\n <body>\n <h1>Is this right, I don't know html</h1>\n </body>\n</html>\n"` | |
26+
| htmlSnippets.three | string | `"<html><head></head></html>"` | Another description |
27+
| htmlSnippets.two | string | `""` | Let's put it in the description <html></html> |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
elasticsearch:
2+
# -- The Elasticsearch cluster health status params that will be used by readinessProbe command
3+
clusterHealthCheckParams: "wait_for_status=yellow&timeout=1s"
4+
5+
# -- Now let's put some special characters in the description: wait_for_status=yellow&timeout=1s
6+
clusterHealthCheckParamsDescription: ""
7+
8+
htmlSnippets:
9+
one: |
10+
<html>
11+
<head></head>
12+
<body>
13+
<h1>Is this right, I don't know html</h1>
14+
</body>
15+
</html>
16+
17+
# -- Let's put it in the description <html></html>
18+
two: ""
19+
20+
# -- Another description
21+
three: "<html><head></head></html>"

example-charts/special-characters/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ A chart demonstrating handling of special characters in values files
2323
| elasticsearch.clusterHealthCheckParams | string | `"wait_for_status=yellow&timeout=1s"` | The Elasticsearch cluster health status params that will be used by readinessProbe command |
2424
| elasticsearch.clusterHealthCheckParamsDescription | string | `""` | Now let's put some special characters in the description: wait_for_status=yellow&timeout=1s |
2525
| htmlSnippets.one | string | `"<html>\n <head></head>\n <body>\n <h1>Is this right, I don't know html</h1>\n </body>\n</html>\n"` | |
26-
| htmlSnippets.three | string | "<html><head></head></html>" | Another description |
26+
| htmlSnippets.three | string | `"<html><head></head></html>"` | Another description |
2727
| htmlSnippets.two | string | `""` | Let's put it in the description <html></html> |

example-charts/special-characters/values.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ htmlSnippets:
1818
two: ""
1919

2020
# htmlSnippets.three -- Another description
21-
# @default -- "<html><head></head></html>"
21+
# @default -- `"<html><head></head></html>"`
2222
three: ""

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ require (
1313
github.com/spf13/cobra v0.0.5
1414
github.com/spf13/viper v1.4.0
1515
github.com/stretchr/testify v1.2.2
16-
gopkg.in/yaml.v2 v2.2.2
16+
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
1717
k8s.io/helm v2.14.3+incompatible
1818
)

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl
163163
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
164164
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
165165
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
166+
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ=
167+
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
166168
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
167169
k8s.io/helm v2.14.3+incompatible h1:uzotTcZXa/b2SWVoUzM1xiCXVjI38TuxMujS/1s+3Gw=
168170
k8s.io/helm v2.14.3+incompatible/go.mod h1:LZzlS4LQBHfciFOurYBFkCMTaZ0D1l+p0teMg7TSULI=

0 commit comments

Comments
 (0)