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"

Glorfindel
  • 169
  • 1
  • 2
  • 12
William
  • 41
  • 1
  • 1
  • 2

2 Answers2

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
Arvind Rawat
  • 161
  • 4
0

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