Skip to content

Instantly share code, notes, and snippets.

@jayme-github
Created November 14, 2019 10:27
Show Gist options
  • Save jayme-github/2c17ed6b7f2bd577dadc2e686f9706a1 to your computer and use it in GitHub Desktop.
Save jayme-github/2c17ed6b7f2bd577dadc2e686f9706a1 to your computer and use it in GitHub Desktop.
List all empty namespaces
#!/bin/bash
# grep -E pattern to ignore certain resources
IGNORE="^resourcequota/gke-resource-quotas|^secret/default-toke|^serviceaccount/default"
# Get a list of all "listable" namespaced ressources
resources=$(kubectl api-resources --verbs=list --namespaced=true -o name | paste -sd, -)
namespaces=$(kubectl get namespaces -o jsonpath='{.items[*].metadata.name}')
for ns in $namespaces; do
ns_resouces=$(kubectl get ${resources} --ignore-not-found --namespace ${ns} -o name | grep -vE "${IGNORE}")
if [ -z "$ns_resouces" ]; then
echo $ns
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment