<p>I'm trying to add ingress to my nginx container.</p>
<p>The following ingress template gives me &quot;parse error (&lt;&gt;/ingress.yaml:71: unexpected EOF)&quot;. I went through trying mark possible missing end statements, but even adding arbitrary end at the end of file didn't fix it. I am out of ideas as to what causes this EOF.</p>
<p>So the question is the general: What causes &quot;unexpected EOF&quot; in the file?</p>
<pre class="lang-yaml prettyprint-override"><code>{{- if .Values.web.ingress.enabled }}

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: {{ .Release.Name }}-proxy-ingress
  labels:
    tier: intelowl
    component: proxy
    release: {{ .Release.Name }}
    chart: {{ .Chart.Name }}
    heritage: {{ .Release.Service }}
{{- with .Values.labels }}
{{ toYaml . | indent 4 }}
{{- end }} # {{- with .Values.labels }}

{{- if .Values.web.ingress.annotations }}
  annotations:
{{- with .Values.web.ingress.annotations }}
{{ toYaml . | indent 4 }}
{{- end }} # {{- with .Values.web.ingress.annotations }}
{{- end }} # {{- if .Values.web.ingress.annotations }}

spec:

{{- if .Values.web.ingress.tls.enabled }}
  tls:
    - hosts:
        - {{ .Values.web.ingress.host }}
      secretName: {{ .Values.web.ingress.tls.secretName }}
{{- end }} # {{- if .Values.web.ingress.tls.enabled }}

  rules:
    - http:
        paths:
{{- range .Values.web.ingress.precedingPaths }}
          - path: {{ .path }}
            backend:
              service:
                name: {{ .serviceName }}
                port: 
                  number: {{ .servicePort }}
{{- end }} # {{- range .Values.web.ingress.precedingPaths }}

          - backend:
              service:
                name: {{ .Release.Name }}-proxy
                port: 
                  number: {{ ternary 443 80 .Values.web.ingress.tls.enabled }}
{{- if .Values.web.ingress.path }}
            path: {{ .Values.web.ingress.path }}
{{- end }} # {{- if .Values.web.ingress.path }}

{{- range .Values.web.ingress.succeedingPaths }}
          - path: {{ .path }}
            backend:
              service:
                name: {{ .serviceName }}
                port: 
                  number: {{ .servicePort }}
{{- end }} # {{- range .Values.web.ingress.succeedingPaths }}

{{- if .Values.web.ingress.host }}
      host: {{ .Values.web.ingress.host }}
{{- end }} # {{- if .Values.web.ingress.host }}

{{- end }} # {{- if .Values.web.ingress.enabled }}

</code></pre>

Zerg Overmind
<p>Your file is generally structured like so:</p>
<pre class="lang-none prettyprint-override"><code>{{- if .Values.someCondition }}
...
{{- end }} # {{- if .Values.someCondition }}
</code></pre>
<p>However, the Go <code>text/template</code> engine runs before any YAML parsing happens.  There is <em>not</em> a comment in this example; there is an <code>if</code> statement, the matching <code>end</code>, and an unterminated <code>if</code>.</p>
<p>The <code>text/template</code> language has its own <code>{{/* comment */}}</code> syntax, and in principle you could use this</p>
<pre class="lang-none prettyprint-override"><code>{{- if .Values.someCondition }}
...
{{- end }}{{/* if .Values.someCondition */}}
</code></pre>
<p>Beyond this, the file you show seems to have the right number of <code>{{ end }}</code>s.</p>
<p>I'd probably avoid this style myself.  Usually these condition blocks are fairly short; you could break the template into multiple <code>define</code> named templates if that helps.</p>
<pre class="lang-yaml prettyprint-override"><code>metadata:
  labels:
    tier: intelowl
    et: cetera
{{- include &quot;more-labels&quot; . | indent 4 }}
{{- include &quot;ingress-annotations&quot; . | indent 2 }}

{{- define &quot;more-labels&quot; -}}
{{ with .Values.labels }}{{ toYaml . }}{{ end }}
{{- end -}}

{{- define &quot;ingress-annotations&quot; -}}
{{- with .Values.web.ingress.annotations }}
annotations:
{{ toYaml . | indent 2 }}
{{- end -}}
{{- end -}}
</code></pre>
<p>Especially for labels you might find that some of the values will be reused in all of your objects, and so including a template in the <code>_helpers.tpl</code> file to produce the common values will reduce some of the repetitiveness.</p>
