gpt4 book ai didi

kubernetes-helm - 如何从 values.yaml 替换 bool 值

转载 作者:行者123 更新时间:2023-12-05 05:40:15 25 4
gpt4 key购买 nike

在我下面的一些示例中,我看到,对于字符串值,我可以这样做:

{{- with .Values.cookieDomain }}
- --cookieDomain={{- toString . }}
{{- end }}

有了这个,如果我有,例如cookieDomain: .mydomain.comvalues.yaml 中,模板获取正确的值。

bool 值如何做相同/相似?
例如,如果我在 values.yaml 中有这个:proxyPass: true,我该如何在模板中解释它,因为没有 toBool功能。

最佳答案

函数toString ,在您的示例中,如果 cookieDoman 中包含的值实际上没有实际意义已经是一个字符串,它什么都不做。

with .Values.cookieDoman中你必须了解的内容是上下文现在已经从.改变了作为变量定义的根成为 .Values.cookieDoman .

有点像在计算机中更改目录,如果我 cd /tmp , 然后 ./some_file/tmp/some_file 中查找文件.现在如果我 cd /etc ,相同的命令,./some_file , 现在将查找文件 /etc/some_file .

This controls variable scoping. Recall that . is a reference to the current scope. So .Values tells the template to find the Values object in the current scope.

来源:https://helm.sh/docs/chart_template_guide/control_structures/#modifying-scope-using-with

所以,在你的例子中,已经足够好了

flags:
{{- with .Values.cookieDomain }}
- --cookieDomain={{- . }}
{{- end }}

这将呈现在

flags:
- --cookieDomain=.mydomain.com

因此,如果你有一个 bool 值,它是完全一样的:

flags:
{{- with .Values.proxyPass }}
- --proxyPass={{- . }}
{{- end }}

将给予:

flags:
- --proxyPass=true

关于kubernetes-helm - 如何从 values.yaml 替换 bool 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72445325/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com