-
Notifications
You must be signed in to change notification settings - Fork 3
/
wait-for-it.sh
executable file
·37 lines (30 loc) · 1.14 KB
/
wait-for-it.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
# Label to identify the deployment and pod
LABEL="app.kubernetes.io/instance=zoo-project-dru"
NAMESPACE="zoo"
# Function to get the status of the deployment
get_deployment_status() {
kubectl get deployment zoo-project-dru-zookernel -n $NAMESPACE -o "jsonpath={.status.availableReplicas}"
}
# Function to get the status of the pod
get_pod_status() {
kubectl get pods -l $LABEL -n $NAMESPACE -o "jsonpath={.items[0].status.phase}"
}
# Check if the deployment and pod are running
while true; do
# Get the current status of the deployment
DEPLOYMENT_STATUS=$(get_deployment_status)
echo "Deployment replicas: $DEPLOYMENT_STATUS"
# Get the current status of the pod
POD_STATUS=$(get_pod_status)
echo "Pod status: $POD_STATUS"
# Check if the deployment has 1 available replica and the pod is running
if [ "$DEPLOYMENT_STATUS" = "1" ] && [ "$POD_STATUS" = "Running" ]; then
echo "Deployment with label $LABEL is running and a pod is in Running state"
break
else
echo "Waiting for deployment and pod to be running..."
fi
# Wait for 5 seconds before checking again
sleep 5
done