Last active
April 21, 2022 19:42
-
-
Save dudash/cf99565191a8110f76f66e4513fd710e to your computer and use it in GitHub Desktop.
OpenShift CLI wait for argument pod to go "Running" - or prompt if no pod name given
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
#!/bin/bash | |
# Simple script to wait for named pod | |
# | |
# if no arguments are specified it will prompt | |
# if 1 argument is specified it will look for a pod with that name | |
# if more than 1 argument is specified it will only use the 1st and ignore the rest | |
# | |
# tested against oc 3.9 - might not work with other versions | |
if [ $# -eq 0 ] | |
then | |
prompt="Please select an deployment:" | |
options=( $(oc get pod -o name) ) | |
PS3="$prompt " | |
select opt in "${options[@]}" "Quit" ; do | |
if (( REPLY == 1 + ${#options[@]} )) ; then | |
exit | |
elif (( REPLY > 0 && REPLY <= ${#options[@]} )) ; then | |
echo "You picked $REPLY" | |
break | |
else | |
echo "Invalid option. Try another one." | |
fi | |
done | |
echo "Waiting for $opt pod to start. You can safely exit this with Ctrl+C or just wait." | |
until | |
oc get $opt | grep -m 1 "Running" | |
do | |
oc get $opt | |
sleep 2 | |
done | |
echo "Yay, $opt is ready." | |
exit 1 | |
fi | |
echo "Waiting for $1 pod to start. You can safely exit this with Ctrl+C or just wait." | |
until | |
oc get pods -l name=$1 | grep -m 1 "Running" | |
do | |
oc get pods -l name=$1 | |
sleep 2 | |
done | |
echo "Yay, $1 is ready." | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
oc
andkubctl
havewait
. So you might not need this gist anymore.e.g.:
oc wait --for=condition=Ready=false pod/busybox1