Helm 复杂数组变量

问题描述 投票:0回答:1

在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: '[email protected]'
        pipelines:
          - name: test_rep
            pipeline: '{"my_json":{}}'
      - name: test222
        location: us-west1
        creating_cron: @once
        removing_cron: @once
        config:
          type: Basic
          displayName: test222
          dataprocServiceAccount: '[email protected]'
        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}}

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

kubernetes kubernetes-helm
1个回答
1
投票

Helm 包含一个未充分记录的

toYaml
函数,可将任意对象转换为 YAML 语法。由于 YAML 对空格敏感,因此请注意
toYaml
的输出从第一列开始并以换行符结束。您可以将其与
indent
函数结合使用,以使输出显示在正确的缩进处。

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

请注意,最后一行包含

indent 4
来缩进生成的 YAML 块(比前一行多两个空格),并且模板调用之前没有空格。

在此示例中,我已将内容作为 YAML 块标量(倒数第二行的

|-
)包含在 ConfigMap 中,但您可以在 Helm 值中配置复杂设置的任何地方使用相同的技术,即使它是针对资源限制或入口路径等内容的 Kubernetes 设置。

© www.soinside.com 2019 - 2024. All rights reserved.