Use split_doc with other documents in the same stream #1789
Unanswered
mathewpeterson
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Yep:
Yourcan use the '//` alternative operator (https://mikefarah.gitbook.io/yq/operators/alternative-default-value) to provide an alternative value when we don't find a node with Kind ConfigMapList |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I am trying to handle an edge case when working with "lists" resources (ConfigMapList, RoleBindingList, RoleList) that are generated by a Helm chart. Since these are not real KRDs, I would like to split all items from the list into their own document so that I can save them to disk.
Typically, this is very easy with the
split_doc
operator since it works exactly as expected. However the issue I am running into is when there are other non "list" documents in the YAML stream as I need those, too.Say I have a stream of documents like:
I can execute the following which only gives me documents that were split from the list and does not include the third, non-list document:
yq 'select(.kind == "ConfigMapList") | .items[] | split_doc ' all.yaml
Is it possible to get the following as a result? It would be fine for my use-case if this also included the original ConfigMapList document as I could filter that out later.
I understand that I could execute multiple invocations of yq if I store the output on disk but I am hoping that I can do this in a single yq call so I can pass the output directly into another utility.
Beta Was this translation helpful? Give feedback.
All reactions