Skip to content
Snippets Groups Projects
Commit a0bcc831 authored by František Dvořák's avatar František Dvořák
Browse files

More robust pods cleaner script - kill everything in Terminating state

parent 4d54f853
No related branches found
No related tags found
No related merge requests found
...@@ -5,18 +5,17 @@ ...@@ -5,18 +5,17 @@
# #
# Example: # Example:
# #
# k8s-pods-cleaner.sh hub app=jupyterhub,component=singleuser-server --yes # k8s-pods-cleaner.sh hub --yes
# #
if [ -z "$1" ]; then if [ -z "$1" ]; then
echo "Usage: $0 NAMESPACE [QUERY [--yes]]" echo "Usage: $0 NAMESPACE [--yes]"
exit 0 exit 0
fi fi
NS="$1" NS="$1"
QUERY="$2" PERFORM="$2"
PERFORM="$3" for pod in $(kubectl get pod -n "$NS" | awk 'NR>1 && $3=="Terminating" {print $1}'); do
for pod in $(kubectl get pod -n "$NS" -l "$QUERY" --field-selector="status.phase==Failed" -ojsonpath='{.items[*].metadata.name}'); do
if [ -n "$PERFORM" ]; then if [ -n "$PERFORM" ]; then
kubectl get pod -n "$NS" "$pod" -oyaml > "/tmp/$NS-$pod.yaml" kubectl get pod -n "$NS" "$pod" -oyaml > "/tmp/$NS-$pod.yaml"
kubectl delete pod -n "$NS" "$pod" --force kubectl delete pod -n "$NS" "$pod" --force
......
...@@ -133,7 +133,7 @@ ...@@ -133,7 +133,7 @@
name: "Notebooks {{ name }} cleanup" name: "Notebooks {{ name }} cleanup"
minute: "*" minute: "*"
hour: "*" hour: "*"
job: "KUBECONFIG=$HOME/.kube/config /usr/local/bin/k8s-pods-cleaner.sh '{{ name }}' app=jupyterhub,component=singleuser-server --yes >/dev/null 2>&1" job: "KUBECONFIG=$HOME/.kube/config /usr/local/bin/k8s-pods-cleaner.sh '{{ name }}' --yes >/dev/null 2>&1"
user: egi user: egi
with_fileglob: with_fileglob:
- "../deployments/*.yaml" - "../deployments/*.yaml"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment