9
votes

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
in some configuration files, such as grafana's dashboard json file, alert rule definition in prometheus, both of them use the {{..}} format alsoMarco

3 Answers

9
votes

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 }}
8
votes

You can embed it as a literal string with backticks:

{{`{{ "name" }}`}}
0
votes

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