Helm tpl 渲染文件的功能不起作用

use*_*309 5 kubernetes-helm

我正在尝试使用 tpl 函数渲染文件。我正在使用 Files.Get 检索文件的内容,它工作正常,直到我对其使用 tpl 函数。

我的输入文件是:

apiVersion: autoscaling/v2beta2
Run Code Online (Sandbox Code Playgroud)

我的头盔模板是:

{{- $files := .Files }}
{{- tpl ($files.Get "files/autoscaling.yaml" ) . -}}
Run Code Online (Sandbox Code Playgroud)

我必须使用 $files 因为它会抛出错误:

at <.Files.Get>:无法评估类型接口 {} 中的字段文件

运行 helm 模板时看到的输出是

Error: template: subchart-demoapp/templates/sub-deployments.yaml:5:47: executing "subchart-demoapp/templates/sub-deployments.yaml" at <.>: wrong type for value; expected chartutil.Values; got string
helm.go:84: [debug] template: subchart-demoapp/templates/sub-deployments.yaml:5:47: executing "subchart-demoapp/templates/sub-deployments.yaml" at <.>: wrong type for value; expected chartutil.Values; got string
Run Code Online (Sandbox Code Playgroud)

我的头盔版本是:

version.BuildInfo{Version:"v3.2.1", GitCommit:"fe51cd1e31e6a202cba7dead9552a6d418ded79a", GitTreeState:"clean", GoVersion:"go1.13.10"}
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助。

use*_*309 11

弄清楚了。tpl在块中使用时,函数range需要顶级上下文作为第二个参数。参考:头盔问题

替换.$,它按预期工作。