4

I am having trouble accessing some named templates defined in the main chart from subcharts. As it is in the documentation that every defined named template is global, I'd like to get help on what I am doing wrong here.

Below is the defined named template in _helper.tpl of the main chart and I am trying to access it in the configMap from the subchart which is resulting into an error of no template.

_helper.tpl inside chart/templates

{{- define "main.postgres"}}
    POSTGRES_URL: 172.30.30.39
    POSTGRES_PORT: 5432
{{- end }}

configMap.yaml inside chart/subchart/templates

apiVerions: v1
kind: ConfigMap
metadata: 
  name: subchart-config
  data:
    {{- template "main.postgres" .}}

Error

error calling include: template: no template "main.postgres" associated with template "gotpl"

1
  • did you try adding .tpl to the end of your template tpl? So it's "main.postgres.tpl?" Also looking back at some I made I found that I added code at the bottom of all my files. So I define the tpl at the top level and the bottom have the following. {{- define "main.postgres" -}} {{- include "main.postgres.util.merge" (append . "main.postgres.tpl") -}} {{- end -}} Commented Jul 2, 2021 at 3:47

2 Answers 2

1

I found the issue in your helm templates.

The charts directory inside the helm chart must be charts, not chart. I tried to simulate your issue and am able to fix it now.

I refactored the directory structure like below

.
├── Chart.yaml
├── charts
│   └── subchart
│       ├── Chart.yaml
│       ├── charts
│       ├── templates
│       │   └── configMap.yaml
│       └── values.yaml
├── templates
│   └── _helper.tpl
└── values.yaml

I used your _helper.tpl file as it is.

{{- define "main.postgres"}}
    POSTGRES_URL: 172.30.30.39
    POSTGRES_PORT: 5432
{{- end }}

when I am running helm template . command, so I am getting the proper results to hope you expected.

helm template .
---
# Source: test/charts/subchart/templates/configMap.yaml
apiVerions: v1
kind: ConfigMap
metadata: 
  name: subchart-config
  data:
    POSTGRES_URL: 172.30.30.39
    POSTGRES_PORT: 5432
0

I had the same problem. I double checked my folder structure. Instead of templates I named my folder template.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.