-
Notifications
You must be signed in to change notification settings - Fork 9
/
pods
executable file
·122 lines (98 loc) · 3.03 KB
/
pods
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
# This tool is a variant of `kubectl get pods` and `kubectl get ksvc`.
# It executes both commands but only shows the entries of interest during
# a live demo. For example, it doesn't show Terminating pods.
set -e
once=""
# noclear=""
untilcmd=""
grepcmd=""
while [[ "$1" == "--"* ]]; do
case "$1" in
# --noclear) noclear="1" ;;
--once) once="1" ;;
--until) untilcmd="$2" ; shift ;;
--grep) grepcmd="$2" ; shift ;;
*) echo "Uknown option '$1'" ; exit 1 ;;
esac
shift
done
# if [[ -z "${noclear}" ]]; then
# clear
# fi
CLUSTER=${1:-${KUBECONFIG##*-}}
CLUSTER=${CLUSTER%.yml}
TMPFILE=/tmp/pods-tmp${RANDOM}
function finish {
rm -f "${TMPFILE}"
rm -f "${TMPFILE}.out"
}
trap finish EXIT
oldSize=0
if ! [[ "${KUBECONFIG}" == *"${CLUSTER}".yml ]]; then
bx config --check-version false
$(bx ks cluster-config -s --export ${CLUSTER})
fi
while true ; do
printf "Cluster: ${CLUSTER}\033[K\\n" > $TMPFILE
kubectl get ksvc --all-namespaces --no-headers < /dev/null > $TMPFILE.out 2>&1
IKS=$'\r\n' eval 'NSs=($(grep -v NAME $TMPFILE.out | sed "s/ .*//" | sort -u))'
printf "%-30s %-30s %-5s\033[K\\n" NS/NAME LATESTREADY READY >> $TMPFILE
cat $TMPFILE.out | while read ns name domain latestc latestr ready reason
do
[[ "${ns}" == "No" ]] && continue
# Shorten 'default' namespaced names
if [[ "${ns}" == "default" ]]; then
ns=""
else
ns="${ns}/"
fi
printf "%-30s %-30s %-5s\033[K\\n" "${ns}${name}" "${latestr}" "${ready}" >> $TMPFILE
done
printf "\033[K\\n" >> $TMPFILE # Blank line
read -s -n 1 -t 0.01 ch || true
if ! [[ "$ch" == "" ]]; then
break
fi
printf "%-55s %-15s %s\033[K\\n" POD_NAME STATUS AGE >> $TMPFILE
for ns in "${NSs[@]}"
do
kubectl get pods -n $ns --no-headers < /dev/null 2>&1 | while read name ready status restarts age
do
[[ "${name}" == "No" ]] && continue
[[ "${status}" == "Completed" ]] && continue
[[ "${status}" == "Terminating" ]] && continue
printf "%-55s %-15s %s\033[K\\n" "${name}" "${status}" "${age}" >> $TMPFILE
done
done
! [[ "${PIPESTATUS[0]}" == "0" ]] && exit 1
# printf "\033[K\\n" >> $TMPFILE # Blank line
if [[ "$oldSize" != "0" ]]; then
printf "\033[%dA" "${oldSize}"
fi
newSize=$(wc -l "${TMPFILE}" | sed "s/ .*//")
while (( oldSize > newSize )); do
printf "\033[K\\n" >> $TMPFILE
let oldSize=oldSize-1
done
cat $TMPFILE
oldSize=$(wc -l "${TMPFILE}" | sed "s/ .*//")
# rm -f $TMPFILE $TMPFILE.out
if [[ -n "${once}" ]]; then
break
fi
if [[ -n "${grepcmd}" ]]; then
set +e
grep "${grepcmd}" $TMPFILE > /dev/null 2>&1 && break
set -e
fi
if [[ -n "$untilcmd" ]]; then
set +e
bash -c " ${untilcmd} " >/dev/null 2>&1 && break
set -e
fi
read -s -n 1 -t 1 ch || true
if ! [[ "$ch" == "" ]]; then
break
fi
done