Helm template: How raise exception in in helm function?

4/29/2020

In helm templating, I want to raise an error if the condition is not matched.

Code:

{{- if eq .Values.key "desiredValue" }}
{{- .Value.key }}
{{- else }}
{{- raise "value for .Values.key is not as expected" }}
{{- end }}

Where :

raise: is a function which will fail the helm possess and will display error value for .Values.key is not as expected.

How to achieve the functionality of raise as illustrated in code above in helm templating?

One way to achieve this is:

{{- if eq .Values.key "desiredValue" }}
{{- .Value.key }}
{{- else }}
{{- required "value for .Values.key is not as expected" "" }}
{{- end }}

But I want to know if there are any other elegant way of doing it.

-- mad_boy
kubernetes-helm
yaml

1 Answer

4/29/2020

The Sprig support library includes a fail function that has the same semantics as your proposed raise.

{{- if ne .Values.key "desiredValue" }}
{{- fail "value for .Values.key is not as expected" }}
{{- end }}
-- David Maze
Source: StackOverflow