Skip to content

Commit 63d6417

Browse files
authored
Merge pull request #620 from mattcary/wait
Wait on driver deployment rather than sleep
2 parents 292b299 + 494d11d commit 63d6417

File tree

2 files changed

+59
-10
lines changed

2 files changed

+59
-10
lines changed

deploy/kubernetes/wait-for-driver.sh

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
# This script waits for the deployments from ./deploy-driver.sh to be ready.
4+
5+
print_usage()
6+
{
7+
printf "wait-for-driver.sh [--windows]\n"
8+
printf "\t--windows: wait on the windows deployment rather than linux"
9+
echo
10+
}
11+
12+
node_daemonset=csi-gce-pd-node
13+
while [[ -n "${1-}" ]]; do
14+
case $1 in
15+
--windows ) shift
16+
node_daemonset=csi-gce-pd-node-win
17+
;;
18+
-h | --help ) print_usage
19+
exit 1
20+
;;
21+
* ) print_usage
22+
exit 1
23+
;;
24+
esac
25+
done
26+
27+
kubectl wait -n gce-pd-csi-driver deployment csi-gce-pd-controller --for condition=available
28+
29+
retries=90
30+
while [[ $retries -ge 0 ]];do
31+
ready=$(kubectl -n gce-pd-csi-driver get daemonset "${node_daemonset}" -o jsonpath="{.status.numberReady}")
32+
required=$(kubectl -n gce-pd-csi-driver get daemonset "${node_daemonset}" -o jsonpath="{.status.desiredNumberScheduled}")
33+
if [[ $ready -eq $required ]];then
34+
echo "Daemonset $node_daemonset found"
35+
exit 0
36+
fi
37+
((retries--))
38+
sleep 10s
39+
done
40+
echo "Timeout waiting for node daemonset $node_daemonset"
41+
exit -1
42+

test/k8s-integration/driver.go

+17-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"os"
77
"os/exec"
88
"path/filepath"
9-
"time"
109

1110
"k8s.io/klog"
1211
"k8s.io/kubernetes/test/e2e/framework/podlogs"
@@ -77,19 +76,27 @@ func installDriver(platform, goPath, pkgDir, stagingImage, stagingVersion, deplo
7776
deployEnv = append(deployEnv,
7877
fmt.Sprintf("GOPATH=%s", goPath),
7978
fmt.Sprintf("GCE_PD_DRIVER_VERSION=%s", deployOverlayName))
80-
deployCmd.Env = append(os.Environ(), deployEnv...)
79+
deployEnv = append(os.Environ(), deployEnv...)
80+
deployCmd.Env = deployEnv
8181
err := runCommand("Deploying driver", deployCmd)
8282
if err != nil {
83-
return fmt.Errorf("failed to deploy driver: %v", err)
83+
return fmt.Errorf("failed to deploy driver: %w", err)
84+
}
85+
86+
waitScript := filepath.Join(pkgDir, "deploy", "kubernetes", "wait-for-driver.sh")
87+
waitCmd := exec.Command(waitScript)
88+
waitCmd.Env = deployEnv
89+
err = runCommand("Waiting for driver to start", waitCmd)
90+
if err != nil {
91+
return fmt.Errorf("driver failed to come up: %w", err)
8492
}
85-
klog.Infof("Deploying driver")
86-
// TODO (#139): wait for driver to be running
8793
if platform == "windows" {
88-
klog.Infof("Waiting 15 minutes for the driver to start on Windows")
89-
time.Sleep(15 * time.Minute)
90-
} else {
91-
klog.Infof("Waiting 5 minutes for the driver to start on Linux")
92-
time.Sleep(5 * time.Minute)
94+
waitCmd = exec.Command(waitScript, "--windows")
95+
waitCmd.Env = deployEnv
96+
err = runCommand("Waiting for windows deployment to start", waitCmd)
97+
if err != nil {
98+
return fmt.Errorf("Windows deployment failed to come up: %w", err)
99+
}
93100
}
94101
out, err := exec.Command("kubectl", "describe", "pods", "-n", getDriverNamespace()).CombinedOutput()
95102
klog.Infof("describe pods \n %s", string(out))

0 commit comments

Comments
 (0)