How do the "if and (ne)" operators work in helm?

Viewed 7249

I'm working with a chart that has the following structure at the beginning but I'm having a hard time understanding when does this evaluate to true.

{{- if and .Values.vpceIngress.enabled .Values.http.paths (ne .Values.vpceIngress.class "traefik2") }}

I believe that both enabled and paths must be true, but the ne throws me off after that.

1 Answers

and and ne are functions in go templates.

and
    Returns the boolean AND of its arguments by returning the
    first empty argument or the last argument, that is,
    "and x y" behaves as "if x then y else x". All the
    arguments are evaluated.
ne
    Returns the boolean truth of arg1 != arg2

So the template line equates to a more psuedo codish

if (
  .Values.vpceIngress.enabled
  && .Values.http.paths
  && .Values.vpceIngress.class != "traefik2"
)

The truthiness of the plain .Value.key is basically a "is this field/key not the zero value for the data type. This also works for maps as 'is this field/key defined' due to a map without that path equating to nil or non value (Note that this only works when the parent map is actually defined! Otherwise the template errors)

Related