Helm templating doesn't let me use dash in names
Asked Answered
T

4

39

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?

Talc answered 11/9, 2020 at 20:8 Comment(2)
Could you share the full (sanitized) ConfigMap? In case it helps here are examples of the structure a ConfigMap should be compiled to: kubernetes.io/docs/concepts/configuration/configmapInterdisciplinary
Here is a pretty old issue about this problem github.com/helm/helm/issues/2192 that is closed, and here is my fresh issue to document this problem: github.com/helm/helm/issues/10632Comines
B
45

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

Bearcat answered 12/9, 2020 at 18:6 Comment(1)
it works for me only if single quotes were added xyz.abc-def: '{{ index .Values.xyz "abc-def" }}'Nolte
L
6

For future or similar questions

I had a nested value like this in values.yaml:

gitlab-runner:
  gitlabUrl: http://192.168.49.2:31122

I wanted to reference it in configmap.yaml, in that case i used double-quotes twice:

apiVersion: v1
kind: ConfigMap
metadata:
  name: gitlab-config
#   namespace: {{ .Release.Name }}-ns
data:
  gitlab.rb: |
    external_url '{{ index .Values "gitlab-runner" "gitlabUrl" }}'
Liguria answered 31/5, 2023 at 14:2 Comment(0)
A
1
{{ toYaml (index .Values "jobs" "update-es" "resources") | nindent 12 }}
Alexaalexander answered 26/6, 2024 at 7:4 Comment(0)
O
-3

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 }}
Olnay answered 19/1, 2021 at 16:49 Comment(1)
If you remove '-' then you also rename it to the values file.Macruran

© 2022 - 2025 — McMap. All rights reserved.