21

In a helm chart, we can define value as something like {{ Values.name }}, which will be replaced by the real value defined in values.yaml. But if the original value has the similar format such as {{name}}, when trying to install that chart, it will fail due to error that "name" is not defined. Is there any way to handle this?

3
  • What is the purpose of using "{{name}}" as a name of something?
    – nickgryg
    Nov 9, 2017 at 9:36
  • 2
    in some configuration files, such as grafana's dashboard json file, alert rule definition in prometheus, both of them use the {{..}} format also
    – Marco
    Nov 9, 2017 at 19:58
  • This helm RFE has been attracting lots of suggestions for workarounds: github.com/helm/helm/issues/2798 Apr 10 at 12:14

3 Answers 3

37

You can embed it as a literal string with backticks:

{{`{{ "name" }}`}}
2
  • 4
    This was the only suggestion that worked for me
    – Don Rhummy
    Oct 20, 2021 at 14:36
  • 1
    This should be the accepted answer. I agree that using .Files is good in some use cases, but this much more directly answers the question.
    – Vorticity
    Jul 6, 2022 at 18:55
12

You can escape double curly brackets in Go templates using {{ "{{" }}.

But the best way is embedding the alerting rules as separate files:

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "fullname" . }}-rules
  labels:
    chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
    prometheus: {{ template "fullname" . }}
data:
  {{ (.Files.Glob "rules/*").AsConfig | indent 2 }}
2
  • 1
    still cannot work. Trying to deploy the helm chart and got the error message: function "name" not defined
    – Marco
    Nov 10, 2017 at 3:30
  • 5
    For non-gophers: if your template fragment is inside a string like json: '{ "mustache": "{{ .Values.prefix }} {{ name }}" }' you can use back ticks to quote the inner {{ (although it gets pretty messy): json: '{ "mustache": "{{ .Values.prefix }} {{ `{{` }} name {{ `}}` }}" }' Sep 4, 2018 at 13:07
8

Use '{{"{{"}}name{{"}}"}}' for it to be read as {{name}}

1
  • This was also the way for me to add the variable in Jaeger tracesToLogsV2 in the Grafana datasource.
    – Diogo Cruz
    Mar 5 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.