Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

go-template split string by delimiter

I have my own helm chart and I'm trying to perform split without using the _helpers.tpl in one line

my values.yaml file content:

deployment:
    domain: my.domain

I need to split domain name in my template file: my.domain

I have tried to perform this by using the following syntax:

name regex (.*)\.{{ (split .Values.deployment.domain ".")._0 }}\.{{ (split .Values.deployment.domain ".")._1 }}

or

{{- $split := .Values.deployment.domain "." . }}
name regex (.*)\.{{ first split }}\.{{ second split }}

But nothing worked

I'm trying to get the following results in my template file:

name regex (.*)\.my\.domain
like image 497
dsaydon Avatar asked Dec 05 '18 14:12

dsaydon


1 Answers

Helm uses the sprig library to provide lots of data manipulation functions, have a look at their docs for strings. You can use the {{ split }} function to do what you want.

$parts := split "." .Values.deployment.domain
$parts._0
like image 93
Alex Pliutau Avatar answered Nov 13 '22 17:11

Alex Pliutau