Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Helm string variable - Is it possible to replace a placeholder in a string variable with another helm variable value?

I have a helm chart which has a CRD yaml as follows

.......
.......
arguments:
   parameters:
     - name: {{ .Values.workflow_template_command_name }}
       value: "echo '{{ .Values.notebook_details }}'| jq .run_id > /tmp/info.txt"
.......
.......

The string variable notebook_details in values.yaml has a placeholder which I would like to replace with another variable defined in values.yaml.

something like this?

value: "echo '{{ .Values.notebook_details |replace 'PLACEHOLDER' .Values.text }}'| jq .run_id > /tmp/info.txt"

Is it possible? if so, whats the right syntax?

like image 587
saranya elumalai Avatar asked Mar 14 '26 10:03

saranya elumalai


1 Answers

The Helm documentation includes a Template Function List; if you look at the list of string functions, there is a replace function.

If you want to take the string from .Values.notebook_details, and replace the string literal PLACEHOLDER with the value in .Values.text, the template syntax is almost exactly what you have, but with double quotes around the string literal (it doesn't matter that it's in a double-quoted YAML string):

value: "echo '{{ .Values.notebook_details | replace "PLACEHOLDER" .Values.text }}' | jq ..."

Another approach to consider is to allow Helm templating in the value itself. Documented elsewhere is the Helm tpl template function which will evaluate a string as a template

value: "echo '{{ tpl .Values.notebook_details . }}' | jq ..."
# values.yaml
notebook_details: The text is {{ .Values.text }}.
text: replaced by the `tpl` function
like image 181
David Maze Avatar answered Mar 16 '26 15:03

David Maze



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!