<p>I want to mount a shell script template into a container.</p>

<p>I have the following <code>configmap.yaml</code>:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "myservice-chart.fullname" . }}--scripts-configmap
  labels:
    app: {{ template "myservice-chart.name" . }}
    chart: {{ template "myservice-chart.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
data:
  setup: |
    {{ include "setup" . | indent 4 }}
</code></pre>

<p>And this is my <code>setup.tpl</code>:</p>

<pre><code>{{- define "setup" }}
#!/bin/bash
echo "Hello world!"
{{- end }}
</code></pre>

<p>When I do a Helm dry-run, Helm generates this (valid) YAML:</p>

<pre><code>...
apiVersion: v1
kind: ConfigMap
metadata:
  name: listening-donkey-myservice-chart-quorum-scripts-configmap
  labels:
    app: myservice-chart
    chart: myservice-chart-0.1.0
    release: listening-donkey
    heritage: Tiller
data:
  setup: |

    #!/bin/bash
    echo "Hello world!"
...
</code></pre>

<p>When I run it without <code>--dry-run</code>, it generates this error:</p>

<blockquote>
  <p>configmap.yaml: error converting YAML to JSON: yaml: line 13: did not
  find expected key</p>
</blockquote>

mitchkman
<p>According to <a href="https://docs.helm.sh/chart_template_guide/" rel="noreferrer">helm chart template guide</a>:</p>

<blockquote>
  <p>The curly brace syntax of template declarations can be modified with
  special characters to tell the template engine to chomp whitespace.
  {{- (with the dash and space added) indicates that whitespace should
  be chomped left, while -}} means whitespace to the right should be
  consumed. Be careful! Newlines are whitespace!</p>
</blockquote>

<p>So, in order to prevent an useless empty line below <code>setup: |</code> the  <code>configmap.yaml</code> should be the following:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "myservice-chart.fullname" . }}--scripts-configmap
  labels:
    app: {{ template "myservice-chart.name" . }}
    chart: {{ template "myservice-chart.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
data:
  setup: |
    {{- include "setup" . | indent 4 }}
</code></pre>
