Skip to content

Commit a584a36

Browse files
committed
deploy: wait until pods are up and snapshotter added the CRD
This is crucial because otherwise creating the snapshotter class can fail (depending on timing). This is also useful because the caller then can be sure that the driver installation has succeeded, without having to know details about the pods that belong to the driver.
1 parent d9a83c2 commit a584a36

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ statefulset.apps/csi-hostpath-provisioner created
5353
using image: quay.io/k8scsi/csi-snapshotter:v1.0.1
5454
service/csi-hostpath-snapshotter created
5555
statefulset.apps/csi-hostpath-snapshotter created
56+
23:04:27 waiting for hostpath deployment to complete, attempt #0
57+
23:04:38 waiting for hostpath deployment to complete, attempt #1
58+
23:04:48 waiting for hostpath deployment to complete, attempt #2
5659
deploying snapshotclass
5760
volumesnapshotclass.snapshot.storage.k8s.io/csi-hostpath-snapclass created
5861
```

deploy/deploy-hostpath.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,24 @@ for i in $(ls ${BASE_DIR}/hostpath/*.yaml | sort); do
138138
done | kubectl apply -f -
139139
done
140140

141+
# Wait until all pods are running. We have to make some assumptions
142+
# about the deployment here, otherwise we wouldn't know what to wait
143+
# for: the expectation is that we run attacher, provisioner,
144+
# snapshotter and hostpath plugin in the default namespace.
145+
cnt=0
146+
while [ $(kubectl get pods 2>/dev/null | grep '^csi-hostpath.* Running ' | wc -l) -lt 4 ] || ! kubectl describe volumesnapshotclasses.snapshot.storage.k8s.io 2>/dev/null >/dev/null; do
147+
if [ $cnt -gt 30 ]; then
148+
echo "Running pods:"
149+
kubectl describe pods
150+
151+
echo >&2 "ERROR: hostpath deployment not ready after over 5min"
152+
exit 1
153+
fi
154+
echo $(date +%H:%M:%S) "waiting for hostpath deployment to complete, attempt #$cnt"
155+
cnt=$(($cnt + 1))
156+
sleep 10
157+
done
158+
141159
# deploy snapshotclass
142160
echo "deploying snapshotclass"
143161
kubectl create -f ${BASE_DIR}/snapshotter/csi-hostpath-snapshotclass.yaml

0 commit comments

Comments
 (0)