我正在尝试合并具有机密数组的多个值文件。但是合并不起作用,而是最后一个值文件被覆盖。这是我的秘密模板
---
{{- range .Values.secrets }}
---
apiVersion: v1
kind: Secret
metadata:
name: {{ required "a valid name is required" .name }}
namespace: ""
type: Opaque
data:
{{- range $key, $val := .data }}
# fix printing the key name in the required string
{{ $key }}: {{ required "a valid key is required" $val }}
{{- end }}
{{- end }}
value1.yaml:
secrets:
- name: "sample"
data:
test: "YXBpa2V5MQo="
value2.yaml:
- name: "sample2"
data:
test: "YXBpa2V5MQo="
helm template secrets-template -f value1.yaml -f value2.yaml
输出为
---
apiVersion: v1
kind: Secret
metadata:
name: sample2
namespace: ""
type: Opaque
data:
# fix printing the key name in the required string
test: YXBpa2V5MQo=
但是预期的输出是
---
apiVersion: v1
kind: Secret
metadata:
name: sample
namespace: ""
type: Opaque
data:
# fix printing the key name in the required string
test: YXBpa2V5MQo=
---
apiVersion: v1
kind: Secret
metadata:
name: sample2
namespace: ""
type: Opaque
data:
# fix printing the key name in the required string
test: YXBpa2V5MQo=
对此有任何帮助吗?
据我所知,头盔始终会覆盖数组。解决方法是使用字典。例如,使用机密名称作为密钥。
模板:
---
{{- range $secretName, $secretValue := .Values.secrets }}
---
apiVersion: v1
kind: Secret
metadata:
name: {{ required "a valid name is required" $secretName }}
namespace: ""
type: Opaque
data:
{{- range $key, $val := $secretValue }}
# fix printing the key name in the required string
{{ $key }}: {{ required "a valid key is required" $val }}
{{- end }}
{{- end }}
value1.yaml
secrets:
sample:
test: "YXBpa2V5MQo="
value2.yaml
secrets:
sample2:
test: "YXBpa2V5MQo="
谢谢。它的工作原理。我做了一个小修改。
{{- range $secretName,$secretValue := .Values.secrets }}
---
apiVersion: v1
kind: Secret
metadata:
name: {{ required "a valid name is required" $secretName }}
type: {{ $secretValue.type | default "Opaque" }}
data:
{{- range $key, $val := $secretValue.data }}
# fix printing the key name in the required string
{{ $key }}: {{ required "a valid key is required" $val }}
{{- end }}
{{- end }}
值文件:
secrets:
sample2:
data:
test2: "YXBpa2V5MQo="
但是尽管它可以正常工作,但我仍处于警告之下。这是问题吗?如何解决此警告?
coalesce.go:160: warning: skipped value for secrets: Not a table.