Marco
Marco

Reputation: 261

How an helm chart have an attribute with value contain {{ }}

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?

Upvotes: 25

Views: 30271

Answers (4)

Adam Kieliszek
Adam Kieliszek

Reputation: 7

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

Upvotes: -1

rohatgisanat
rohatgisanat

Reputation: 828

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

Upvotes: 8

Steve Buzonas
Steve Buzonas

Reputation: 5690

You can embed it as a literal string with backticks:

{{`{{ "name" }}`}}

Upvotes: 45

nickgryg
nickgryg

Reputation: 28593

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

Upvotes: 12

Related Questions