Skip to content

Commit 3cd77f8

Browse files
authored
Merge pull request #624 from mattcary/prepull-wait
Wait for windows prepull images rather than sleeping
2 parents 63d6417 + 17a09dd commit 3cd77f8

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

test/k8s-integration/main.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"path/filepath"
2323
"strings"
2424
"syscall"
25-
"time"
2625

2726
"k8s.io/apimachinery/pkg/util/uuid"
2827
apimachineryversion "k8s.io/apimachinery/pkg/util/version"
@@ -327,15 +326,14 @@ func handle() error {
327326
// It typically takes 5+ minutes to download Windows container image. To avoid tests being timed out,
328327
// pre-pulling the test images as best effort.
329328
klog.Infof("Prepulling test images.")
330-
err = os.Setenv("PREPULL_IMAGE", filepath.Join(pkgDir, "test", "k8s-integration", "prepull.yaml"))
329+
err = os.Setenv("PREPULL_YAML", filepath.Join(pkgDir, "test", "k8s-integration", "prepull.yaml"))
331330
if err != nil {
332331
return err
333332
}
334333
out, err = exec.Command(filepath.Join(pkgDir, "test", "k8s-integration", "prepull-image.sh")).CombinedOutput()
335334
if err != nil {
336335
return fmt.Errorf("failed to prepull images: %s, err: %v", out, err)
337336
}
338-
time.Sleep(10 * time.Minute)
339337
out, err = exec.Command("kubectl", "describe", "pods", "-n", getDriverNamespace()).CombinedOutput()
340338
klog.Infof("describe pods \n %s", string(out))
341339

test/k8s-integration/prepull-image.sh

+28-10
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,40 @@ set -o nounset
44
set -o pipefail
55
set -o xtrace
66

7-
if [[ -z "${PREPULL_IMAGE}" ]]; then
7+
# This is taken from prepull.yaml.
8+
readonly prepull_daemonset=prepull-test-containers
9+
10+
wait_on_prepull()
11+
{
12+
# Wait up to 15 minutes for the test images to be pulled onto the nodes.
13+
retries=90
14+
while [[ $retries -ge 0 ]];do
15+
ready=$(kubectl get daemonset "${prepull_daemonset}" -o jsonpath="{.status.numberReady}")
16+
required=$(kubectl get daemonset "${prepull_daemonset}" -o jsonpath="{.status.desiredNumberScheduled}")
17+
if [[ $ready -eq $required ]];then
18+
echo "Daemonset $prepull_daemonset ready"
19+
return 0
20+
fi
21+
((retries--))
22+
sleep 10s
23+
done
24+
echo "Timeout waiting for daemonset $prepull_daemonset"
25+
return -1
26+
27+
}
28+
29+
if [[ -z "${PREPULL_YAML}" ]]; then
830
# Pre-pull all the test images. The images are currently hard-coded.
931
# Eventually, we should get the list directly from
1032
# https://github.com/kubernetes-sigs/windows-testing/blob/master/images/PullImages.ps1
1133
curl https://raw.githubusercontent.com/kubernetes-sigs/windows-testing/master/gce/prepull-1.18.yaml -o prepull.yaml
12-
PREPULL_IMAGE=prepull.yaml
13-
echo ${PREPULL_IMAGE}
34+
PREPULL_YAML=prepull.yaml
35+
echo ${PREPULL_YAML}
1436
fi
1537

16-
kubectl create -f ${PREPULL_IMAGE}
17-
# Wait 10 minutes for the test images to be pulled onto the nodes.
18-
sleep 15m
19-
echo "sleep 15m"
38+
kubectl create -f ${PREPULL_YAML}
39+
wait_on_prepull || exit -1 # Error already printed
2040
# Check the status of the pods.
2141
kubectl get pods -o wide
2242
# Delete the pods anyway since pre-pulling is best-effort
23-
kubectl delete -f ${PREPULL_IMAGE}
24-
# Wait a few more minutes for the pod to be cleaned up.
25-
sleep 5m
43+
kubectl delete -f ${PREPULL_YAML} --wait=true

0 commit comments

Comments
 (0)