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 .
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.