Skip to content

Commit

Permalink
add --unsafe switch to delete clusterrole/clusterrolebinding (#1)
Browse files Browse the repository at this point in the history
clusterrole and clusterrolebinding are global, use with caution
also added usage when no params provided
  • Loading branch information
danielllek authored and rms1000watt committed Feb 6, 2019
1 parent 940a281 commit ace4697
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions kubenukem
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down

0 comments on commit ace4697

Please sign in to comment.