6

We are going to write Helm chart and providing configuration file using configmap.

For some reasons our app is using JSON format configuration file. Currently we provide configuration file in Helm chart's values.yaml like this.

conffiles:
  app_conf.json:
    ...(content in YAML)...

And to make it easy to modify, in values.yaml we use YAML format and in configmap's template we did conversion using "toJson",

data:
{{- range $key, $value := .Values.conffiles }}
  {{ $key }}: |      
{{ toJson $value | default "{}" | indent 4 }}
{{- end -}}
{{- end -}}

So in values.yaml it's YAML, and in configmap it will be JSON, then in container it will be stored into JSON file.

Our question is,

  • Is there a way to convert YAML to JSON when saving files into container? That is, we hope those configuration content could be 1) YAML in values.yaml 2) YAML in configmap 3) JSON file in container

Thank in advance.

Community
  • 1
  • 1
Lijing Zhang
  • 63
  • 1
  • 5
  • I know this isn't the answer to the question, but yaml is a superset of JSON anyway. Why not get your app to use a proper yaml parser, then you can user either? https://yaml.org/spec/1.2/spec.html#id2759572 – jaxxstorm Jan 16 '19 at 02:33
  • Sincerely thanks @jaxxstorm . We've decided to make app directly read yaml configuration file. Though it needs to change src code we don't want to do more tricky things. – Lijing Zhang Jan 17 '19 at 03:24

1 Answers1

1

I don't think there is anything out of the box but you do have options, depending upon your motivation.

Your app is looking for json and the configmap is mounted for your app to read that json. Your helm deployment isn't going to modify the container itself. But you could change your app to read yaml instead of json.

If you want to be able to easily see the yaml and json versions you could create two configmaps - one containing yaml and one with json.

Or if you're just looking to be able to see what the yaml was that was used to create the configmap then you could use helm get values <release_name> to look at the values that were used to create that release (which will include the content of the conffiles entry).

Ryan Dawson
  • 11,832
  • 5
  • 38
  • 61
  • 1
    Sincerely thanks Ryan. We've decided to make app directly read yaml configuration file. Though it needs to change src code we don't want to do more tricky things... – Lijing Zhang Jan 17 '19 at 03:26