首页 > 解决方案 > “if and (ne)”运算符在 helm 中是如何工作的?

问题描述

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

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

我相信两者都是enabled真实paths的,但ne在那之后让我失望了。

标签: gokuberneteskubernetes-helm

解决方案


and并且nego 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

所以模板行相当于一个更伪的 codish

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

纯文本的真实性.Value.key基本上是“此字段/键不是数据类型的零值。这也适用于映射,因为“此字段/键是否已定义”,因为映射没有该路径等于 nil 或非值(请注意,这仅在实际定义父地图时才有效!否则模板错误)


推荐阅读