Go client SDK: check if a Deployment is fully ready

7/9/2019

Say I have an in-memory Deployment object, what is the correct way of testing if it is fully ready? (not in the progress of rollout, upgrade or rollback).

-- Dagang
kubernetes

1 Answer

7/9/2019

I can't comment, so it will have to be an answer.


I don't think there is a right way of doing this, as it depends on a number of variables. Such as what languages you are proficient with etc.

Where I work, we run a kubectl get pods and grep the information that is relevant (in this case if the pod is available (ready) or not. This is all run through bash as part of a startup script:

function not_ready_count() {
  kubectl ${1} get pods -o json | jq -r '.items[].status.conditions[].status' | grep False | wc -l | awk '{ print $1 }'
}

function not_running_count() {
  kubectl ${1} get pods -o json | jq -r '.items[].status.phase' | grep -v Running | wc -l | awk '{ print $1 }'
}

function wait_until_running_and_ready() {
  sleep 2
  while [[ "$(not_running_count ${1})" != "0" ]]; do
    echo "waiting for $(not_ready_count ${1}) pods to start"
    sleep 3
  done
  while [[ "$(not_ready_count ${1})" != "0" ]]; do
    echo "waiting for $(not_ready_count ${1}) status probes to pass"
    sleep 3
  done
  sleep 2
}
-- Todai
Source: StackOverflow