“if and (ne)”操作符如何掌舵?

mot*_*ess 2 go kubernetes kubernetes-helm

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

{{- if and .Values.vpceIngress.enabled .Values.http.paths (ne .Values.vpceIngress.class "traefik2") }}
Run Code Online (Sandbox Code Playgroud)

我相信无论是enabledpaths必须是真实的,但ne之后抛出我送行。

Mat*_*att 5

andnego 模板中的函数。

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.
Run Code Online (Sandbox Code Playgroud)
ne
    Returns the boolean truth of arg1 != arg2
Run Code Online (Sandbox Code Playgroud)

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

if (
  .Values.vpceIngress.enabled
  && .Values.http.paths
  && .Values.vpceIngress.class != "traefik2"
)
Run Code Online (Sandbox Code Playgroud)

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