When you nest values in yaml like
server:
spec:
cpu: 0.5
You use it in helm as {{ .Values.server.spec.cpu | default 0.5 }}
, which works fine till you try the values as not defined
e.g
server:
Now {{ .Values.server.spec.cpu | default 0.5 }}
will cause the template code to panic with a nil exception.
Ultimately the Helm templates are Golang templates and this is just how it works. There is no ?.
operator.
The best and strangest undocumented solution is to wrap each level of nesting in (
, )
.
e.g.
{{ (((.Values.server).spec).cpu) | default 0.5 }}
This will not panic and you will get the expected behaviour.