'How to check if a namespace is active
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.
Solution 1:[1]
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
Solution 2:[2]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | gohm'c |
| Solution 2 | Rajesh Kazhankodath |
