sebastianwth
sebastianwth

Reputation: 187

Merge two YAML files using yq

Using YQ, I can merge 2 Kubernetes Helm chart yaml value files together using:

yq '. *= load("values-prod.yaml")' ../web/values.yaml

However, with values-prod.yaml, I need the contents to be dynamically generated at runtime.

I'm trying:

yq '. *= load("<(helm template -f values-prod.yaml -s templates/web.yaml . | yq .spec.source.helm.values)")' ../web/values.yaml

Error: Failed to load <(helm template -f values-prod.yaml -s templates/web.yaml . | yq .spec.source.helm.values): open <(helm template -f values-prod.yaml -s templates/web.yaml . | yq .spec.source.helm.values): no such file or directory

I've tried multiple variations of quotations with no luck.

Thanks.

Upvotes: 0

Views: 1211

Answers (1)

jpseng
jpseng

Reputation: 2190

load is an operator of yq. It accepts a file name as a parameter. You cannot use process substitution here as this is shell syntax (the error is generated by yq, not by your shell). You need to create the dynamic content outside yq and pass it to yq.

Maybe you can just swap the two inputs:

yq '. *= load("../web/values.yaml")' <(helm template -f values-prod.yaml -s templates/web.yaml . | yq .spec.source.helm.values)

I can't test this code, but I hope the idea leads you to the solution.

Upvotes: 0

Related Questions