Skip to content

Instantly share code, notes, and snippets.

@ltupin
Created February 28, 2019 14:41
Show Gist options
  • Save ltupin/ad08489113ee5b8600a08201dbabad54 to your computer and use it in GitHub Desktop.
Save ltupin/ad08489113ee5b8600a08201dbabad54 to your computer and use it in GitHub Desktop.
Filter failed kubernetes jobs to delete it
#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
@alexlopes
Copy link

Thanks! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment