forked from eldada/kubernetes-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpodReady.sh
More file actions
executable file
·40 lines (31 loc) · 1.11 KB
/
podReady.sh
File metadata and controls
executable file
·40 lines (31 loc) · 1.11 KB
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
#!/bin/bash
## Simple script to check if pod is really ready.
# Check status is 'Running' and that all containers are ready.
# Return 1 is not ready. Return 0 is ready.
# pod is the pod name
pod=$1
[ -z "${pod}" ] && echo "ERROR: Pod name not passed" && exit 1
# ns is namespace. Defaults to 'default'
ns=$2
[ -z "${ns}" ] && ns='default'
# Return code
result=1
# Get the pod record from 'kubectl get pods'
p=$(kubectl get pods -n ${ns} | grep "${pod}")
if [ ! -z "${p}" ]; then
pod_name=$(echo -n ${p} | awk '{print $1}')
ready=$(echo -n ${p} | awk '{print $2}')
ready_actual=$(echo -n ${ready} | awk -F/ '{print $1}')
ready_max=$(echo -n ${ready} | awk -F/ '{print $2}')
status=$(echo -n ${p} | awk '{print $3}')
## Uncomment to see output
# echo "... pod ${pod_name}; ready is ${ready}; ready_actual is ${ready_actual}; ready_max is ${ready_max}; status is ${status}"
if [ "${ready_actual}" == "${ready_max}" ] && [ "${status}" == "Running" ]; then
result=0
fi
else
echo "ERROR: Pod ${pod} not found"
fi
## Uncomment to see output
# echo "Result: ${result}"
exit ${result}