检查列表是否包含 Helm 图表中的项目
check if list contains item in Helm chart
如果某个值在值列表中,我想部署一个图表。
我试过以下方法
{{if .Release.Namespace in .Values.Namespaces }}
<chart goes here>
{{ end }}
其中使用的值文件包含以下内容
Namespaces:
-value1
-value2
但是我得到一个错误function "in" not defined
搜索互联网我一直无法找到正确的语法来检查 helm 中的列表中是否存在值。
可以使用has
function from the sprig functions library which is used by Helm. Please note however that there's an issue with the documentation of the function(参数顺序错误)。在你的情况下应该是这样的:
{{if has .Release.Namespace .Values.Namespaces }}
<chart goes here>
{{ end }}
如果某个值在值列表中,我想部署一个图表。 我试过以下方法
{{if .Release.Namespace in .Values.Namespaces }}
<chart goes here>
{{ end }}
其中使用的值文件包含以下内容
Namespaces:
-value1
-value2
但是我得到一个错误function "in" not defined
搜索互联网我一直无法找到正确的语法来检查 helm 中的列表中是否存在值。
可以使用has
function from the sprig functions library which is used by Helm. Please note however that there's an issue with the documentation of the function(参数顺序错误)。在你的情况下应该是这样的:
{{if has .Release.Namespace .Values.Namespaces }}
<chart goes here>
{{ end }}