【问题标题】:How to use boolean and array variable in yaml?如何在 yaml 中使用布尔变量和数组变量?
【发布时间】:2021-12-11 11:00:55
【问题描述】:

我在替换/替换 yaml 中的布尔值和数组变量时遇到问题。我正在使用 argocd yaml 文件。

values:
          files: 
             - 'values.yaml'
             - 'values-stage.yaml'
          automated:
            - name: prune
              type: boolean
              value: true


valueFiles: {{values.files}}   ##Should receive array </code>

prune: {{values.automated.prune}} ##Should receive array </code>

如何将 values.files 放入 valueFiles 和 values.automated.prune 进行修剪?

【问题讨论】:

  • 我认为您正在寻找 helm 模板。看看 stackoverflow.com/a/58030379/2854252>

标签: arrays kubernetes yaml boolean argocd


【解决方案1】:

看来anchor/alias 功能可以解决这个问题。

# example.yaml

values:
  files: &files 
    - 'values.yaml'
    - 'values-stage.yaml'
  automated: &automated
    - name: prune
      type: boolean
      value: true


valueFiles: *files
# It seems there is no 'values.automated.prune' field.
valueAutomated: *automated

我用yq测试过:

yq eval '. | explode(.)' example.yml

给出:

values:
  files:
    - 'values.yaml'
    - 'values-stage.yaml'
  automated:
    - name: prune
      type: boolean
      value: true
valueFiles:
  - 'values.yaml'
  - 'values-stage.yaml'
valueAutomated:
  - name: prune
    type: boolean
    value: true

注意:YAML 别名只能引用具有锚点的节点,不能引用节点的特定条目。 p>

【讨论】:

    猜你喜欢
    • 2021-08-21
    • 1970-01-01
    • 2012-09-27
    • 2010-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多