I have got several namespaces (iso, dev, sandbox, etc.) which correspond to my different environments. For each environment and thus namespace, there is an associated db. When I deploy my pod with Helm, I would like to inject the namespace inside a value to get the appropriate password .
In my values file I have something that looks like this :
db:
iso: passwordISO
dev: passwordDEV
sandbox: passwordSANDBOX
spec: passwordSPEC
val: passwordVAL
and in my consumer_config file I have this :
db_host: DB_HOST-{{ .Release.Namespace }}
db_port: DB_PORT
db_name: DB_NAME
db_user: DB_PORT
db_password: {{ .Values.db.iso }}
I already tried to use the {{- include }}
pattern but with no success. I also tried {{ .Values.db.{{ .Release.Namespace }}}}
giving me the following error unexpected <.> in operand
Any insight on how to do this or any workaround ?
As Helm is based on the Go-template language, the functions availabe in the go-template language can be of help:
{{ index .Values.db .Release.Namespace }}
From the docs (go-template docs):
index Returns the result of indexing its first argument by the following arguments. Thus "index x 1 2 3" is, in Go syntax, x[1][2][3]. Each indexed item must be a map, slice, or array.
so in this case you index .Values.db
with the key .Release.Namespace