在我下面的一些示例中,我看到,对于字符串值,我可以这样做:
{{- with .Values.cookieDomain }}
- --cookieDomain={{- toString . }}
{{- end }}
有了这个,如果我有,例如cookieDomain: .mydomain.com
在 values.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 theValues
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/