-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_pods.sh
executable file
·41 lines (35 loc) · 1.39 KB
/
check_pods.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
#!/bin/sh
# vim: ts=4 sw=4
# assumes you have either KUBECONFIG set of did oc login before as cluster admin
pending=$( oc get pod -A -o jsonpath="{.items[?(@.status.phase=='Pending')].metadata.namespace}" )
#running=$( oc get pod -A -o jsonpath="{.items[?(@.status.phase=='Running')].metadata.namespace}" )
#succeeded=$( oc get pod -A -o jsonpath="{.items[?(@.status.phase=='Succeeded')].metadata.namespace}" )
failed=$( oc get pod -A -o jsonpath="{.items[?(@.status.phase=='Failed')].metadata.namespace}" )
unknown=$( oc get pod -A -o jsonpath="{.items[?(@.status.phase=='Unknown')].metadata.namespace}" )
if [ -n "${failed}" -o -n "${unknown}" -o -n "${pending}" ]
then
if [ -n "${failed}" ]
then
echo '✘ Namespaces with failed pods:'
echo "✘ $( echo ${failed} | tr ' ' '\n' | sort | uniq )"
else
echo "✔ There are no failed pods."
fi
if [ -n "${unknown}" ]
then
echo '✘ Namespaces with pods in an unknown stage:'
echo "✘ $( echo ${unknown} | tr ' ' '\n' | sort | uniq )"
else
echo "✔ There are no pods in an unknown state."
fi
if [ -n "${pending}" ]
then
echo '✘ Namespaces with pending pods:'
echo "✘ $( echo ${pending} | tr ' ' '\n' | sort | uniq )"
else
echo "✔ There are no pending pods."
fi
exit 1
else
echo "✔ All pods are either running or succeeded."
fi