Replies: 2 comments 1 reply
-
So $ yq '. *d (load("./override.yaml") | .templates."deployment.yaml") | explode(.) | del(.. | select(. == null))' ./templates/deployment.yaml How could we match certain index of array without repetition? While this looks ok it may be a problem with a lot of elements: containers:
- null: null
- name: "busybox-override" |
Beta Was this translation helpful? Give feedback.
-
I'm not quite sure what you want to do - but it sounds like you need to merge the array matching on the name field? By default, yq doesn't have any contextual knowledge of how to merge in a particular arrays, it either merges by index, appends or just replaces the entire array. Have a look at this example here: https://mikefarah.gitbook.io/yq/operators/multiply-merge#merge-arrays-of-objects-together-matching-on-a-key on how to merge an array by a given field. For you the idPath is ".name", originalPath=".spec.template.spec.containers", otherPath=".spec.template.spec.containers" From you example this likely means you need to do two merges, one for the containers array by name, using the example in the help docs and another for the labels. |
Beta Was this translation helpful? Give feedback.
-
Hey i am looking for a way to utilize
jq
as a replacement forhelm
andkustomize
. While being excited seeing how nice it can work I just got stuck at arrays, given below files and command - output is not like i would imagine - first element in arraycontainers
is actually overriden ( keyname
) but it's also added as an additional element. I wonder what would be the best way here to provide consistency while being able to delete certain array element by index and also customizable overriding of other values.$ yq '. *d+ (load("./override.yaml") | .templates."deployment.yaml") | explode(.) | del(.. | select(. == null))' ./templates/deployment.yaml
Beta Was this translation helpful? Give feedback.
All reactions