Helm复杂数组变量



在values.yaml中,我定义了

data_fusion:
tags:
- tag1
- tag2
- tag3
instances:
- name: test
location: us-west1
creating_cron: @once
removing_cron: @once
config:
type: Developer
displayName: test
dataprocServiceAccount: 'my@project.iam.gserviceaccount.com'
pipelines:
- name: test_rep
pipeline: '{"my_json":{}}'
- name: test222
location: us-west1
creating_cron: @once
removing_cron: @once
config:
type: Basic
displayName: test222
dataprocServiceAccount: 'my222@project.iam.gserviceaccount.com'
pipelines:
- name: test_rep222
pipeline: '{"my_json222":{}}'
- name: test_rep333
pipeline: '{"my_json333":{}}'
- name: test_rep444
pipeline: '{"my_json444":{}}'

你们可以看到我有3个标签和2个实例。第一个实例包含1个管道,第二个实例包含3个管道。

我想将标签和实例传递到我的yaml文件:

another_config: {{ .Values.blabla.blablabla }}
data_fusion:
tags:
- array of tags should be here
instances:
- array of instances (and associated pipelines) should be here

或者只是简单的

another_config: {{ .Values.blabla.blablabla }}
data_fusion:
{{.Whole.things.should.be.here}}

你们能帮忙吗?由于我是新手,所以我不知道如何通过复杂的数组(或整个yaml的大部分(。

Helm包含一个文档不足的toYaml函数,该函数将任意对象转换为YAML语法。由于YAML对空格敏感,因此需要注意的是,toYaml的输出从第一列开始,并以换行符结束。您可以将其与indent函数相结合,使输出显示在正确的缩进处。

apiVersion: v1
type: ConfigMap
metadata: { ... }
data:
data_fusion: |-
{{ .Values.data_fusion | toYaml | indent 4 }}

请注意,最后一行包含indent 4,用于缩进生成的YAML块(比前一行多出两个空格(,并且在模板调用之前没有空白。

在这个例子中,我在ConfigMap中包含了作为YAML块标量的内容(倒数第二行的|-(,但您可以在Helm值中配置复杂设置的任何地方使用相同的技术,即使是用于资源约束或入口路径等的Kubernetes设置。

最新更新