I am creating a helm chart for my app. In the templates directory, I have a config-map.yaml with this in it
{{- with Values.xyz }}
xyz.abc-def: {{ .abc-def }}
{{- end }}
When I try to run helm install I get a
Error: parse error in "config-map.yaml": template:config-map.yaml:2: unexpected bad character U+002D '-' in command.
Is there a way to use dashes in the name and variable for helm?
First, the curly brace syntax of template declarations can be modified with special characters to tell the template engine to chomp whitespace. {{- (with the dash and space added) indicates that whitespace should be chomped left, while -}} means whitespace to the right should be consumed.
The Helm template syntax is based on the Go programming language's text/template package. The braces {{ and }} are the opening and closing brackets to enter and exit template logic.
Chart names should use lower case letters and numbers, and start with a letter. Hyphens (-) are allowed, but are known to be a little trickier to work with in Helm templates (see issue #2192 for more information). Neither uppercase letters nor underscores should be used in chart names.
With Helm's helm template command, you can check the output of the chart in fully rendered Kubernetes resource templates. This is a very handy command to check the templates' outputs, especially when you are developing a new chart, making changes to the chart, debugging, and so on.
Might be worth trying using index
method:
xyz.abc-def: {{ index .Values.xyz "abc-def" }}
looks like it's still restricted by helm to allow hyphens in variable names (as well in subchart names) and index
is a workaround
I faced the same issue because the resource defined had a '-' in its name:
resources:
{{- with .Values.my-value }}
After I removed the '-', the error disappeared:
resources:
{{- with .Values.myvalue }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With