Added flag to skip confirmation when force-deleting

Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
This commit is contained in:
Marcus Noble 2024-09-17 12:28:54 +01:00
parent 2d78ed73c9
commit aab2b2a52f
Signed by: AverageMarcus
GPG Key ID: B8F2DB8A7AEBAF78

View File

@ -18,6 +18,7 @@ print_usage() {
echo "-n, --namespace the namespace the resource is in (default: current namespace)" echo "-n, --namespace the namespace the resource is in (default: current namespace)"
} }
YOLO="0"
POS_ARGS=() POS_ARGS=()
while test $# -gt 0; do while test $# -gt 0; do
@ -36,6 +37,10 @@ while test $# -gt 0; do
print_usage print_usage
exit 0 exit 0
;; ;;
--yolo)
YOLO="1"
shift
;;
/) /)
# We want to ignore slash seperators between resource types and names # We want to ignore slash seperators between resource types and names
shift shift
@ -68,15 +73,27 @@ if [[ "${SELECTOR}" == "" ]]; then
RESOURCES=("${POS_ARGS[0]}/${POS_ARGS[1]}") RESOURCES=("${POS_ARGS[0]}/${POS_ARGS[1]}")
else else
printf "Are you sure you want to delete all matching '${SELECTOR}'? (y/n): " printf "Are you sure you want to delete all matching '${SELECTOR}'? (y/n): "
SELECTOR="-l ${SELECTOR}"
NAMES="$(kubectl api-resources --verbs list -o name 2>/dev/null | tr '\n' ,)"
RESOURCES=$(kubectl get "${NAMES::${#NAMES}-1}" --ignore-not-found ${SELECTOR} -n ${NAMESPACE} -o go-template='{{range.items}}{{.kind}}.{{.apiVersion}}/{{.metadata.name}}{{"\n"}}{{end}}' 2>/dev/null | tr '[:upper:]' '[:lower:]' | sed -r "s|/(v.+)/|/|g")
fi fi
read CONFIRM
if [[ "${YOLO}" == 0 ]]; then
read CONFIRM
else
echo ""
echo ""
orange "YOLO MODE!!! (What could go wrong?!)"
CONFIRM="y"
fi
if [ "${CONFIRM}" = "y" ]; then if [ "${CONFIRM}" = "y" ]; then
echo "" echo ""
echo "💣 OK, I hope you know what you're doing..." echo "💣 OK, I hope you know what you're doing..."
if [[ "${SELECTOR}" != "" ]]; then
SELECTOR="-l ${SELECTOR}"
NAMES="$(kubectl api-resources --verbs list -o name 2>/dev/null | tr '\n' ,)"
RESOURCES=$(kubectl get "${NAMES::${#NAMES}-1}" --ignore-not-found ${SELECTOR} -n ${NAMESPACE} -o go-template='{{range.items}}{{.kind}}.{{.apiVersion}}/{{.metadata.name}}{{"\n"}}{{end}}' 2>/dev/null | tr '[:upper:]' '[:lower:]' | sed -r "s|/(v.+)/|/|g")
fi
IFS=' IFS='
' '
for RESOURCE in ${RESOURCES} for RESOURCE in ${RESOURCES}