34

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?

user1729409
  • 587
  • 2
  • 6
  • 10
  • Could you share the full (sanitized) ConfigMap? In case it helps here are examples of the structure a ConfigMap should be compiled to: https://kubernetes.io/docs/concepts/configuration/configmap/ – Leif Jones Sep 12 '20 at 04:23
  • Here is a pretty old issue about this problem https://github.com/helm/helm/issues/2192 that is closed, and here is my fresh issue to document this problem: https://github.com/helm/helm/issues/10632 – Murz Feb 01 '22 at 11:05

3 Answers3

38

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

Anna Slastnikova
  • 1,260
  • 9
  • 9
1

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" }}'
deepGrave
  • 320
  • 3
  • 11
0

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 }}
Brini
  • 77
  • 5