Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes use {{ include xx }} inside values.yaml

I'm refactoring a helm chart, and wanted to put some values from deployment.yaml to values.yaml and that value is

hosts:
  - {{ include "myApp.externalHostName" . | quote }}

but it gives me the error

[ERROR] values.yaml: unable to parse YAML: error converting YAML to
 JSON: yaml: invalid map key: map[interface {}]interface {}{"toJson
 include \"myApp.externalHostName\" . | quote":interface {}(nil)}

[ERROR] templates/: cannot load values.yaml: error converting YAML to
 JSON: yaml: invalid map key: map[interface {}]interface {}{"toJson
 include \"myApp.externalHostName\" . | quote":interface {}(nil)}

it would work if I just used

hosts:
  - myExternalHostname.something

but is it possible to run include in values.yaml?

like image 618
CptDolphin Avatar asked Nov 27 '25 07:11

CptDolphin


1 Answers

The values.yaml files are not subject to golang interpolation. If you need dynamic content, you'll need to update files inside the templates directory (which are subject to golang interpolation), or generate the values.yaml content using another mechanism

In this specific case, you may find yaml anchors to be helpful:

myApp:
  externalHostName: &externalHostName myapp.example.com

theIngressOrWhatever:
  hosts:
  - *externalHostName
like image 85
mdaniel Avatar answered Nov 29 '25 18:11

mdaniel