I'm trying to dynamically specify the name of a file to include in a configmap.yaml, using the Helm templating language.
Here is an example:
{{- $filename := .Values.KRB5_REALM -}}
apiVersion: v1
data:
# When the config map is mounted as a volume, these will be created as files.
krb5.conf: |
{{ .Files.Get $filename".krb5.conf" | indent 4 }}
kind: ConfigMap
metadata:
name: {{ template "myapp.fullname" . }}
labels:
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
app: {{ template "myapp.name" . }}
environment: {{ .Values.environment }}
The above code results in an error.
I've tried several variations but without any success, such as:
{{ .Files.Get .Values.KRB5_REALM".krb5.conf" | indent 4 }}
How can I resolve this issue?
The usual way to assemble strings like this is with the Go text/template printf
function. One way to do it could be:
{{ printf "%s.krb5.conf" .Values.KRB5_REALM | .Files.Get | indent 4 }}
Or you could parenthesize the expression:
{{ .Files.Get (printf "%s.krb5.conf" .Values.KRB5_REALM) | indent 4 }}