title: Golang template (helm) iterating over a list of maps
body: <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>