diff --git a/kubenukem b/kubenukem index 04ffbfe..57f01bd 100755 --- a/kubenukem +++ b/kubenukem @@ -1,7 +1,15 @@ #!/usr/bin/env bash +things=(deployment replicaset statefulset daemonset service job hpa pod role rolebinding serviceaccount) + if [[ -z $1 ]]; then - echo "ERROR: no service provided in default namespace" + echo "Usage: kubenukem [namespace] name [--unsafe]" + echo + echo "Nukes (deletes) all resources with a particular *name* in a particular namespace from a Kubernetes cluster" + echo + echo " namespace if not provided, 'default' namespace is used" + echo " name name of resources to delete, can be partial name (like grep)" + echo " --unsafe deletes also 'clusterrole' and 'clusterrolebinding' which are global (not namespace specific!)" exit 1 fi @@ -13,8 +21,10 @@ if [[ -z $service ]]; then namespace=default fi +if [[ $3 == "--unsafe" ]]; then + things+=(clusterrole clusterrolebinding) +fi -things=(deployment replicaset statefulset daemonset service job hpa pod role rolebinding clusterrole clusterrolebinding serviceaccount) for thing in "${things[@]}"; do for thingy in "$(kubectl -n "$namespace" get "$thing" | grep "$service")"; do for t in $(echo "$thingy"| cut -d' ' -f1); do