<p>I have a template that renders a secret containing the credentials to log in to my server.  There is a deployment configuration in which this is done insecurely, in which case I don't want to render the secret.  Normally my values.yaml contains auth.myapp.username, and auth.myapp.password, however when the deployment lacks credentials, the whole auth section no longer exists.</p>
<p>My secret template looks like this:</p>
<pre><code>{{ if .Values.auth.myapp.username }}
apiVersion: v1
kind: Secret
metadata:
  name: myapp-credentials-secret
type: Opaque
data:
  USERNAME: {{ .Values.auth.myapp.username | b64enc }}
  PASSWORD: {{ .Values.auth.myapp.password | b64enc }}
{{ end }}
</code></pre>
<p>However I get an error when running helm install on this because the 'auth' value doesn't exist, it fails to lookup myapp from it.</p>
<p>I know I can get around this by not using the --strict flag, but I don't have control over that, is there a proper way of predicating on nested values?</p>

Andy
<p>Use haskey function:</p>
<pre><code>{{ if haskey .Values &quot;auth&quot; }}
apiVersion: v1
kind: Secret
metadata:
  name: myapp-credentials-secret
type: Opaque
data:
  USERNAME: {{ .Values.auth.myapp.username | b64enc }}
  PASSWORD: {{ .Values.auth.myapp.password | b64enc }}
{{ end }}
</code></pre>
<p>The <code>hasKey</code> <a href="https://helm.sh/docs/chart_template_guide/function_list/" rel="nofollow noreferrer">function</a> returns <code>true</code> if the given dict contains the given key.</p>
<pre><code>hasKey $myDict &quot;name1&quot;
</code></pre>
<p>If the key is not found, this returns <code>false</code>.</p>
