Search code examples
kubernetes-helm

Helm Subcharts values with Named Template getting null


Using helm version 3.7.2.

I've tried many ways to implement named template to cover many cases, for example: I have an umbrella chart structure that contains other subchart. I want to have the ability to define a named template in subchart #1 and include it in other named template in subchart #2.

I have tried many things to accomplish that, the way I found that works well is: (simple example)

I have tried many things to accomplish that, the way I found that works well is: (simple example)

in subchart #1: {{- define "subchart1.ports" -}} 5678 {{- end -}}

in subchart #2: ... port: {{ include "subchart1.ports" .Subcharts.subchart1Name }} ...

and it worked! I've read the keyword ".Subcharts" can exposed scopes between subcharts... I know between parent chart and subchart there's another ways, but I am talking about implementing this between subchats.

The problem is when I am doing the same thing but just mention a value.. case:

in subchart #1: {{- define "subchart1.ports" -}} {{ .Values.service.port }} {{- end -}}

in subchart #2: ... port: {{ include "subchart1.ports" .Subcharts.subchart1Name }} ...

In any other "regular" named template let's say define and include at the same chart, I do not have this issue and I get the content of the value. I have made sure that this value is set and I even see it thru helm template command... but in the situation I have described, with using .Subchart and share it between subcharts I do not get the content of the value... I get null (when I pipe it toYaml..).

If there is a better way to achieve it, I'll be glad to hear or any insight about my case.

Thank you!


Solution

  • After deep checking, as far as I know and see at the source code, the capability of using the .Subcharts is between sub-charts in an umbrella and not between the sub-charts to the root/main/global chart that holds the umbrella. It’s also relevant to tpl files and templating, there no way to point from a template to higher lever as long as it’s not between the sub-charts.