.values中的helm变量 [英] helm variables in .Values
问题描述
我要动态生成模板文件,这是我的情况:
I want to dynamically generate my template file, here is my case:
{{- $v := (.Files.Get "values-deployment-nginx.yaml") | fromYaml }}
spec:
{{- range $key, $value := $v.containers }}
containers:
- name: {{ $value.name }}
image: {{ .Values.{{ $value.name }}-image }}:{{ .Values.{{ $value.name }}--tag }}
我想首先获取{{$ value.name}},它可能是类似"nginx"的字符串,然后我想使用{{.Values.nginx-image}}来获取正确的图像值在值文件中.
有没有办法可以做到这一点?非常感谢你!
I want to first get the {{ $value.name }}, it maybe a string like "nginx", then I would like to use the {{ .Values.nginx-image }} to get the right image value in values file.
Is there a way can do this? Thank you very much!
我有许多动态生成的部署模板,但是只想将映像和标签公开到值文件,以便我们在安装图表时可以传递不同的映像信息.其他变量在(.Files.Get"values-deployment-nginx.yaml")中,就像这样(也是动态生成的).因此,当生成模板时,我要匹配值文件中的图像和标签.
I have many deployment template dynamically generated, but only want to expose the image and tag to values file , so that we can pass different image informations when install chart. Other variables are in (.Files.Get "values-deployment-nginx.yaml") , like this(is also generated dynamically). So when generate the template, I want to match the image and tag in value file.
值文件如下:
deployment-nginx-imagerepo: nginx
deployment-nginx-imagetag: latest
values-deployment-nginx.yaml(由其他项目生成)如下:
values-deployment-nginx.yaml like this(generated by other project):
autoscale: []
containers:
- envs: []
imagerepository: nginx
imagetag: latest
itemid: n79fecd51_6716_fa65_5e64_aeed8ed6ab7e
name: nginx
resource:
maxcpu: ""
maxmemory: ""
mincpu: "0.5"
minmemory: 512m
volumemounts: []
name: details
replicas: 1
schedulpolicy: []
storages: []
type: deployment
推荐答案
在使用文本/模板语言我相信index
函数可以做到这一点. (.Values
通常是一个映射,YAML映射和列表会转换为Go映射和切片.)(还要记住
In the Go text/template language I believe the index
function will do this. (.Values
is typically a map, and YAML maps and lists convert to Go maps and slices.) (Also remember almost everything in the sprig library is available.)
image: {{ index .Values (printf "%s-image" $value.name) }}:{{ index .Values (printf "%s-tag" $value.name) }}
这篇关于.values中的helm变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!