Skip to content

Commit a67afef

Browse files
committed
make pod ready status check precise
1 parent 9a95af3 commit a67afef

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

start.bash

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ if [[ "$(whoami)" != "root" ]]; then
1616
exit
1717
fi
1818

19-
echo "Docker pull dependency images ..."
19+
echo "Docker pull dependency images, you can comment this if already have them ..."
2020
# c.f. https://github.com/sql-machine-learning/sqlflow/blob/develop/.travis.yml
2121
docker pull sqlflow/sqlflow:jupyter
2222
docker pull sqlflow/sqlflow:mysql
2323
docker pull sqlflow/sqlflow:server
2424
docker pull sqlflow/sqlflow:step
2525
docker pull argoproj/argoexec:v2.7.7
26+
docker pull argoproj/argocli:v2.7.7
27+
docker pull argoproj/workflow-controller:v2.7.7
2628
echo "Done."
2729

2830
# NOTE: According to https://stackoverflow.com/a/16619261/724872,
@@ -40,15 +42,17 @@ set +e
4042
# "$3" is expected output
4143
function wait_until() {
4244
echo -n "Waiting for $1 "
43-
while [[ true ]]; do
45+
for i in {1..50}; do
4446
$2 | grep -o -q "$3"
4547
if [[ $? -eq 0 ]]; then
46-
break
48+
echo "Done"
49+
return
4750
fi
4851
echo -n "."
4952
sleep 3
5053
done
51-
echo "Done"
54+
echo "Fail"
55+
exit
5256
}
5357

5458
# Use a faster kube image and docker registry
@@ -73,50 +77,49 @@ fi
7377

7478
wait_until "minikube" "minikube status" "apiserver: Running"
7579

76-
# Test if a Kubernetes resource is alive
80+
# Test if a Kubernetes pod is ready
7781
# "$1" shoulde be namespace id e.g. argo
78-
# "$2" should be resource id e.g. pod/argo-server
79-
function is_resource_alive() {
80-
local type=$(echo "$2" | cut -d / -f1)
81-
local name=$(echo "$2" | cut -d / -f2)
82-
if kubectl get -n "$1" "$2" 2>/dev/null | grep -q -o "$name" >/dev/null; then
83-
# make sure relative pod is alive
84-
if kubectl get pod -n "$1" 2>/dev/null | grep "$name" | grep "Running" >/dev/null; then
85-
echo "yes"
86-
else
87-
echo "no"
88-
fi
82+
# "$2" should be pod selector e.g. k8s-app=kubernetes-dashboard
83+
function is_pod_ready() {
84+
pod=$(kubectl get pod -n "$1" -l "$2" -o name | tail -1)
85+
if [[ -z "$pod" ]]; then
86+
echo "no"
87+
return
88+
fi
89+
ready=$(kubectl get -n "$1" "$pod" -o jsonpath='{.status.containerStatuses[0].ready}')
90+
if [[ "$ready" == "true" ]]; then
91+
echo "yes"
8992
else
9093
echo "no"
9194
fi
9295
}
9396

9497
echo "Start argo ..."
95-
argo_server_alive=$(is_resource_alive "argo" "service/argo-server")
98+
argo_server_alive=$(is_pod_ready "argo" "app=argo-server")
9699
if [[ "$argo_server_alive" == "yes" ]]; then
97100
echo "Already in running."
98101
else
99102
$(dirname $0)/sqlflow/scripts/travis/start_argo.sh
100103
fi
101-
wait_until "argo" "is_resource_alive argo service/argo-server" "yes"
104+
wait_until "argo" "is_pod_ready argo app=argo-server" "yes"
102105

103106
echo "Strat Kubernetes Dashboard ..."
104-
dashboard_alive=$(is_resource_alive "kubernetes-dashboard" "service/kubernetes-dashboard")
107+
dashboard_alive=$(is_pod_ready "kubernetes-dashboard" "k8s-app=kubernetes-dashboard")
105108
if [[ "$dashboard_alive" == "yes" ]]; then
106109
echo "Already in running."
107110
else
108-
nohup minikube dashboard &
111+
nohup minikube dashboard >/dev/null 2>&1 &
109112
fi
110-
wait_until "Kubernetes Dashboard" "is_resource_alive kubernetes-dashboard service/kubernetes-dashboard" "yes"
113+
wait_until "Kubernetes Dashboard" "is_pod_ready kubernetes-dashboard k8s-app=kubernetes-dashboard" "yes"
111114

112115
echo "Strat SQLFlow ..."
113-
sqlflow_alive=$(is_resource_alive "default" "pod/sqlflow-server")
116+
sqlflow_alive=$(is_pod_ready "default" "app=sqlflow-server")
114117
if [[ "$sqlflow_alive" == "yes" ]]; then
115118
echo "Already in running."
116119
else
117120
kubectl apply -f sqlflow/doc/run/k8s/install-sqlflow.yaml
118121
fi
119-
wait_until "SQLFlow" "is_resource_alive default pod/sqlflow-server" "yes"
122+
#wait_until "SQLFlow" "is_pod_ready default app=sqlflow-server" "yes"
120123

121124
# Kill port exposing if it already exist
122125
function stop_expose() {

0 commit comments

Comments
 (0)