Deleting object incorrectly deleting attribute, how to delete object? #1160
Unanswered
CraigRubendall
asked this question in
Q&A
Replies: 1 comment
-
Without having a representative sample file it's hard to know what the syntax should be. Assuming its something like this: - kind: thing
other: stuff
- kind: PodDisruptionBudget
interesting: things
- kind: bingo
meow: cat Then the command to delete the entry with the kind=PodDistruptionBudget is: yq 'del(.[] | select(.kind == "PodDisruptionBudget"))' file.yaml which leaves: - kind: thing
other: stuff
- kind: bingo
meow: cat What happens under the hood is:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm using yq 4.20.1.
I'm working with my kubernetes site.yaml file. What I need to do is to remove any PodDisruptionBudget objects.
I can find them properly using this command:
yq eval 'select(.kind == "PodDisruptionBudget")' site.yaml
when I try to delete using a similar syntax:
yq eval 'del(.kind == "PodDisruptionBudget")' site.yaml
the result is that the kind attribute is removed from all objects (including non-PodDisruptionBudget ones)!
I've also tried several other variants:
yq eval 'del(select(.kind == "PodDisruptionBudget"))' site.yaml # doesn't remove anything
yq eval 'del(. | select(.kind == "PodDisruptionBudget"))' site.yaml # doesn't remove anything
I need to end up with a valid site.yaml file so the answer shouldn't flatten or otherwise disrupt the remaining items in the file contents.
What is the proper syntax for doing so?
Beta Was this translation helpful? Give feedback.
All reactions