Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Helm Variables inside ConfigMap File

So I had a ConfigMap with a json configuration file in it, like this:

apiVersion: v1
kind: ConfigMap
metadata:
  name: my-config-map
data:
  config.json: |+
  {
    "some-url": "{{ .Values.myApp.someUrl }}"
  }

But I’ve moved to having my config files outside the ConfigMap’s yaml, and just referencing them there, like this:

apiVersion: v1
kind: ConfigMap
metadata:
  name: my-config-map
data:
  config.json: |-
{{ .Files.Get .Values.myApp.configFile | indent 4 }}

But now I want my json to look like the following

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{
  "some-url": "{{ .Values.myApp.someUrl }}"
}

The only thing I tried is what I just showed. I ‘m not even sure how to look for this answer.

Is it even possible?

>Solution :

At the time of reading the file, its content is a string. It’s not evaluated as template, and therefore you cannot use variables like you do.

However, helm has a function for this purpose specifically called tpl:

apiVersion: v1
kind: ConfigMap
metadata:
  name: my-config-map
data:
  config.json: |- 
{{ tpl (.Files.Get .Values.myApp.configFile) $ | indent 4 }}

The tpl function takes a template string and renders it with some context. This is useful when you have template snippets in your values file or like in your case in some files content.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading