<p>I'm using helm to generate kubernetes yamls. </p>

<p>My values.yaml looks like this:</p>

<pre><code>...
jobs:
  - nme: job1
    command: [sh, -c, "/app/deployment/start.sh job1"]
    activeDeadlineSeconds: 600
  - name: job2
    command: [sh, -c, "/app/deployment/start.sh job2"]
    activeDeadlineSeconds: 600
...
</code></pre>

<p><code>templates/jobs.yaml</code></p>

<pre><code>{{ range $i, $job := .Values.jobs -}}
apiVersion: batch/v1
kind: Job
metadata:
  name: {{ template "name" . }}-{{ $job.name }}
  labels:
    chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
spec:
  activeDeadlineSeconds: {{ $job.activeDeadlineSeconds }}
  template:
    metadata:
      labels:
        app: {{ template "name" . }}-{{ $job.name }}
    spec:
      containers:
      - name: {{ .Chart.Name }}
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        command: {{ $job.command }}
        env:
{{ toYaml .Values.service.env | indent 10 }}
        ports:
        - containerPort: {{ .Values.service.internalPort }}
{{- end }}
</code></pre>

<p>Helm is failing with this error:</p>

<pre><code>Error: UPGRADE FAILED: render error in "app1/templates/jobs.yaml": template: app1/templates/_helpers.tpl:6:18: executing "name" at &lt;.Chart.Name&gt;: can't evaluate field Name in type interface {}
</code></pre>

<p>When I look at _helpers.tpl:</p>

<pre><code>{{- define "name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
</code></pre>

<p>If I remove the range loop and references to $job in my <code>jobs.yaml</code>, the _helpers.tpl <code>name</code> template works fine. When I add in the loop, it fails. </p>

<p>It seems like within the loop, all dot <code>.</code> pipeline, which contains the scope for <code>.Chart</code> and <code>.Values</code>, is reassigned to something else.</p>

<p>What am I doing wrong?  </p>

<p>Inside the loop the value of the <code>.</code> is set to the current element and you have to use <code>$.Chart.Name</code> to access your data.</p>

<p>I asked a similar question and I think the answer <a href="https://stackoverflow.com/a/44734585/8131948">https://stackoverflow.com/a/44734585/8131948</a> will answer your question too.</p>
