-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwaitpods.sh
More file actions
executable file
·56 lines (41 loc) · 1.2 KB
/
waitpods.sh
File metadata and controls
executable file
·56 lines (41 loc) · 1.2 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env bash
# Copyright 2017, Z Lab Corporation. All rights reserved.
# Copyright 2017, Kubernetes scripts contributors
#
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.
set -e
function __is_pod_ready() {
[[ "$(kubectl get po "$1" -o 'jsonpath={.status.conditions[?(@.type=="Ready")].status}')" == 'True' ]]
}
function __pods_ready() {
local pod
[[ "$#" == 0 ]] && return 0
for pod in $pods; do
__is_pod_ready "$pod" || return 1
done
return 0
}
function __wait-until-pods-ready() {
local period interval i pods
if [[ $# != 2 ]]; then
echo "Usage: wait-until-pods-ready PERIOD INTERVAL" >&2
echo "" >&2
echo "This script waits for all pods to be ready in the current namespace." >&2
return 1
fi
period="$1"
interval="$2"
for ((i=0; i<$period; i+=$interval)); do
pods="$(kubectl get po -o 'jsonpath={.items[*].metadata.name}')"
if __pods_ready $pods; then
return 0
fi
echo "Waiting for pods to be ready..."
sleep "$interval"
done
echo "Waited for $period seconds, but all pods are not ready yet."
return 1
}
__wait-until-pods-ready $@
# vim: ft=sh :