Does anyone know a way to refer to a namespace inside of values.yaml using an environment variable?
For example, when mapping a secret
secret:
# RabbitMQ password
V_RABBIT_PASSWORD:
secretKeyRef:
name: jx-staging-rabbit //<--- this needs to work for staging and prod
key: rabbitmq-password
This is the section in deployment.yaml
- name: {{ $name | quote }}
valueFrom:
secretKeyRef:
name: {{ $value.secretKeyRef.name | quote }} //<-- trying different combinations here
key: {{ $value.secretKeyRef.key | quote }}
attempts:
${NAMESPACE}-{{ $value.secretKeyRef.name | quote }}
and
{{ template "namespace" . }}-{{ $value.secretKeyRef.name | quote }}
Thanks
I guess this is in a helm chart for an app that you're deploying with jenkins-x. Helm has a Release.Namespace value that you can access. So in the deployment.yaml you could use {{ .Release.Namespace }}
Although jx-staging
is also the name of the release so {{ .Release.Name}}
that could equally apply here. I would expect this to look like:
valueFrom:
secretKeyRef:
name: {{ .Release.Name }}-{{ .Values.rabbitmq.name }}
key: rabbitmq-password
Where {{ .Values.rabbitmq.name }}
is equal to rabbitmq
or whatever you call rabbitmq in your requirements.yaml. (Here's an example chart doing it this way for postgres, it also uses rabbit but accesses the rabbit password differently.)
If you have the secret loading correctly but still get password problems then make sure you're setting an explicit password value as otherwise you could be hitting https://github.com/helm/charts/issues/5167
The use of {{ .Release.Name }}
won't work inside of the values.yaml but I'm not sure if you need it to if you can do it in the deployment.yaml.
(If you really do need access to a function from the values.yaml then you need to have an entry for the string value in the values.yaml and then pass it through the tpl
function within the template.)