Skip to content

Instantly share code, notes, and snippets.

@icy
Last active September 24, 2019 14:32
Show Gist options
  • Save icy/67009e41829b8c5afec92b29b390c536 to your computer and use it in GitHub Desktop.
Save icy/67009e41829b8c5afec92b29b390c536 to your computer and use it in GitHub Desktop.
sys_wait_for_k8s_object.sh
# 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