Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Helm templating doesn't let me use dash in names

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?

like image 657
user1729409 Avatar asked Sep 11 '20 20:09

user1729409


People also ask

What is dash in helm template?

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.

What does {{ }} mean in helm?

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.

How do you name a helm chart?

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.

What does the helm Template command do?

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.


2 Answers

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

like image 95
Anna Slastnikova Avatar answered Sep 19 '22 06:09

Anna Slastnikova


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 }}
like image 26
Brini Avatar answered Sep 21 '22 06:09

Brini