-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathls-deployments.sh
executable file
·97 lines (71 loc) · 3.47 KB
/
ls-deployments.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
#set -x
KCMD=kubectl
function Help()
{
if [[ ! -z "${SHORT_HELP_MODE}" ]]; then
echo "[-n <namespace>] show kubernetes deployments with containers, their image and command "
exit 1
fi
cat <<EOF
Usage: $0 -n <namespace> [-v] [-h]
-v : verbose run
-h : help
list the name of all kubernetes deployments in a namespace given by -n option. (if no -n option then applies to all namespaces)
for each deployment it also displays for each container its name, image and command
requires: $KCMD and jq
EOF
exit 1
}
POD_NSPACE_SPEC="--all-namespaces"
while getopts "hvn:p:" opt; do
case ${opt} in
h)
Help
;;
n)
POD_NSPACE_SPEC=" -n $OPTARG "
POD_NSPACE="$OPTARG "
;;
p)
POD_NAME=$OPTARG
;;
v)
set -x
export PS4='+(${BASH_SOURCE}:${LINENO}) '
VERBOSE=1
;;
*)
echo "Invalid Option"
Help
;;
esac
done
function tokenize {
local OLD_IFS
OLD_IFS=$IFS
IFS=$1 read -d '' -r -a TOKEN_ARRAY <<< "$2" || true
IFS=$OLD_IFS
}
DEPLOYMENTS=$($KCMD get deployments $POD_NSPACE_SPEC --no-headers )
function dep_info {
echo "deployment: $DEP_NAME namespace: $NAMESPACE"
$KCMD get deployment -n $NAMESPACE $DEP_NAME -o json | jq '.spec | .template | .spec | .containers | .[] | "container-info name: " + .name + " image: " + .image + " command: " + ( .command // [] | join(" ")) '
}
if [[ "$POD_NSPACE" == "" ]]; then
while read -r line; do
echo ""
tokenize ' ' "$line"
NAMESPACE=${TOKEN_ARRAY[0]}
DEP_NAME=${TOKEN_ARRAY[1]}
dep_info
done <<< "$DEPLOYMENTS"
else
while read -r line; do
echo ""
tokenize ' ' "$line"
NAMESPACE="$POD_NSPACE"
DEP_NAME=${TOKEN_ARRAY[0]}
dep_info
done <<< "$DEPLOYMENTS"
fi