I will try to reproduce a very strange behaviour (or my misunderstanding probably) of a helm template function which basically detects the existence of a node within values.yaml file. Actually is not so simple but it is the simplest way to show the problem:
I'm using v2.16.1 helm version, but it is reproduced on newer 3.3. Follow the next steps:
- Create an example chart
helm create myChart
- Append the function to myChart helpers
cat << EOF >> myChart/templates/_helpers.tpl {{- define "myChart.hasNodeA" -}} {{- \$found := false -}} {{- if .Values.A -}} {{- \$found := true -}} {{- end -}} {{- print \$found -}} {{- end -}} EOF
(note the dollar escapes, that's only to ease you append the function with the cat/EOF)
- Append the rendered condition within deployment:
cat << EOF >> myChart/templates/deployment.yaml {{- if eq (include "myChart.hasNodeA" .) "true" }} hasNodeA: "yes" {{- end }} {{- if eq (include "myChart.hasNodeA" .) "false" }} hasNodeA: "no" {{- end }} EOF
- Render without and with the node at values:
helm template myChart | grep hasNodeA
This shows "no", and although it is "correct", it is because the function always returns 'false'
Adding the node:
cat << EOF >> myChart/values.yaml A: whatever: 555 EOF
You will see the problem:
helm template myChart | grep hasNodeA
THIS SHOW "no" again.
The thing is that the function condition is being fulfilled, indeed, if you test this one (edit the _helpers.tpl file moving the printout to the middle):
{{- define "myChart.hasNodeA" -}} {{- $found := false -}} {{- if .Values.A -}} {{- $found := true -}} {{- print $found -}} {{- end -}} {{- end -}}
You will see that the condition is really passed:
$> helm template myChart | grep hasNodeA hasNodeA: "yes"
Obviously this does not work for negative cases. The strange thing here is that the variable configured within the condition seems to be ignored when printed at the end.
Any idea about this behaviour ? Thank U