-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-all-resource-in-namespace.sh
executable file
·67 lines (54 loc) · 1.16 KB
/
get-all-resource-in-namespace.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
function Help {
if [[ $1 != "" ]]; then
echo "Error: $*"
fi
if [[ ! -z "${SHORT_HELP_MODE}" ]]; then
echo "-s <namespace> : show all kubernetes objects that exist in namspace"
exit 1
fi
cat <<EOF
$0 -
show all kubernetes objects that exist in namspace
-n <namespace> : the namespace (required)
-o : for each of these objects - dump as json (default off)
-h : show help
EOF
exit 1
}
JSON=""
while getopts "hon:" opt; do
case ${opt} in
h)
Help
;;
n)
NSPACE="$1"
;;
o)
JSON="-o json"
;;
*)
Help "Invalid option"
;;
esac
done
if [[ $NSPACE == "" ]]; then
Help "-n option required"
fi
for f in $(kubectl api-resources --namespaced=true | sed 's/1d//' | awk '{ print $1 }'); do
RET=$(kubectl get -n olm $f -o wide 2>&1)
if [[ $? == 0 ]]; then
NOTFOUND=$(echo "$RET" | grep -c "No resources found")
if [[ ${NOTFOUND} == "0" ]]; then
echo "***"
echo "kubectl get -n olm $f -o wide"
echo ""
echo "$RET"
if [[ "$JSON" != "" ]]; then
echo "kubectl get -n olm $f $JSON"
kubectl get -n olm $f $JSON
fi
fi
fi
done