-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathall.sh
executable file
·58 lines (48 loc) · 1.45 KB
/
all.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
#!/usr/bin/env bash
# Usage:
# kubectl all resources
# kubectl all resources [namespace]
# Requires:
# - kubectl
set -eo pipefail
function usage() {
echo "USAGE"
echo "-----"
echo "kubectl all resources"
echo ""
echo "kubectl all resources namespace"
echo ""
echo "kubectl all -h | --help : Usage of this command line";
echo ""
}
#Add any resources that need to be ignored
list=(bindings localsubjectaccessreviews.authorization.k8s.io pods.metrics.k8s.io events.events.k8s.io)
elementIn () {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
function get_resources() {
if [ -z "$1" ]; then namespace='default'; else namespace="$1"; fi
resources=$(kubectl api-resources --namespaced=true --output=name)
for resource in $resources; do
if elementIn "$resource" "${list[@]}"; then
continue
else
data=$(kubectl get $resource -n $namespace --ignore-not-found=true)
if [[ ! -z $data ]]; then
echo $resource':'
echo -e "$data"
printf '\n'
fi
fi
done
}
if [ -z "$1" ]; then usage && exit; fi
while [ -n "$1" ]; do
case "$1" in
resources) shift; get_resources "$@"; exit;;
-h|--help) usage; exit;; # quit and show usage
* ) echo "$1 not recognized"; exit 1;; # if no match, add it to the positional args
esac
done