How to parse helm chart yaml file using python

Viewed 2001

I am trying to parse a helm chart YAML file using python. The file contains some curly braces, that's why I am unable to parse the YAML file.

a sample YAML file

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,

2 Answers

You would have to write an implementation of Go's text/template library in Python. A better option is probably to push your content through helm template first and then parse it.

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.

Related