Skip to content

Commit

Permalink
Improve code according to mjpitz suggestions
Browse files Browse the repository at this point in the history
Replace `# -- @ignore` with simple `@ignore`
  • Loading branch information
j-buczak committed May 11, 2022
1 parent 1bf1fee commit 39f98ee
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,10 @@ 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:
In cases you would like to ignore certain values, you can mark it with @ignored tag:

```yaml
# -- @ignored
# @ignored
service:
port: 8080
```
Expand Down
12 changes: 6 additions & 6 deletions example-charts/ignored-values-example/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ config:
# -- user with access to the database with the same name
- {name: hashbash, readwriteDatabases: [hashbash]}

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

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

# -- @ignore
ignoredConfig: 5
# @ignore
ignoredConfig: 6

configWithAllValuesIgnored:
# -- @ignore
# @ignore
ignoredOne: true
# -- @ignore
# @ignore
ignoredTwo: "?"
26 changes: 11 additions & 15 deletions pkg/helm/chart_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,23 +146,19 @@ 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)
}
func removeIgnored(rootNode *yaml.Node, parentKind yaml.Kind) {
newContent := make([]*yaml.Node , 0, len(rootNode.Content))
for i := 0; i < len(rootNode.Content); i++ {
node := rootNode.Content[i]
if !strings.Contains(node.HeadComment, "@ignore") {
removeIgnored(node, node.Kind)
newContent = append(newContent, node)
} else if parentKind == yaml.MappingNode {
// for parentKind each yaml key is represented by two nodes
i++
}
}
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)
}
rootNode.Content = newContent
}

func parseChartValuesFile(chartDirectory string) (yaml.Node, error) {
Expand Down

0 comments on commit 39f98ee

Please sign in to comment.