How an helm chart have an attribute with value contain {{ }}
Asked Answered
S

4

22

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?

Scoggins answered 9/11, 2017 at 6:48 Comment(3)
What is the purpose of using "{{name}}" as a name of something?Blenny
in some configuration files, such as grafana's dashboard json file, alert rule definition in prometheus, both of them use the {{..}} format alsoScoggins
This helm RFE has been attracting lots of suggestions for workarounds: github.com/helm/helm/issues/2798Mistress
P
39

You can embed it as a literal string with backticks:

{{`{{ "name" }}`}}
Proserpina answered 5/3, 2020 at 12:13 Comment(2)
This was the only suggestion that worked for meSurf
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.Kennithkennon
B
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 }}
Blenny answered 9/11, 2017 at 21:9 Comment(2)
still cannot work. Trying to deploy the helm chart and got the error message: function "name" not definedScoggins
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 {{ `}}` }}" }'Mehala
G
8

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

Garret answered 25/6, 2021 at 11:10 Comment(1)
This was also the way for me to add the variable in Jaeger tracesToLogsV2 in the Grafana datasource.Niacin
O
1

Use pipe '|' and in next line pass txt with string what incluses {{ and }}

name: NAME_OF_VALUE
value: | 
  value_with{{rest_of_text}}and_other_text
Orchid answered 27/5, 2024 at 7:38 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.