Search code examples
kuberneteskubernetes-helm

Helm template parse error - unexpected EOF


I have this template

_service.yaml

{{- define "common.service" -}}
apiVersion: v1
kind: Service
metadata:
  name: "{{ .Values.app.name }}-{{ .Values.app.environment }}-service"
spec:
  selector:
    app: "{{ .Values.app.name }}-{{ .Values.app.environment }}"
  ports:
    - protocol: TCP
      port: {{ .Values.app.listeningPort }}
      targetPort: {{ .Values.app.listeningPort }}

I get this error when I try to do helm install.

helm upgrade --install core-banking-poc-dev ./config/helm -f ./config/helm/values/dev.yaml --set-string image.tag=cb82feca --dry-run --debug
history.go:53: [debug] getting history for release core-banking-poc-dev
upgrade.go:121: [debug] preparing upgrade for core-banking-poc-dev
Error: UPGRADE FAILED: parse error at (core-banking-poc-service/charts/corebankingcommon/templates/_service.yaml:13): unexpected EOF
helm.go:81: [debug] parse error at (core-banking-poc-service/charts/corebankingcommon/templates/_service.yaml:13): unexpected EOF
UPGRADE FAILED

This works fine when I don't use the template from dependency and just have the YAML in place for service.yaml, this happens only when I export service.yaml as a template _service.yaml and pull that in another helm project.

I referred many places but still couldn't find solution.

Thanks for the help!


Solution

  • If you have are using {{ define ... }} to create a named template, you need a corresponding {{ end }}. See the documentation, which includes this example:

    For example, we can define a template to encapsulate a Kubernetes block of labels:

    {{- define "mychart.labels" }}
      labels:
        generator: helm
        date: {{ now | htmlDate }}
    {{- end }}