Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to set values at runtime using Named templates in helm chart?

I created a simple helm chart using helm create nginx-test and it worked successfully

Is it possible to set the values service.port at run-time by calling a template function as mentioned below

helm install --set service.port="{{ include changePortNo . }}" nginx-test .

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The named template changePortNo was defined in _helpers.tpl

>Solution :

You can’t invoke Helm templates at that level. In the command line you’re showing, the --set=... argument will be processed by the shell, and so you can use things like environment variables and shell functions, but you can’t directly invoke Helm code.

I suspect you’re trying to set this here because the helm create template has this as a parameter. If I were writing a chart from scratch, the port number of the Service wouldn’t be something I’d customize. You can change the templates/service.yml to call your function directly

spec:
  ports:
    - port: {{ include "changePortNo" . }}
            {{/* not .Values.service.port */}}

In principle it would be possible to use the tpl function to allow passing a template string in the way you show. This still would involve changing the service.yml to use tpl, in the same place.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading