When would you use `fail`?
IntermediateConceptTemplating: Go Templates & Sprig
Answer
To reject invalid combinations that a single required cannot express:
{{- if and .Values.autoscaling.enabled .Values.api.replicaCount }}
{{- if gt (int .Values.api.replicaCount) (int .Values.autoscaling.maxReplicas) }}
{{- fail "api.replicaCount cannot exceed autoscaling.maxReplicas" }}
{{- end }}
{{- end }}
{{- if and (eq .Values.env "prod") (not .Values.postgres.persistence.enabled) }}
{{- fail "persistence must be enabled in prod" }}
{{- end }}
Put such validations in a _validate.tpl helper included from one template so they run once.
More on Templating: Go Templates & Sprig
What template language does Helm use?BeginnerWhat does the dot (`.`) mean in a Helm template?BeginnerWhat is `$` and when do you need it?IntermediateHow does whitespace control (`{{-` and `-}}`) work?BeginnerHow do `if`, `else if` and `else` evaluate truthiness?BeginnerWhat do `and`, `or`, `not`, `eq`, `ne`, `lt`, `gt` look like in Helm?Beginner