Interview Prep/Helm/Templating: Go Templates & Sprig

How do you quote values safely?

BeginnerConceptTemplating: Go Templates & Sprig
Answer

Use quote (double quotes, with escaping) or squote:

env:
  - name: LOG_LEVEL
    value: {{ .Values.logLevel | quote }}
  - name: FEATURE_FLAG
    value: {{ .Values.featureFlag | quote }}   # true -> "true", required for env values

Environment variable values and annotations must be strings; an unquoted true or 8080 fails with cannot unmarshal bool into Go struct field EnvVar.value of type string. Do not quote fields that must be integers, such as containerPort or replicas.

All Helm questions Roadmap: Helm

More on Templating: Go Templates & Sprig