【问题标题】:Convert string to YAML map将字符串转换为 YAML 映射
【发布时间】:2020-07-10 08:47:32
【问题描述】:

在 values.yaml 中,我有另一个 yaml 配置编码为 base64。在模板中,我使用

对其进行解码
{{ $config := b64dec .Values.config }}

我需要像访问地图一样访问它,所以需要的是一种类似于文件 AsConfig 但用于字符串的类似物。

【问题讨论】:

    标签: kubernetes-helm go-templates


    【解决方案1】:

    可以使用 Helm 的fromYaml 函数(除了this commit,没有找到任何文档)

    config.yaml 编码为cat config.yaml | base64

    xxx: yyy
    zzz: qqq
    

    values.yaml

    config: eHh4OiB5eXkKenp6OiBxcXEK
    

    secret.yaml

    {{ $config :=  (b64dec .Values.config) | fromYaml  }}
    apiVersion: v1
    kind: Secret
    metadata:
      name: secret
    type: Opaque
    data:
      test: {{  $config.xxx }}
    

    头盔模板

    /mnt/c/home/chart> helm template .
    ---
    # Source: chart/templates/secret.yaml
    apiVersion: v1
    kind: Secret
    metadata:
      name: secret
    type: Opaque
    data:
      test: yyy
    

    【讨论】:

    • 感谢您的回答,它有效。我以前试过这个,当时我收到了一个字符串,一定是我的错误。无论如何,这是最好的解决方案,谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-10
    • 2021-12-25
    • 2016-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多