<p>I'm having the following secret definition:</p>
<pre><code>apiVersion: v1
kind: Secret
metadata:
    name: &quot;{{ .Release.Name }}-psql&quot;
type: Opaque
stringData:
  {{ if not .Release.IsUpgrade }}
  dbReplPassword: {{ (randAlphaNum 23) | quote }}
  {{ else  }}
  dbReplPassword: {{ index (lookup &quot;v1&quot; &quot;Secret&quot; .Release.Namespace &quot;{{ .Release.Name }}-psql&quot;).data &quot;dbReplPassword&quot; | b64dec | quote }}
  {{ end }}
</code></pre>
<p>On initial installation of my helm chart, everything works smoothly. But when I upgrade my helm chart, it shows me the following error:</p>
<blockquote>
<p>pgsql.yaml:11:21: executing &quot;helm-chart/templates/pgsql.yaml&quot; at
&lt;index (lookup &quot;v1&quot; &quot;Secret&quot; .Release.Namespace &quot;{{ .Release.Name
}}-psql&quot;).data &quot;dbReplPassword&quot;&gt;: error calling index: index of
untyped nil</p>
</blockquote>
<p>I guess the problem is the &quot;{{ .Release.Name }}-psql&quot; part of the lookup function, but I've no idea how I can fix this issue. Is anyone having any idea how I can fix it?</p>

Nrgyzer
<p>You can't nest Helm templates like this.  The standard <a href="https://pkg.go.dev/text/template" rel="nofollow noreferrer">Go <code>text/template</code> language</a> includes a <code>printf</code> function that you can use to construct a string from parameters, so use this instead:</p>
<pre class="lang-none prettyprint-override"><code>... (lookup &quot;v1&quot; &quot;Secret&quot; .Release.Namespace (printf &quot;%s-psql&quot; .Release.Name)) ...
</code></pre>
<p>It could be clearer to break up this complex expression into multiple variables:</p>
<pre class="lang-yaml prettyprint-override"><code>{{- $secretName := printf &quot;%s-psql&quot; .Release.Name }}
{{- $secret := lookup &quot;v1&quot; &quot;Secret&quot; .Release.Namespace $secretName }}
dbReplPassword: {{ $secret.data.dbReplPassword | b64dec | quote }}
</code></pre>
