简体   繁体   English

如何使用 python 解析舵图 yaml 文件

[英]How to parse helm chart yaml file using python

I am trying to parse a helm chart YAML file using python.我正在尝试使用 python 解析掌舵图 YAML 文件。 The file contains some curly braces, that's why I am unable to parse the YAML file.该文件包含一些花括号,这就是我无法解析 YAML 文件的原因。

a sample YAML file YAML 文件示例

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Values.nginx.name }}-config-map
  labels:
    app: {{ .Values.nginx.name }}-config-map
data:
  SERVER_NAME: 12.121.112.12
  CLIENT_MAX_BODY: 500M
  READ_TIME_OUT: '500000'

Basically, I could not figure out how to ignore the values present at right side.基本上,我无法弄清楚如何忽略右侧存在的值。

Thank you,谢谢,

You would have to write an implementation of Go's text/template library in Python.您必须在 Python 中编写 Go 的text/template库的实现。 A better option is probably to push your content through helm template first and then parse it.更好的选择可能是先通过helm template推送您的内容,然后再解析它。

I solved it by wrapping quotes wherever I use the template.我通过在使用模板的任何地方加上引号来解决它。

like this像这样

apiVersion: v1
kind: ConfigMap
metadata:
    name: "{{ .Values.nginx.name }}-config-map"
    labels:
         app: "{{ .Values.nginx.name }}-config-map"
data:
    SERVER_NAME: 12.121.112.12
    CLIENT_MAX_BODY: 500M
    READ_TIME_OUT: '500000'

Helm can read this and I can parse this using python YAML as it's a valid YAML file. Helm 可以读取它,我可以使用 python YAML 解析它,因为它是一个有效的 YAML 文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM