Skip to content

Instantly share code, notes, and snippets.

@dudash
Last active April 21, 2022 19:42
Show Gist options
  • Save dudash/cf99565191a8110f76f66e4513fd710e to your computer and use it in GitHub Desktop.
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
#!/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."
@dudash
Copy link
Author

dudash commented Apr 21, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment