forked from juice-shop/multi-juicer
-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
list-unused-ns.sh
executable file
·36 lines (34 loc) · 1.33 KB
/
list-unused-ns.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
echo "This script shows all the namespaces that have not been used, it requires an export of the users in CTFD"
echo "It assumes you have the users.csv file and teams.csv file from CTFD in the same folder"
echo "This script results in a file unusedteams.txt with all the teams that have no exact match with the registration of users and teams in CTFD"
rm unusedteams.txt
source check-available-commands.sh
checkCommandsAvailable kubectl jq awk
IFS=$'
'
USERS=($(awk -F , '{print tolower($3)}' users.csv))
TEAMS=($(awk -F , '{print tolower($3)}' teams.csv))
unset IFS
NAMESPACES=$(kubectl get ns | grep t- | awk '{print $1;}')
count=0
for NAMESPACE in `kubectl get ns | grep t- | awk '{print $1;}'`
do
echo "found $NAMESPACE"
CUT_NAMESPACE=${NAMESPACE:2}
let count++
NO_TDASH_NAMESPACE=`echo $CUT_NAMESPACE | awk '{print tolower($0)}'`
echo "checking list for $NO_TDASH_NAMESPACE"
if [[ " ${USERS[*]} " =~ " ${NO_TDASH_NAMESPACE} " ]]; then
echo "FOUND $NO_TDASH_NAMESPACE in users"
else
if [[ " ${TEAMS[*]} " =~ " ${NO_TDASH_NAMESPACE} " ]]; then
echo "FOUND $NO_TDASH_NAMESPACE in teams"
else
echo "did NOT find $NO_TDASH_NAMESPACE in users and teams"
echo $NAMESPACE >> unusedteams.txt
fi
fi
done
unregistered=$(wc -l unusedteams.txt)
echo "${count} namespaces active where not registered ${unregistered}"