小编fir*_*ter的帖子

Helm 模板转换为 json

我希望能够从如下 Helm 模板文件中插入带有toJson helm 函数的模板,如文档中所述:

value: {{ include "mytpl" . | lower | quote }}
Run Code Online (Sandbox Code Playgroud)

https://helm.sh/docs/howto/charts_tips_and_tricks/#know-your-template-functions

我的配置: _helper.tpl

{{- define "my_tpl" -}}
key1: value1
key2: value2
{{- end -}}
Run Code Online (Sandbox Code Playgroud)

dep.yaml

  template:
    metadata:
      annotations:
        test: >-
          {{ include "my_tpl" . | toJson }}
Run Code Online (Sandbox Code Playgroud)

这应该返回

  template:
    metadata:
      annotations:
        test: >-
          {"key1":"value1","key2":"value2"}
Run Code Online (Sandbox Code Playgroud)

但它返回

  template:
    metadata:
      annotations:
        test: >-
          "key1:value1\nkey2:value2"
Run Code Online (Sandbox Code Playgroud)

我正在使用 Helm v3。有人有什么想法吗?

kubernetes-helm helm3

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

helm3 ×1

kubernetes-helm ×1