forked from eldada/kubernetes-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
podReady.sh
executable file
·83 lines (63 loc) · 1.62 KB
/
podReady.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
#!/bin/bash
# set -x
## Simple script to check if pod is really ready.
# Check containers are ready
# Return 1 if not ready. Return 0 if ready.
NAMESPACE=default
POD=
errorExit () {
echo -e "\nERROR: $1\n"
exit 1
}
usage () {
cat << END_USAGE
${SCRIPT_NAME} - Get pod readiness (all containers ready).
Exit with 0 of all containers are ready. Exit with 1 if not.
Usage: ${SCRIPT_NAME} <options>
-n | --namespace <name> : Namespace. Default: default
-p | --pod <name> : Pod to check
-h | --help : Show this usage
Examples:
========
$ ${SCRIPT_NAME} --namespace test --pod nginx-1234asdf
END_USAGE
exit 1
}
# Process command line options. See usage above for supported options
processOptions () {
while [[ $# -gt 0 ]]; do
case "$1" in
-n | --namespace)
NAMESPACE="$2"
shift 2
;;
-p | --pod)
POD="$2"
shift 2
;;
-h | --help)
usage
exit 0
;;
*)
usage
;;
esac
done
if [[ -z "${POD}" ]]; then errorExit "Pod not passed"; fi
}
checkPod () {
local ready_status
ready_status=$(kubectl get pod -n ${NAMESPACE} ${POD} --output=jsonpath='{.status.containerStatuses[*].ready}')
# Leave only unique words
ready_status=$(echo "$ready_status" | tr ' ' '\n' | sort -u)
[[ $ready_status =~ ^true$ ]] && return 0
return 1
}
main () {
processOptions "$@"
checkPod && exit 0
exit 1
}
######### Main #########
main "$@"