<p>Secret value is returning NIL</p>
<p>When i run the command below to check the values in the secret</p>
<pre><code>kubectl get secret cred2 -n service-b -o jsonpath='{.data.*}' | base64 -d
</code></pre>
<p>It returns a Nil value. How do i get the value that was passed on the values.yaml file?</p>
<pre><code>{&quot;auths&quot;:{&quot;%!s(&lt;nil&gt;)&quot;:{&quot;username&quot;:&quot;%!s(&lt;nil&gt;)&quot;,&quot;password&quot;:&quot;%!s(&lt;nil&gt;)&quot;,&quot;email&quot;:&quot;%!s(&lt;nil&gt;)&quot;,&quot;auth&quot;:&quot;JSFzKDxuaWw+KTolIXMoPG5pbD4p&quot;}}}%`
</code></pre>
<p>Sample Code used to generate the secret</p>
<pre><code>{{ range $index, $namespace := (lookup &quot;v1&quot; &quot;Namespace&quot; &quot;&quot; &quot;&quot;).items }}
{{ range $.Values.imageCredentials }}
apiVersion: v1
kind: Secret
metadata:  
  name: {{ .name }}
  namespace: {{ $namespace.metadata.name }}
type: kubernetes.io/dockerconfigjson
data:
  .dockerconfigjson: {{ template &quot;imagePullSecret&quot; $ }}
{{ end }}
{{ end }}
</code></pre>
<pre><code>values.yaml

imageCredentials:
 - name: cred1
   registry: quay.io
   username: someone
   password: sillyness
   email: someone@host.com
 - name: cred2
   registry: quay.io
   username: someone
   password: sillyness
   email: someone@host.com
</code></pre>
<pre><code>_helpers
{{- define &quot;imagePullSecret&quot; }}
{{- printf &quot;{\&quot;auths\&quot;:{\&quot;%s\&quot;:{\&quot;username\&quot;:\&quot;%s\&quot;,\&quot;password\&quot;:\&quot;%s\&quot;,\&quot;email\&quot;:\&quot;%s\&quot;,\&quot;auth\&quot;:\&quot;%s\&quot;}}}&quot; .registry .username .password .email (printf &quot;%s:%s&quot; .username .password | b64enc) | b64enc }}
{{- end }}
</code></pre>

<p>You should think of <code>template</code> (and the Helm-specific <code>include</code>) like function calls that take a single parameter.  Here you're passing that parameter as <code>$</code>, a special variable that refers to the top-level object.  You probably want <code>.</code>, which within a <code>range</code> loop refers to the current item.</p>
<pre class="lang-yaml prettyprint-override"><code>{{ range $.Values.imageCredentials }}
data:
  .dockerconfigjson: {{ template &quot;imagePullSecret&quot; . }}
{{/*                                               ^ not `$`  */}}
{{ end }}
</code></pre>
<p>You might be confusing this case with the similar <a href="https://stackoverflow.com/questions/74964282/create-kubernetes-docker-registry-secret-from-yaml-file-for-each-lookup-namespac">Create kubernetes docker-registry secret from yaml file for each lookup namespaces?</a>.  In that question, the template is trying to refer to <code>.Values.imageCredentials</code>.  This expression can be decomposed as: within <code>.</code> (the template parameter), find the field <code>Values</code>, and within that find the field <code>imageCredentials</code>.  In that question the template parameter must be the top-level Helm object so that it can dereference <code>.Values</code>.  But in your example here, you loop over a list in the top-level template, and need to pass the individual values into the supporting template.</p>
<pre class="lang-yaml prettyprint-override"><code>{{/* Your question: template accepts a sub-item of the values; pass
    `.` or another derived expression */}}
{{- define &quot;imagePullSecret&quot; -}}
{{ printf ... .registry .email ... }}
{{- end -}}

{{/* Other question: template accepts the top-level Helm object; pass
     `$`, a saved reference to the top-level object, or you can use
     `.` outside a `range` or `with` block that redefines it */}}
{{- define &quot;imagePullSecret&quot; -}}
{{- with .Values.imageCredentials }}...{{- end }}
{{- end -}}
</code></pre>
