<p>I am having difficulty determining whether a portion of a rendered Helm Chart template is technically faulty and may fail me in the future. The YAML in question is accepted right now by both Helm (lint) and Kubernetes for deployments.</p>
<p><strong>Background</strong></p>
<p>As far as I know, any valid use of a multiline block-style indicator, &quot;|&quot;, in YAML should be followed by newline and then the desired content starting on the next line as so.</p>
<pre><code>foo: |
  [start content indented two spaces]
</code></pre>
<p><strong>Problem</strong></p>
<p>In my case, Helm is generating the following which appears is being accepted both by Helm linting and by Kubernetes. Note the # from my injected file <em>on the same line</em> as the &quot;|&quot;.</p>
<pre><code>  common.runtime.properties: |    #
    #
    app.flag.enabled=true
</code></pre>
<p>The template that generates the above looks like this:</p>
<pre><code>  common.runtime.properties: |
{{- .Files.Get (printf &quot;envconfig/%s/my.properties&quot; .Values.configEnvironment) | indent 4 }}
</code></pre>
<p>The file is being read in properly and does not have any special characters. To me the above should not be possible and happens no matter which version of the pipe indicator I use.</p>
<p>Is the above format actually valid? The YAML specification does not specifically address this, but all examples have a newline following the block chomping indicator |.</p>
<p>I reviewed the YAML specification and many articles I could find a topic that matched the above.</p>

Kevin Serikstad
<p><strong>The practical answer:</strong> Delete the <code>-</code> at the start of the <code>.Files.Get</code> line.</p>
<pre class="lang-yaml prettyprint-override"><code>  common.runtime.properties: |
{{ .Files.Get (printf &quot;envconfig/%s/my.properties&quot; .Values.configEnvironment) | indent 4 }}
</code></pre>
<p>That <code>-</code> removes all whitespace before the template block, including the preceding newline.  So you get the <code>|</code> YAML block-scalar indicator, then on the same line the 4 spaces added by <code>indent</code> followed by the first line of the file.</p>
<p><strong>The language-lawyer answer:</strong> This happens to work only because the first line is a comment.  If you <code>kubectl get configmap release-name -o yaml</code> I expect you'll see that first line is missing from the ConfigMap content.  It should parse as</p>
<pre class="lang-yaml prettyprint-override"><code>  common.runtime.properties: |    # a YAML comment in the Kubernetes manifest
    # a comment in the embedded file
    app.flag.enabled=true
</code></pre>
<p><a href="https://yaml.org/spec/1.2.2/#811-block-scalar-headers" rel="nofollow noreferrer">YAML 1.2.2 §8.1.1</a> has the key bit of grammar: a <code>c-b-block-header</code> contains all of the things that can appear after <code>|</code> or <code>&gt;</code> in a block scalar header.  That can contain a chomping indicator (the <code>-</code> in <code>|-</code> or <code>&gt;-</code>), an explicit indentation level, and also a <code>s-b-comment</code>.  The diagram in the spec highlights the <code>  # comment</code> as matched by the grammar production.</p>
