Created
November 14, 2019 10:27
-
-
Save jayme-github/2c17ed6b7f2bd577dadc2e686f9706a1 to your computer and use it in GitHub Desktop.
List all empty namespaces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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