Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Helm tpl function to render a file does not work

I am trying to render a file using the tpl function. I am retrieving the content of the file using Files.Get, which works fine until I use tpl function on it.

My input file is:

apiVersion: autoscaling/v2beta2

My helm template is:

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

I had to use $files because it would throw the error:

at <.Files.Get>: can't evaluate field Files in type interface {}

The output that I see when I run the helm template is

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

My helm version is:

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

Thanks for any help.

like image 226
nerdy_darkknight Avatar asked Sep 01 '26 20:09

nerdy_darkknight


1 Answers

Figured it out. tpl function when used in a range block needs the top-level context as the second argument. Ref: Helm Issue

Replaced the . with $ and it works as expected.

like image 88
nerdy_darkknight Avatar answered Sep 05 '26 16:09

nerdy_darkknight