Kubernetes Helm,将两个变量与中间的字符串组合在一起 [英] Kubernetes Helm, combine two variables with a string in the middle

查看:723
本文介绍了Kubernetes Helm,将两个变量与中间的字符串组合在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改变量的值(如果通过在中间用破折号组合两者来设置另一个变量),我不确定这样做的语法,我在想这样的事情:

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

这是正确的吗?如果serviceNamespacehello并且serviceTag1.0.0,我最终会以serviceNamespacehello-1.0.0吗?

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

推荐答案

要进行串联,只需使用printf:

For concatenation just use printf:

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

这篇关于Kubernetes Helm,将两个变量与中间的字符串组合在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆