Skip to content

Add option for ignoring values #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,14 @@ The order is important. The first comment line(s) must be the one specifying the
the description for the field. The `@default` comment must follow.

See [here](./example-charts/custom-template/values.yaml) for an example.
### Ignoring values
In cases you would like to ignore certain values, you can mark it as ignored:

```yaml
# -- @ignored
service:
port: 8080
```

### Spaces and Dots in keys
In the old-style comment, if a key name contains any "." or " " characters, that section of the path must be quoted in
Expand Down
11 changes: 11 additions & 0 deletions example-charts/ignored-values-example/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v2
name: ignored-values-example
description: Based on best-values-example
version: "0.1.0"
home: "https://github.com/norwoodj/helm-docs/tree/master/example-charts/ignored-values-example"
sources: ["https://github.com/norwoodj/helm-docs/tree/master/example-charts/ignored-values-example"]
engine: gotpl
type: application
maintainers:
- email: [email protected]
name: Jakub Buczak
35 changes: 35 additions & 0 deletions example-charts/ignored-values-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# ignored-values-example

![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)

Based on best-values-example

**Homepage:** <https://github.com/norwoodj/helm-docs/tree/master/example-charts/ignored-values-example>

## Maintainers

| Name | Email | Url |
| ---- | ------ | --- |
| Jakub Buczak | <[email protected]> | |

## Source Code

* <https://github.com/norwoodj/helm-docs/tree/master/example-charts/ignored-values-example>

## Values

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| config.databasesToCreate[0] | string | `"postgresql"` | default database for storage of database metadata |
| config.databasesToCreate[1] | string | `"hashbash"` | database for the [hashbash](https://github.com/norwoodj/hashbash) project |
| config.usersToCreate[0] | object | `{"admin":true,"name":"root"}` | admin user |
| config.usersToCreate[1] | object | `{"name":"hashbash","readwriteDatabases":["hashbash"]}` | user with access to the database with the same name |
| configWithAllValuesIgnored | object | `{}` | |
| statefulset.extraVolumes | list | `[{"emptyDir":{},"name":"data"}]` | Additional volumes to be mounted into the database container |
| statefulset.image.repository | string | `"jnorwood/postgresq"` | Image to use for deploying, must support an entrypoint which creates users/databases from appropriate config files |
| statefulset.image.tag | string | `"11"` | |
| statefulset.livenessProbe | object | `{"enabled":false}` | Configure the healthcheck for the database |
| statefulset.podLabels | object | `{}` | The labels to be applied to instances of the database |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.9.1](https://github.com/norwoodj/helm-docs/releases/v1.9.1)
51 changes: 51 additions & 0 deletions example-charts/ignored-values-example/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
statefulset:
image:
# -- Image to use for deploying, must support an entrypoint
# which creates users/databases from appropriate config files
repository: jnorwood/postgresq
tag: "11"

# -- Additional volumes to be mounted into the database container
extraVolumes:
- name: data
emptyDir: {}

# -- Configure the healthcheck for the database
livenessProbe:
enabled: false

# -- The labels to be applied to instances of the database
podLabels: {}

config:
databasesToCreate:
# -- default database for storage of database metadata
- postgresql

# -- database for the [hashbash](https://github.com/norwoodj/hashbash) project
- hashbash

usersToCreate:
# -- admin user
- {name: root, admin: true}

# -- user with access to the database with the same name
- {name: hashbash, readwriteDatabases: [hashbash]}

# -- @ignore test
- {name: test, readDatabases: [test]}

# -- @ignore
internalConfig:
rpcPort: 8080
# -- this should also be ignored
generateData: true

# -- @ignore
ignoredConfig: 5

configWithAllValuesIgnored:
# -- @ignore
ignoredOne: true
# -- @ignore
ignoredTwo: "?"
20 changes: 20 additions & 0 deletions pkg/helm/chart_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,25 @@ func parseChartRequirementsFile(chartDirectory string, apiVersion string) (Chart
return chartRequirements, nil
}

func removeIgnored(rootNode *yaml.Node, rootKind yaml.Kind) {
var toDelete []int
for i, node := range rootNode.Content {
if strings.Contains(node.HeadComment, "# -- @ignore") {
toDelete = append(toDelete, i)
if rootKind == yaml.MappingNode {
toDelete = append(toDelete, i+1)
}
}
}
for i := len(toDelete) - 1; i >= 0; i-- {
var d int = toDelete[i]
rootNode.Content = append(rootNode.Content[:d], rootNode.Content[d+1:]...)
}
for _, node := range rootNode.Content {
removeIgnored(node, node.Kind)
}
}

func parseChartValuesFile(chartDirectory string) (yaml.Node, error) {
valuesPath := filepath.Join(chartDirectory, viper.GetString("values-file"))
yamlFileContents, err := getYamlFileContents(valuesPath)
Expand All @@ -156,6 +175,7 @@ func parseChartValuesFile(chartDirectory string) (yaml.Node, error) {
}

err = yaml.Unmarshal(yamlFileContents, &values)
removeIgnored(&values, values.Kind)
return values, err
}

Expand Down