【问题标题】:Helm tpl function to render a file does not work渲染文件的 Helm tpl 函数不起作用
【发布时间】:2021-06-03 04:09:05
【问题描述】:

我正在尝试使用 tpl 函数呈现文件。我正在使用 Files.Get 检索文件的内容,在我对其使用 tpl 函数之前它工作正常。

我的输入文件是:

apiVersion: autoscaling/v2beta2

我的 helm 模板是:

{{- $files := .Files }}
{{- tpl ($files.Get "files/autoscaling.yaml" ) . -}}

我不得不使用 $files 因为它会抛出错误:

在 <.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

我的掌舵版本是:

version.BuildInfo{Version:"v3.2.1", GitCommit:"fe51cd1e31e6a202cba7dead9552a6d418ded79a", GitTreeState:"clean", GoVersion:"go1.13.10"}

感谢您的帮助。

【问题讨论】:

    标签: kubernetes-helm helmfile


    【解决方案1】:

    想通了。 tpl 函数在 range 块中使用时需要顶级上下文作为第二个参数。参考:Helm Issue

    将. 替换为$ 并按预期工作。

    【讨论】:

      猜你喜欢
      • 2020-05-22
      • 2018-02-24
      • 2020-09-11
      • 1970-01-01
      • 2022-09-27
      • 1970-01-01
      • 2019-06-17
      • 2011-03-15
      • 2015-01-09
      相关资源
      最近更新 更多