I'm using the following command to check if the namespace is active
kubectl wait --for=condition=items.status.phase=Active namespace/mynamespace --timeout=2s
This always returns "error: timed out waiting for the condition on namespaces/mynamespace" although the namespace is active. Is there a correct way to wait for the namespace to be active? This script is part of a job to check the namespace is active after a AKS cluster restart.
CodePudding user response:
To date status
is not a recognized condition
. Try:
while ! [ "$(kubectl get ns <change to your namespace> -o jsonpath='{.status.phase}')" == "Active" ]; do echo 'Waiting for namespace to come online. CTRL-C to exit.'; sleep 1; done
CodePudding user response:
timeout_value=3
starttime=$(date %s)
while [ $(( $(date %s) - $timeout_value )) -lt $starttime ]; do
status=$(kubectl get ns mynamespace -o jsonpath='{.status.phase}')
status=${status:-"X"}
echo $status
if [ "$status" == "Active" ];then
echo " test"
break
fi
done
Modified @gohm'c answer to include a timeout value of 3 seconds.