小编Cin*_*hou的帖子

有没有办法验证/解析包含 go-template 变量的 YAML 文件?

我有一个“YAML”文件。我想在渲染其中的 go-template 变量之前验证它。例如:

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-configmap
data:
  myvalue: "Hello World"
  drink: {{ .Values.favorite.drink | default "tea" | quote }}
  food: {{ .Values.favorite.food | upper | quote }}
Run Code Online (Sandbox Code Playgroud)

典型的 YAML 解析器在这里不起作用,因为它将解析{为映射的开头。

err := yaml.Unmarshal(data, &Content)
// Failed to parse the provided YAML: yaml: line 4: did not find expected key
Run Code Online (Sandbox Code Playgroud)

我想知道是否有任何软件包可以帮助我做到这一点?我在网上搜索了一段时间但没有运气。谢谢你的帮助!

yaml go unmarshalling go-templates kubernetes-helm

5
推荐指数
1
解决办法
5519
查看次数

标签 统计

go ×1

go-templates ×1

kubernetes-helm ×1

unmarshalling ×1

yaml ×1