<p>What I'm trying to achieve is to set an array of values into the hosts field in my ingress chart similar to:</p>
<pre><code>spec:
  tls:
    hosts:
      - domain1
      - domain2
      - domain3
</code></pre>
<p>The problem I'm facing is that I have a default domain (domain1) and an array of extra domains (domain2, domain3) which is not of a fixed length.</p>
<p>What I tried was to iterate through the array along the default value</p>
<pre><code>- hosts:
  - {{.Values.domain}}
  {{- range $key, $val := .Values.regionalDomain }}
    - {{ $val }}
  {{- end }}
</code></pre>
<p>But I get errors similar to: <code>spec.tls[0].hosts: Invalid value: &quot;domain1 - domain2 - domain3&quot;: a DNS-1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')</code></p>

Timotei Manolache
<p>YAML is very whitespace-sensitive, and the interaction with the Helm/Go templating can be a little tricky.  It looks like there are two extra spaces on the items inside the <code>range</code> loop, so you should be able to change:</p>
<pre class="lang-yaml prettyprint-override"><code>- hosts:
  - {{.Values.domain}}
  {{- range $key, $val := .Values.regionalDomain }}
  {{/* The - lines up with the above -- two fewer indent spaces */}}
  - {{ $val }}
  {{- end }}
</code></pre>
<p>The templating isn't really aware of YAML syntax, and treats spaces very literally.  The <code>{{- ...</code> with a hyphen inside the braces will delete all whitespace, both newlines and spaces, on one side or the other of a template, and reasoning about this can involve consciously counting the newlines.  (There is not a newline immediately after the default domain, but there is a newline before every item inside the <code>range</code> loop and after its <code>end</code>, which is the correct number of newlines.)</p>
<p>If you're getting a YAML parse error, it can be useful to run <code>helm template</code> with your set of values, find the item in question, and make sure the generated YAML actually looks correct (there isn't a missing newline, the indentation lines up).</p>
