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?
How an helm chart have an attribute with value contain {{ }}
Asked Answered
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 also –
Scoggins
This helm RFE has been attracting lots of suggestions for workarounds: github.com/helm/helm/issues/2798 –
Mistress
You can embed it as a literal string with backticks:
{{`{{ "name" }}`}}
This was the only suggestion that worked for me –
Surf
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 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 }}
still cannot work. Trying to deploy the helm chart and got the error message: function "name" not defined –
Scoggins
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 Use '{{"{{"}}name{{"}}"}}'
for it to be read as {{name}}
This was also the way for me to add the variable in Jaeger tracesToLogsV2 in the Grafana datasource. –
Niacin
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
© 2022 - 2025 — McMap. All rights reserved.