Skip to content

Commit 1bf1fee

Browse files
committed
Add option for ignoring values
Ignoring is set up using `# -- @ignored` tag
1 parent ef73e2e commit 1bf1fee

File tree

5 files changed

+125
-0
lines changed

5 files changed

+125
-0
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,14 @@ The order is important. The first comment line(s) must be the one specifying the
321321
the description for the field. The `@default` comment must follow.
322322

323323
See [here](./example-charts/custom-template/values.yaml) for an example.
324+
### Ignoring values
325+
In cases you would like to ignore certain values, you can mark it as ignored:
326+
327+
```yaml
328+
# -- @ignored
329+
service:
330+
port: 8080
331+
```
324332

325333
### Spaces and Dots in keys
326334
In the old-style comment, if a key name contains any "." or " " characters, that section of the path must be quoted in
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v2
2+
name: ignored-values-example
3+
description: Based on best-values-example
4+
version: "0.1.0"
5+
home: "https://github.com/norwoodj/helm-docs/tree/master/example-charts/ignored-values-example"
6+
sources: ["https://github.com/norwoodj/helm-docs/tree/master/example-charts/ignored-values-example"]
7+
engine: gotpl
8+
type: application
9+
maintainers:
10+
11+
name: Jakub Buczak
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# ignored-values-example
2+
3+
![Version: 0.1.0](https://img.shields.io/badge/Version-0.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)
4+
5+
Based on best-values-example
6+
7+
**Homepage:** <https://github.com/norwoodj/helm-docs/tree/master/example-charts/ignored-values-example>
8+
9+
## Maintainers
10+
11+
| Name | Email | Url |
12+
| ---- | ------ | --- |
13+
| Jakub Buczak | <[email protected]> | |
14+
15+
## Source Code
16+
17+
* <https://github.com/norwoodj/helm-docs/tree/master/example-charts/ignored-values-example>
18+
19+
## Values
20+
21+
| Key | Type | Default | Description |
22+
|-----|------|---------|-------------|
23+
| config.databasesToCreate[0] | string | `"postgresql"` | default database for storage of database metadata |
24+
| config.databasesToCreate[1] | string | `"hashbash"` | database for the [hashbash](https://github.com/norwoodj/hashbash) project |
25+
| config.usersToCreate[0] | object | `{"admin":true,"name":"root"}` | admin user |
26+
| config.usersToCreate[1] | object | `{"name":"hashbash","readwriteDatabases":["hashbash"]}` | user with access to the database with the same name |
27+
| configWithAllValuesIgnored | object | `{}` | |
28+
| statefulset.extraVolumes | list | `[{"emptyDir":{},"name":"data"}]` | Additional volumes to be mounted into the database container |
29+
| statefulset.image.repository | string | `"jnorwood/postgresq"` | Image to use for deploying, must support an entrypoint which creates users/databases from appropriate config files |
30+
| statefulset.image.tag | string | `"11"` | |
31+
| statefulset.livenessProbe | object | `{"enabled":false}` | Configure the healthcheck for the database |
32+
| statefulset.podLabels | object | `{}` | The labels to be applied to instances of the database |
33+
34+
----------------------------------------------
35+
Autogenerated from chart metadata using [helm-docs v1.9.1](https://github.com/norwoodj/helm-docs/releases/v1.9.1)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
statefulset:
2+
image:
3+
# -- Image to use for deploying, must support an entrypoint
4+
# which creates users/databases from appropriate config files
5+
repository: jnorwood/postgresq
6+
tag: "11"
7+
8+
# -- Additional volumes to be mounted into the database container
9+
extraVolumes:
10+
- name: data
11+
emptyDir: {}
12+
13+
# -- Configure the healthcheck for the database
14+
livenessProbe:
15+
enabled: false
16+
17+
# -- The labels to be applied to instances of the database
18+
podLabels: {}
19+
20+
config:
21+
databasesToCreate:
22+
# -- default database for storage of database metadata
23+
- postgresql
24+
25+
# -- database for the [hashbash](https://github.com/norwoodj/hashbash) project
26+
- hashbash
27+
28+
usersToCreate:
29+
# -- admin user
30+
- {name: root, admin: true}
31+
32+
# -- user with access to the database with the same name
33+
- {name: hashbash, readwriteDatabases: [hashbash]}
34+
35+
# -- @ignore test
36+
- {name: test, readDatabases: [test]}
37+
38+
# -- @ignore
39+
internalConfig:
40+
rpcPort: 8080
41+
# -- this should also be ignored
42+
generateData: true
43+
44+
# -- @ignore
45+
ignoredConfig: 5
46+
47+
configWithAllValuesIgnored:
48+
# -- @ignore
49+
ignoredOne: true
50+
# -- @ignore
51+
ignoredTwo: "?"

pkg/helm/chart_info.go

+20
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,25 @@ func parseChartRequirementsFile(chartDirectory string, apiVersion string) (Chart
146146
return chartRequirements, nil
147147
}
148148

149+
func removeIgnored(rootNode *yaml.Node, rootKind yaml.Kind) {
150+
var toDelete []int
151+
for i, node := range rootNode.Content {
152+
if strings.Contains(node.HeadComment, "# -- @ignore") {
153+
toDelete = append(toDelete, i)
154+
if rootKind == yaml.MappingNode {
155+
toDelete = append(toDelete, i+1)
156+
}
157+
}
158+
}
159+
for i := len(toDelete) - 1; i >= 0; i-- {
160+
var d int = toDelete[i]
161+
rootNode.Content = append(rootNode.Content[:d], rootNode.Content[d+1:]...)
162+
}
163+
for _, node := range rootNode.Content {
164+
removeIgnored(node, node.Kind)
165+
}
166+
}
167+
149168
func parseChartValuesFile(chartDirectory string) (yaml.Node, error) {
150169
valuesPath := filepath.Join(chartDirectory, viper.GetString("values-file"))
151170
yamlFileContents, err := getYamlFileContents(valuesPath)
@@ -156,6 +175,7 @@ func parseChartValuesFile(chartDirectory string) (yaml.Node, error) {
156175
}
157176

158177
err = yaml.Unmarshal(yamlFileContents, &values)
178+
removeIgnored(&values, values.Kind)
159179
return values, err
160180
}
161181

0 commit comments

Comments
 (0)