“ if and(ne)”运算符如何掌舵?

时间:2020-07-31 02:56:01

标签: go kubernetes kubernetes-helm

我正在使用一开始具有以下结构的图表,但是我很难理解何时将其评估为true。

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

我相信enabledpaths都必须为真,但是ne之后会让我失望。

1 个答案:

答案 0 :(得分:4)

andnego 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

因此模板行相当于更多的伪鳕鱼

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

平原.Value.key的真实性基本上是“是此字段/关键字not the zero value for the data type”。这也适用于地图,因为地图没有“等价于此字段/关键字已定义”路径设置为nil或非值(请注意,这仅在实际定义父映射时有效!否则,模板错误)

相关问题