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

yq for merge strings

I have following prod.yaml file

configMap:
  data: 
    env:
      APP_1: "{{ .Data.data.app_1 }}"
      APP_2: "{{ .Data.data.app_2 }}"
      APP_3: "{{ .Data.data.app_3 }}"
      APP_4: "{{ .Data.data.app_4 }}"

and updated.yaml file:

APP_1:
APP_2:
APP_3:
APP_4:
APP_5:
LOG_DIR:

The expected result is:

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

configMap:
  data: 
    env:
      APP_1: "{{ .Data.data.app_1 }}"
      APP_2: "{{ .Data.data.app_2 }}"
      APP_3: "{{ .Data.data.app_3 }}"
      APP_4: "{{ .Data.data.app_4 }}"
      APP_5:
      LOG_DIR:

I am using awk to format the fields new data fields

cat .env | awk -F":" '{print $1": \"{{ .Data.data."tolower($1)" }}\""}' > updated.yaml

And awk to merge the new fields

yq '.env[] *=n [load("update.yaml")]' prod.yaml > a.yaml

But I cannot update the prod.yaml file…

I am reading this documentation yq doc

>Solution :

With mikefarah/yq that you are using, its pretty close to what you have. Remember that .env is a !!map type and not a !!seq, so do the recursive merge as the map type, i.e.

yq '.configMap.data.env *=n load("update.yaml")' prod.yaml

The above does not modify the file in-place. If you are satisfied with the contents of stdout, you could use the -i flag to do in-place substitution of the file

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