<p>So I have an Helm template:</p>
<pre><code>    spec:
      containers:
        - name: {{ .Values.dashboard.containers.name }}
          image: {{ .Values.dashboard.containers.image.repository }}:{{ .Values.dashboard.containers.image.tag }}
          imagePullPolicy: Always
          env:
            - name: BASE_PATH
              value: /myapp/web
</code></pre>
<p>and I want to pass extra environment variable to it</p>
<p>my <code>values.yaml</code>:</p>
<pre><code>  extraEnvs:
    - name: SOMETHING_ELSE
      value: hello
    - name: SOMETHING_MORE
      value: world
</code></pre>
<p>how can I do it so that my result would be like this?</p>
<pre><code>    spec:
      containers:
        - name: {{ .Values.dashboard.containers.name }}
          image: {{ .Values.dashboard.containers.image.repository }}:{{ .Values.dashboard.containers.image.tag }}
          imagePullPolicy: Always
          env:
            - name: BASE_PATH
              value: /myapp/web
            - name: SOMETHING_ELSE
              value: hello
            - name: SOMETHING_MORE
              value: world
</code></pre>
<p>I was thinking something like this:</p>
<pre><code>  {{- if .Values.extraEnvs}}
    env: -|
    {{- range .Values.extraEnvs }}
      - {{ . | quote }}
    {{- end }}
  {{- end -}}
</code></pre>
<p>But this will override the previous settings</p>

<p>Just remove the <code>env:</code> from your bit.</p>
<pre><code>          env:
            - name: BASE_PATH
              value: /myapp/web
            {{- if .Values.extraEnvs}}
            {{- range .Values.extraEnvs }}
            - name: {{ .name }}
              value: {{ .value }}
            {{- end }}
            {{- end -}}
</code></pre>
<p>You can also use <code>toYaml</code> as mentioned in comments rather than iterating yourself.</p>
