helm: "Unexpected unclosed action in template clause" when trying to render templated string from values.yaml
Many charts currently support Prometheus Operator by optionally adding “prometheusRule” objects to the cluster. A user can then just add the rules in his “values.yaml”. The supplied values can be templated strings and will be used by a “prometheusrule.yaml” template. This works for simple rules, but in most cases the chart will just refuse to render properly. The funny thing is, that even the example alerts that can be found in the values.yaml files of many charts are not working.
I don’t know where the problem exactly is, but it looks like something is trying to pretty print the values by inserting a “\n” at a position where it should not be and this breaks the template in most cases (see "{{ template \"test.fullname\"\n . }} in the complete error message below). I already tried all kinds of workarounds like removing whitespaces, playing with single and double quotes, yaml multiline … nothing seems to work.
values.yaml:
prometheusRule:
enabled: true
additionalLabels: {}
namespace: "monitoring"
rules:
- alert: MyTestAlert
expr: my_test_alert_with_a_long_name_kjlgnkjfdg{service="{{ template "test.fullname" . }}-mymetricsservice"} / 3600 > 1
for: 1m
labels:
severity: critical
annotations:
description: |-
The {{ template "test.fullname" . }} has a problem. The value is {{ "{{ $value }}" }}
summary: Something {{ "{{ $value }}" }}
prometheusrule.yaml:
{{- if .Values.prometheusRule.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: {{ template "test.fullname" . }}
{{- with .Values.prometheusRule.namespace }}
namespace: {{ . }}
{{- end }}
labels:
app: {{ template "test.name" . }}
chart: {{ template "test.chart" . }}
release: {{ .Release.Name | quote }}
heritage: {{ .Release.Service | quote }}
{{- with .Values.prometheusRule.additionalLabels }}
{{ toYaml . | indent 4 }}
{{- end }}
spec:
{{- with .Values.prometheusRule.rules }}
groups:
- name: {{ template "test.name" $ }}
rules: {{ tpl (toYaml .) $ | nindent 8 }}
{{- end }}
{{- end }}
Output of helm template .:
Error: template: test/templates/prometheusrule.yaml:21:16: executing "test/templates/prometheusrule.yaml" at <tpl (toYaml .) $>: error calling tpl: error during tpl function execution for "- alert: MyTestAlert\n annotations:\n description: The {{ template \"test.fullname\" . }} has a problem. The value is\n {{ \"{{ $value }}\" }}\n summary: Something {{ \"{{ $value }}\" }}\n expr: my_test_alert_with_a_long_name_kjlgnkjfdg{service=\"{{ template \"test.fullname\"\n . }}-mymetricsservice\"} / 3600 > 1\n for: 1m\n labels:\n severity: critical": parse error at (test/templates/prometheusrule.yaml:6): unexpected unclosed action in template clause
Output of helm version:
version.BuildInfo{Version:"v3.1.1",` GitCommit:"afe70585407b420d0097d07b21c47dc511525ac8", GitTreeState:"clean", GoVersion:"go1.13.8"}
Client: &version.Version{SemVer:"v2.14.1", GitCommit:"5270352a09c7e8b6e8c9593002a73535276507c0", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.14.1", GitCommit:"5270352a09c7e8b6e8c9593002a73535276507c0", GitTreeState:"clean"}
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 24 (3 by maintainers)
Well, the linebreak is the main problem. See also https://github.com/go-yaml/yaml/issues/166. Under normal circumstances the linebreak “should” not have an impact, because it is valid yaml in any case. Unfortunately this does not take into account that certain strings (see https://godoc.org/text/template) cannot be split.
However. When using something like this … values.yaml:
templates/test.yaml:
The error message is:
It’s a different error message, but the underlying problem is the same.
As a workaround I am currently using yaml literal style for all templated strings. At least in my case it works as expected:
@adasari : Did you try the workaround by changing your values to yaml literals?
The expression is too long. Unfortunately Helm splits the line and this breaks the Go template. Use yaml literal style for templated strings like:
can this issue reopened again? it is not fixed yet.
This issue has been marked as stale because it has been open for 90 days with no activity. This thread will be automatically closed in 30 days if no further activity occurs.
Yes. This is the problematic piece. Everything else renders fine. The “bad linebreak” is inserted as soon as the line is longer than 70-80 characters.
-------- Ursprüngliche Nachricht -------- Von: Josh Dolitsky notifications@github.com Datum: 28.02.2020 21:24 (GMT+01:00) An: helm/helm helm@noreply.github.com Cc: David Heinrich David.Heinrich@cortado.com, Author author@noreply.github.com Betreff: Re: [helm/helm] “Unexpected unclosed action in template clause” when trying to render templated string from values.yaml (#7704)
The issues is certainly with the line rules: {{ tpl (toYaml .) $ | nindent 8 }}
in prometheusrule.yaml Could you try removing the expr: field and see if you still get this error? I suspect thats the piece causing the error, and would be helpful to isolate it. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.