-
-
Save ltupin/ad08489113ee5b8600a08201dbabad54 to your computer and use it in GitHub Desktop.
Filter failed kubernetes jobs to delete it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Should be a job too :-D | |
# With xargs (on all namespaces) | |
kc get jobs -o=jsonpath='{range .items[?(@.status.conditions[0].type == "Failed")]}{.metadata.name}{"\t"}{.metadata.namespace}{"\n"}{end}' --all-namespaces | \ | |
xargs -n2 sh -c 'kubectl delete jobs $0 --namespace=$1' | |
# For loop (only in the current namespace) | |
for i in $(kc get jobs -o=jsonpath='{range .items[?(@.status.conditions[0].type == "Failed")]}{.metadata.name}{"\n"}{end}'); | |
do kubectl delete jobs $i; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! ❤️