Last active
September 24, 2019 14:32
-
-
Save icy/67009e41829b8c5afec92b29b390c536 to your computer and use it in GitHub Desktop.
sys_wait_for_k8s_object.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# purpse: wait for k8s objects to be ready | |
# author: icy | |
# license: mit | |
# usage 1: sys_wait_for_k8s_object pods | |
# usage 2: sys_wait_for_k8s_object services | |
sys_wait_for_k8s_object() { | |
kind="$1" | |
set +xe | |
echo -n ":: Wating for the $kind: " | |
retries=180 | |
while (( retries )); do | |
kubectl get "$kind" --all-namespaces \ | |
| grep -qsEie "(0/[1-9])|(pending)|(creating)|(init)|(error)|(ImagePullBackOff)|(ErrImagePull)|(CrashLoopBackOff)" | |
if [[ $? -ge 1 ]]; then | |
break | |
fi | |
echo -n "[$retries]" | |
sleep 1s | |
(( retries -- )) | |
done || true | |
echo | |
set -xe | |
kubectl get "$kind" --all-namespaces | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment