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 esac
done done
NAMESPACED="--namespaced"
if [[ "${LABEL}" != "" ]]; then if [[ "${LABEL}" != "" ]]; then
LABEL="-l ${LABEL}" LABEL="-l ${LABEL}"
NAMESPACED=""
fi 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 if [[ "$ALL_NAMESPACES" == "true" ]]; then
kubectl get "${NAMES::${#NAMES}-1}" --show-kind --ignore-not-found ${LABEL} -A 2>/dev/null 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 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}" 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") 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 read CONFIRM