<p>I have simple helm chart. I have a <code>labels:</code> block that I need to refer in a <code>Deployment</code></p>
<p>Here's my <code>values.yaml</code></p>
<pre><code>labels:
    app: test-app
    group: test-group
    provider: test-provider
</code></pre>
<p>And in the <code>templates/deployment.yaml</code> I need to add the above whole <code>labels</code> block. So I did;</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: {{ include &quot;accountmasterdata.fullname&quot; . }}
  namespace: {{ .Values.namespace }}
  labels:
  {{ .Values.labels | nindent 4 }}

  {{- include &quot;accountmasterdata.labels&quot; . | nindent 4 }} 
</code></pre>
<p>But I get the following error</p>
<blockquote>
<p>wrong type for value; expected string; got map[string]interface {}</p>
</blockquote>
<p>Can someone help me with two things:</p>
<ol>
<li><p>How can I solve this issue</p>
</li>
<li><p>And in the line where it says <code>{{- include &quot;accountmasterdata.labels&quot; . | nindent 4 }} </code>, where I can see the <code>accountmasterdata.labels</code> values? And how to override those?</p>
</li>
</ol>
<p>Thank you!</p>

Jananath Banuka
<p>Iterating over a mapping is covered in the &quot;<a href="https://helm.sh/docs/chart_template_guide/variables/" rel="nofollow noreferrer">Variables</a>&quot; documentation:</p>
<blockquote>
<p>For data structures that have both a key and a value, we can use range to get both. For example, we can loop through .Values.favorite like this:</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-configmap
data:
  myvalue: &quot;Hello World&quot;
  {{- range $key, $val := .Values.favorite }}
  {{ $key }}: {{ $val | quote }}
  {{- end }}
</code></pre>
</blockquote>
<p>So in your template, you would handle the value of <code>.Values.labels</code> like this:</p>
<pre><code>  labels:
{{- range $name, $value := .Values.labels }}
    {{ $name | quote }}: {{ $value | quote }}
{{- end -}}
</code></pre>
<hr />
<blockquote>
<p>And in the line where it says {{- include &quot;accountmasterdata.labels&quot; . | nindent 4 }} , where I can see the accountmasterdata.labels values? And how to override those?</p>
</blockquote>
<p>Is this a template you are writing? If so, where have you defined these values? Presumably in your <code>templates/</code> directory there exists a file that includes something like:</p>
<pre><code>{{- define &quot;accountmasterdata.labels&quot; -}}
...
{{- end -}}
</code></pre>
<p>The contents of that block are what will get inserted at the point of reference.</p>
<hr />
<p>Lastly, in your template you have:</p>
<pre><code>namespace: {{ .Values.namespace }}
</code></pre>
<p>But you probably want to use <code>.Release.Namespace</code> instead:</p>
<pre><code>namespace: {{ .Release.Namespace | quote }}
</code></pre>
<hr />
<p>With the above changes in place, I end up with:</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: {{ include &quot;accountmasterdata.fullname&quot; . }}
  namespace: {{ .Release.Namespace | quote }}
  labels:
{{- range $name, $value := .Values.labels }}
    {{ $name | quote }}: {{ $value | quote }}
{{- end -}}
{{- include &quot;accountmasterdata.labels&quot; . | nindent 4 }} 
</code></pre>
