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
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 {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on your comment below, it seems this should be a separate if block and not part of the prior if?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be reworded to:
if HeadComment contains @ignore don't include it in newContent. If root node is MappingNode don't include the next node as well

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh! I see what you're saying...

// 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