Skip to content

Wait for windows prepull images rather than sleeping #624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions test/k8s-integration/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"path/filepath"
"strings"
"syscall"
"time"

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

Expand Down
38 changes: 28 additions & 10 deletions test/k8s-integration/prepull-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,40 @@ set -o nounset
set -o pipefail
set -o xtrace

if [[ -z "${PREPULL_IMAGE}" ]]; then
# This is taken from prepull.yaml.
readonly prepull_daemonset=prepull-test-containers

wait_on_prepull()
{
# Wait up to 15 minutes for the test images to be pulled onto the nodes.
retries=90
while [[ $retries -ge 0 ]];do
ready=$(kubectl get daemonset "${prepull_daemonset}" -o jsonpath="{.status.numberReady}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this logic is similar to the other wait script, maybe we can consolidate to a common function later?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should probably move to client-go and have it in code. That's a bigger change than I want to do right now though.

Consolidating would mean have a shared bash include directory between deploy/kubernetes and test/k8s-integration which starts to get messy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#625 created for the client-go work.

required=$(kubectl get daemonset "${prepull_daemonset}" -o jsonpath="{.status.desiredNumberScheduled}")
if [[ $ready -eq $required ]];then
echo "Daemonset $prepull_daemonset ready"
return 0
fi
((retries--))
sleep 10s
done
echo "Timeout waiting for daemonset $prepull_daemonset"
return -1

}

if [[ -z "${PREPULL_YAML}" ]]; then
# Pre-pull all the test images. The images are currently hard-coded.
# Eventually, we should get the list directly from
# https://github.com/kubernetes-sigs/windows-testing/blob/master/images/PullImages.ps1
curl https://raw.githubusercontent.com/kubernetes-sigs/windows-testing/master/gce/prepull-1.18.yaml -o prepull.yaml
PREPULL_IMAGE=prepull.yaml
echo ${PREPULL_IMAGE}
PREPULL_YAML=prepull.yaml
echo ${PREPULL_YAML}
fi

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