在Helm Go模板中使用has

问题描述 投票:0回答:1

values.yaml

{{if (has 1 .Values.xs)}}
a: 42
{{ else }}
b: 1
c: 2
{{ end }}

模板.yaml

xs:
  - 1
  - 2
  - 3

我得到的输出为

b: 1
c: 2

如何修复 it 以便获得

a: 42
的输出,因为
1
位于
[1,2,3]
中?

go-templates helm3
1个回答
0
投票

这是由于类型不匹配造成的。

{{ kindOf (first .Values.xs) }}
返回
float64
,而
{{ kindOf (1) }}
返回
int

另一种方法是使用

float64
,通过写
1.0
,或者你可以投射它:

{{ if has (float64 1) .Values.xs }}
© www.soinside.com 2019 - 2024. All rights reserved.