我可以在 Helm yamls 中做这样的事情吗:
{{- if eq .Values.isCar true }} OR {{- if eq .Values.isBus true }}
# do something
{{- end }}
我知道我们可以做一个 if 检查。但是我将如何检查多个条件?是否有一些与 OR 和 AND 等效的运算符?
最佳答案
如 Helm documentation on operators 所示:
For templates, the operators (
eq
,ne
,lt
,gt
,and
,or
and so on) are all implemented as functions. In pipelines, operations can be grouped with parentheses ((
, and)
).
这意味着你可以使用
{{- if or (eq .Values.isCar true) (eq .Values.isBus true) }}
此外,如 if/else structure 中所述:A pipeline is evaluated as false if the value is:
- a boolean false
- a numeric zero
- an empty string
- a nil (empty or null)
- an empty collection (map, slice, tuple, dict, array)
Under all other conditions, the condition is true.
如果您的属性(
isCar
和 isBus
)是 bool 值,则可以跳过相等检查:{{- if or .Values.isCar .Values.isBus }}
关于kubernetes-helm - 我们可以在 Helm yaml 文件中使用 OR 运算符吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49789867/