Handle non-namespaced resouces

Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
This commit is contained in:
Marcus Noble 2024-06-07 13:18:56 +01:00
parent a1cd7f9eae
commit 951bbcc7fd
Signed by: AverageMarcus
GPG Key ID: B8F2DB8A7AEBAF78
2 changed files with 5 additions and 2 deletions

View File

@ -47,11 +47,14 @@ while test $# -gt 0; do
esac
done
NAMESPACED="--namespaced"
if [[ "${LABEL}" != "" ]]; then
LABEL="-l ${LABEL}"
NAMESPACED=""
fi
NAMES="$(kubectl api-resources --namespaced --verbs list -o name | tr '\n' ,)"
NAMES="$(kubectl api-resources ${NAMESPACED} --verbs list -o name | tr '\n' ,)"
if [[ "$ALL_NAMESPACES" == "true" ]]; then
kubectl get "${NAMES::${#NAMES}-1}" --show-kind --ignore-not-found ${LABEL} -A 2>/dev/null

View File

@ -69,7 +69,7 @@ if [[ "${SELECTOR}" == "" ]]; then
else
printf "Are you sure you want to delete all matching '${SELECTOR}'? (y/n): "
SELECTOR="-l ${SELECTOR}"
NAMES="$(kubectl api-resources --namespaced --verbs list -o name 2>/dev/null | tr '\n' ,)"
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
read CONFIRM