Helm chart template evaluating expression incorrectly

2/14/2018

I am setting some properties in configmap on basis of some flags' values. To achieve this I am using "if/else" conditions in my configmap.yaml. But these "if" conditions are working fine if there is only one expression inside "if" block but for multiple expression clubbed with "or" and "and" is being evaluated incorrectly.

configmap.yaml:

{{- else if (eq .Values.A "oracle") and (eq .Values.B "true") or (eq .Values.A "postgresql") }}

The above condition is being evaluated to false however it was supposed to be evaluated as true because the last condition is true.

MYPROP1 = {{ (eq .Values.A"oracle") and (eq .Values.B "true") or (eq .Values.databaseType "postgresql") }} ==>printing false
    MYPROP2 = {{ (eq .Values.A"oracle") and (eq .Values.B "true") }} ==>printing false
    MYPROP3 = {{ (eq .Values.A"postgresql") }} ===> printing true
-- Sudhir
kubernetes
kubernetes-helm

1 Answer

2/14/2018

The expression is evaluated left to right and will exited as as soon as the and operator is evaluated as false. The or expression will never be evaluated.

You can achieve your expected behaviour when you use parenthesis:

((eq .Values.A "oracle") and (eq .Values.B "true")) or (eq .Values.A "postgresql")
-- Lukas Eichler
Source: StackOverflow