Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes Helm, combine two variables with a string in the middle

I’m trying to change the value of a variable if another variable it set by combining the two with a dash in the middle, I’m not sure of the syntax to do this, I’m thinking of somethings like:

{{- $serviceNamespace := .Values.serviceNamespace -}} {{- $serviceTag := .Values.serviceTag -}} {{- if $serviceTag}} {{- $serviceNamespace := .Values.serviceNamespace  "-" .Values.serviceTag -}} {{- end}} 

Is this correct? if serviceNamespace was hello and serviceTag was 1.0.0 would I end up with serviceNamespace being hello-1.0.0?

like image 590
Simon I Avatar asked Jul 24 '17 10:07

Simon I


2 Answers

For concatenation just use printf:

{{-  $serviceNamespace := printf "%s-%s" .Values.serviceNamespace .Values.serviceTag -}} 
like image 192
abinet Avatar answered Oct 07 '22 12:10

abinet


You can simply do it like this , with string ":" in middle

"{{ $values.image.repository }}:{{ $values.image.tag }}" 
like image 41
Gabriel Wu Avatar answered Oct 07 '22 12:10

Gabriel Wu