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

Simon I picture Simon I · Jul 24, 2017 · Viewed 37.1k times · Source

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?

Answer

abinet picture abinet · Jul 25, 2017

For concatenation just use printf:

{{-  $serviceNamespace := printf "%s-%s" .Values.serviceNamespace .Values.serviceTag -}}