2016-05-20 03:04:58 +00:00
|
|
|
/*
|
2016-06-03 00:25:58 +00:00
|
|
|
Copyright 2016 The Kubernetes Authors.
|
2016-05-20 03:04:58 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package e2e_node
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os/exec"
|
2016-08-04 22:04:01 +00:00
|
|
|
"os/user"
|
2016-05-25 23:37:04 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/golang/glog"
|
2016-05-26 16:16:43 +00:00
|
|
|
|
2016-09-15 21:49:14 +00:00
|
|
|
"k8s.io/kubernetes/pkg/util/sets"
|
|
|
|
commontest "k8s.io/kubernetes/test/e2e/common"
|
2016-05-26 16:16:43 +00:00
|
|
|
"k8s.io/kubernetes/test/e2e/framework"
|
2016-05-20 03:04:58 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2016-05-25 23:37:04 +00:00
|
|
|
// Number of attempts to pull an image.
|
|
|
|
maxImagePullRetries = 5
|
|
|
|
// Sleep duration between image pull retry attempts.
|
|
|
|
imagePullRetryDelay = time.Second
|
2016-05-20 03:04:58 +00:00
|
|
|
)
|
|
|
|
|
2016-09-15 21:49:14 +00:00
|
|
|
// NodeImageWhiteList is a list of images used in node e2e test. These images will be prepulled
|
|
|
|
// before test running so that the image pulling won't fail in actual test.
|
|
|
|
var NodeImageWhiteList = sets.NewString(
|
|
|
|
"google/cadvisor:latest",
|
|
|
|
"gcr.io/google-containers/stress:v1",
|
|
|
|
"gcr.io/google_containers/busybox:1.24",
|
|
|
|
"gcr.io/google_containers/nginx-slim:0.7",
|
|
|
|
"gcr.io/google_containers/serve_hostname:v1.4",
|
2016-10-04 21:46:03 +00:00
|
|
|
"gcr.io/google_containers/netexec:1.7",
|
2016-09-15 21:49:14 +00:00
|
|
|
framework.GetPauseImageNameForHostArch(),
|
|
|
|
)
|
2016-05-20 03:04:58 +00:00
|
|
|
|
2016-09-15 21:49:14 +00:00
|
|
|
func init() {
|
|
|
|
// Union NodeImageWhiteList and CommonImageWhiteList into the framework image white list.
|
|
|
|
framework.ImageWhiteList = NodeImageWhiteList.Union(commontest.CommonImageWhiteList)
|
2016-05-20 03:04:58 +00:00
|
|
|
}
|
|
|
|
|
2016-09-15 21:49:14 +00:00
|
|
|
// Pre-fetch all images tests depend on so that we don't fail in an actual test.
|
2016-05-20 03:04:58 +00:00
|
|
|
func PrePullAllImages() error {
|
2016-08-04 22:04:01 +00:00
|
|
|
usr, err := user.Current()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-09-15 21:49:14 +00:00
|
|
|
images := framework.ImageWhiteList.List()
|
|
|
|
glog.V(4).Infof("Pre-pulling images %+v", images)
|
|
|
|
for _, image := range images {
|
2016-05-25 23:37:04 +00:00
|
|
|
var (
|
|
|
|
err error
|
|
|
|
output []byte
|
|
|
|
)
|
2016-06-03 23:37:58 +00:00
|
|
|
for i := 0; i < maxImagePullRetries; i++ {
|
|
|
|
if i > 0 {
|
|
|
|
time.Sleep(imagePullRetryDelay)
|
|
|
|
}
|
2016-09-15 21:49:14 +00:00
|
|
|
// TODO(random-liu): Use docker client to get rid of docker binary dependency.
|
2016-05-25 23:37:04 +00:00
|
|
|
if output, err = exec.Command("docker", "pull", image).CombinedOutput(); err == nil {
|
|
|
|
break
|
|
|
|
}
|
2016-08-04 22:04:01 +00:00
|
|
|
glog.Warningf("Failed to pull %s as user %q, retrying in %s (%d of %d): %v",
|
|
|
|
image, usr.Username, imagePullRetryDelay.String(), i+1, maxImagePullRetries, err)
|
2016-05-25 23:37:04 +00:00
|
|
|
}
|
2016-05-20 03:04:58 +00:00
|
|
|
if err != nil {
|
2016-05-24 18:34:40 +00:00
|
|
|
glog.Warningf("Could not pre-pull image %s %v output: %s", image, err, output)
|
2016-05-20 03:04:58 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|