我希望我的Helm图表使用不同的映像存储库,这取决于云提供商(AWSvs.Aliyun),不幸的是,在尝试运行helm package命令时,我得到了以下错误:
Error: cannot load values.yaml: error converting YAML to JSON: yaml: invalid map key: map[interface {}]interface {}{"tpl (.Files.Get \"config/repository.config\") . | quote":interface {}(nil)}在我的values.yaml中有:
configuration:
system:
mode:
cloud_provider: aws
image:
repository: {{ tpl (.Files.Get "config/repository.config") . | quote }}在我的config/repository.config文件中有:
{{- if eq ( include "cloud_provider" . | trim ) "aliyun" -}}
registry.cn-qingdao.aliyuncs.com/x/kube-state-metrics
{{- end -}}
{{- if eq ( include "cloud_provider" . | trim ) "aws" -}}
k8s.gcr.io/kube-state-metrics/kube-state-metrics
{{- end -}}在templates/_helpers.tpl文件中,我添加了:
{{- define "cloud_provider" -}}
{{ required "Cloud provider required at .Values.configuration.system.mode.cloud_provider due to Google to unreachable in China" .Values.configuration.system.mode.cloud_provider }}
{{ $valid_cloud_provider := list "aws" "aliyun" }}
{{- if not (has .Values.configuration.system.mode.cloud_provider $valid_cloud_provider ) -}}
{{ fail "Invalid cloud provider set. Should be aws or aliyun" }}
{{end}}
{{- else -}}
{{ .Values.configuration.system.mode.cloud_provider | default "disabled" }}
{{- end -}}
{{- end -}}发布于 2022-06-06 20:24:33
这不是对错误的直接解决方案,而是一种替代方法。我希望这也能帮助到:
我不会将这样的表达式放在值文件values.yaml中
repository: {{ tpl (.Files.Get "config/repository.config") . | quote }}我会对每个环境使用不同的yaml文件:
添加aliyun.yaml值文件
registry: registry.cn-qingdao.aliyuncs.com/x/kube-state-metrics并使用此值文件调用helm。
helm ... -f aliyun.yamlhttps://stackoverflow.com/questions/72519236
复制相似问题