Sometimes helm template
error output isn't very helpful. Here are some error cases and solutions I've found in my own Helm usage.
Using printf with a variable that is a formatter string
Usage of the variable needs to be quoted, even if the values.yaml value was quoted
component:
formatString: "web-%s-%s"
{{ $name := printf (quote $formatString) $field1 $field2}}
Put quotes around numbers, especially if in Java properties
Large numbers seem to get outputted as scientific notation sometimes. This also seems to be an open Github Issue with Helm
# values.yaml:
perInterval: 5000000 # <-- quotes needed around this int
# template:
stream.properties: |
perInterval={{ $perInterval | default 1 }}
# output:
stream.properties: |
perInterval=5e+06
"Expected map .. but was nil" errors / you commented stuff out
This usually happens when you're using a values override file, eg. you have a values.yaml
in chart root and are using something like helm template --values child_values.yaml
webservices:
resources:
limits:
cpu: ..
memory: ..
requests: ..
replicas: ...
component2:
...
If you've commented a whole "map" block like this out in some child values, Helm will think webservices == nil
webservices:
# resources: ..
component2:
However, in a map that is defined in the parent values.yaml
, you can redefine some key-value-pairs and leave out the others, and the missing key-value-pairs will get filled in as expected:
webservices:
resources:
requests: ..
# "limits" key will still be readable at webservices.resources.limit
component2:
{{- -}}
dash/hyphen usage when removing extra newlines / chomping whitepsace
The helm doc section is really verbose about this. The tl;dr is that you typically only need one -
character that goes on the left side:
name: ws-deploy
{{- if .biggerDeploy }}
replicas: 20
{{- end}}
label: ..
If biggerDeploy
is true:
name: ws-deploy
replicas: 20
label: ..
If biggerDeploy
is false:
name: ws-deploy
label: ..