<p>Does anyone know a way to <strong>refer to a namespace</strong> inside of values.yaml using an environment variable? </p>

<p>For example, when mapping a secret </p>

<pre><code>secret:
    # RabbitMQ password
    V_RABBIT_PASSWORD:
      secretKeyRef:
        name: jx-staging-rabbit //&lt;--- this needs to work for staging and prod
        key: rabbitmq-password
</code></pre>

<p>This is the section in deployment.yaml</p>

<pre><code>            - name: {{ $name | quote }}
              valueFrom:
                secretKeyRef:
                  name: {{ $value.secretKeyRef.name | quote }} //&lt;-- trying different combinations here
                  key: {{ $value.secretKeyRef.key | quote }}
</code></pre>

<p>attempts:</p>

<pre><code>${NAMESPACE}-{{ $value.secretKeyRef.name | quote }}
</code></pre>

<p>and</p>

<pre><code>{{ template "namespace" . }}-{{ $value.secretKeyRef.name | quote }}
</code></pre>

<p>Thanks</p>

Kaigo
<p>I guess this is in a helm chart for an app that you're deploying with jenkins-x. Helm has a <a href="https://github.com/helm/helm/blob/master/docs/chart_template_guide/builtin_objects.md" rel="nofollow noreferrer">Release.Namespace</a> value that you can access. So in the deployment.yaml you could use <code>{{ .Release.Namespace }}</code> Although <code>jx-staging</code> is also the name of the release so <code>{{ .Release.Name}}</code> that could equally apply here. I would expect this to look like:</p>

<pre><code>      valueFrom:
        secretKeyRef:
          name: {{ .Release.Name }}-{{ .Values.rabbitmq.name }}
          key: rabbitmq-password
</code></pre>

<p>Where <code>{{ .Values.rabbitmq.name }}</code> is equal to <code>rabbitmq</code> or whatever you call rabbitmq in your requirements.yaml. (<a href="https://github.com/Activiti/activiti-cloud-charts/blob/95a845ded439d71dc8983d3616fc9ef2de730ce5/activiti-cloud-audit/templates/deployment.yaml#L62" rel="nofollow noreferrer">Here's</a> an example chart doing it this way for postgres, it also uses rabbit but accesses the rabbit password differently.)</p>

<p>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 <a href="https://github.com/helm/charts/issues/5167" rel="nofollow noreferrer">https://github.com/helm/charts/issues/5167</a></p>

<p>The use of <code>{{ .Release.Name }}</code> 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. </p>

<p>(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 <a href="https://github.com/jenkins-x/draft-packs/pull/65" rel="nofollow noreferrer">pass it through the <code>tpl</code> function within the template</a>.)</p>
