kubernetes-helm - 我们可以在 Helm yaml 文件中使用 OR 运算符吗

标签 kubernetes-helm

我可以在 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.


如果您的属性( isCarisBus )是 bool 值,则可以跳过相等检查:
{{- if or .Values.isCar .Values.isBus }}

关于kubernetes-helm - 我们可以在 Helm yaml 文件中使用 OR 运算符吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49789867/

相关文章:

kubernetes - 如何在 Kubernetes 中的 nginx 和 php-fpm 容器之间正确共享应用程序文件夹?

nginx - 让我们加密发布假证书的kubernetes Ingress Controller

kubernetes - Helm 升级不会拉新容器

kubernetes - 没有找到匹配的 Helm 切片

kubernetes - Promtail 基本身份验证在 helm values.yaml 中使用 kubernetes secret

docker - 从Docker容器使用默认 namespace 中的群集IP访问k8s服务

kubernetes - 无法为入口后面的入口设置安全连接-错误的网关

azure-pipelines-release-pipeline - 使用kubeconfig内联的Helm命令

kubernetes - Helm似乎根据我是否使用--dry-run --debug来解析我的图表不同。

.net - 使用Helm安装时如何配置nginx?