Skip to content

Instantly share code, notes, and snippets.

@Arka111
Created August 22, 2022 10:09
Show Gist options
  • Save Arka111/a2ec84bb4422b9370d9dd57a2bbd157d to your computer and use it in GitHub Desktop.
Save Arka111/a2ec84bb4422b9370d9dd57a2bbd157d to your computer and use it in GitHub Desktop.
#!/bin/bash
set -xv
# pod is the pod name
pod=$1
[ -z "${pod}" ] && echo "ERROR: Pod name not passed" && exit 1
# ns is namespace. Defaults to 'default'
ns=$2
[ -z "${ns}" ] && ns='default'
# Return code
result=1
p=$(kubectl get pods --namespace ${ns} | grep "${pod}")
if [ -n "${p}" ]; then
pod_name=$(echo -n "${p}" | awk '{print $1}')
ready=$(echo -n "${p}" | awk '{print $2}')
ready_actual=$(echo -n "${ready}" | awk -F/ '{print $1}')
ready_max=$(echo -n "${ready}" | awk -F/ '{print $2}')
status=$(echo -n "${p}" | awk '{print $3}')
echo "... pod ${pod_name}; ready is ${ready}; ready_actual is ${ready_actual}; ready_max is ${ready_max}; status is ${status}"
if [ "${ready_actual}" == "${ready_max}" ] && [ "${status}" == "Running" ]; then
result=0
fi
else
echo "ERROR: Pod ${pod} not found"
fi
echo "Result: ${result}"
exit ${result}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment