Skip to content

Commit 453efd7

Browse files
authored
Merge pull request kubernetes#121604 from pacoxu/image-pull-e2e
[node-e2e] add test cases for serialize and parallel image pulling
2 parents 7c56aa5 + 82df7a7 commit 453efd7

File tree

8 files changed

+386
-18
lines changed

8 files changed

+386
-18
lines changed

test/e2e_node/criproxy_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3333
"k8s.io/apimachinery/pkg/util/uuid"
3434
kubeletevents "k8s.io/kubernetes/pkg/kubelet/events"
35+
"k8s.io/kubernetes/pkg/kubelet/images"
3536
"k8s.io/kubernetes/test/e2e/feature"
3637
"k8s.io/kubernetes/test/e2e/framework"
3738
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
@@ -68,7 +69,12 @@ var _ = SIGDescribe(feature.CriProxy, framework.WithSerial(), func() {
6869
framework.ExpectNoError(err)
6970

7071
pod := e2epod.NewPodClient(f).Create(ctx, newPullImageAlwaysPod())
71-
podErr := e2epod.WaitForPodRunningInNamespace(ctx, f.ClientSet, pod)
72+
podErr := e2epod.WaitForPodCondition(ctx, f.ClientSet, f.Namespace.Name, pod.Name, "ImagePullBackOff", 1*time.Minute, func(pod *v1.Pod) (bool, error) {
73+
if len(pod.Status.ContainerStatuses) > 0 && pod.Status.Reason == images.ErrImagePullBackOff.Error() {
74+
return true, nil
75+
}
76+
return false, nil
77+
})
7278
gomega.Expect(podErr).To(gomega.HaveOccurred())
7379

7480
eventMsg, err := getFailedToPullImageMsg(ctx, f, pod.Name)

test/e2e_node/e2e_node_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ var _ = ginkgo.SynchronizedBeforeSuite(func(ctx context.Context) []byte {
240240
if framework.TestContext.PrepullImages {
241241
klog.Infof("Pre-pulling images so that they are cached for the tests.")
242242
updateImageAllowList(ctx)
243-
err := PrePullAllImages()
243+
err := PrePullAllImages(ctx)
244244
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
245245
}
246246

test/e2e_node/eviction_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,8 @@ func runEvictionTest(f *framework.Framework, pressureTimeout time.Duration, expe
647647
if expectedNodeCondition == v1.NodeDiskPressure && framework.TestContext.PrepullImages {
648648
// The disk eviction test may cause the prepulled images to be evicted,
649649
// prepull those images again to ensure this test not affect following tests.
650-
PrePullAllImages()
650+
err := PrePullAllImages(ctx)
651+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
651652
}
652653
}
653654
// Run prePull using a defer to make sure it is executed even when the assertions below fails

test/e2e_node/image_gc_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ var _ = SIGDescribe("ImageGarbageCollect", framework.WithSerial(), framework.Wit
5050
_, is, err = getCRIClient()
5151
framework.ExpectNoError(err)
5252
})
53-
ginkgo.AfterEach(func() {
54-
framework.ExpectNoError(PrePullAllImages())
53+
ginkgo.AfterEach(func(ctx context.Context) {
54+
framework.ExpectNoError(PrePullAllImages(ctx))
5555
})
5656
ginkgo.Context("when ImageMaximumGCAge is set", func() {
5757
tempSetCurrentKubeletConfig(f, func(ctx context.Context, initialConfig *kubeletconfig.KubeletConfiguration) {

test/e2e_node/image_list.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ func getNodeProblemDetectorImage() string {
110110
// puller represents a generic image puller
111111
type puller interface {
112112
// Pull pulls an image by name
113-
Pull(image string) ([]byte, error)
113+
Pull(ctx context.Context, image string) ([]byte, error)
114+
// Remove removes an image by name
115+
Remove(ctx context.Context, image string) error
114116
// Name returns the name of the specific puller implementation
115117
Name() string
116118
}
@@ -123,15 +125,19 @@ func (rp *remotePuller) Name() string {
123125
return "CRI"
124126
}
125127

126-
func (rp *remotePuller) Pull(image string) ([]byte, error) {
127-
resp, err := rp.imageService.ImageStatus(context.Background(), &runtimeapi.ImageSpec{Image: image}, false)
128+
func (rp *remotePuller) Pull(ctx context.Context, image string) ([]byte, error) {
129+
resp, err := rp.imageService.ImageStatus(ctx, &runtimeapi.ImageSpec{Image: image}, false)
128130
if err == nil && resp.GetImage() != nil {
129131
return nil, nil
130132
}
131-
_, err = rp.imageService.PullImage(context.Background(), &runtimeapi.ImageSpec{Image: image}, nil, nil)
133+
_, err = rp.imageService.PullImage(ctx, &runtimeapi.ImageSpec{Image: image}, nil, nil)
132134
return nil, err
133135
}
134136

137+
func (rp *remotePuller) Remove(ctx context.Context, image string) error {
138+
return rp.imageService.RemoveImage(ctx, &runtimeapi.ImageSpec{Image: image})
139+
}
140+
135141
func getPuller() (puller, error) {
136142
_, is, err := getCRIClient()
137143
if err != nil {
@@ -143,7 +149,7 @@ func getPuller() (puller, error) {
143149
}
144150

145151
// PrePullAllImages pre-fetches all images tests depend on so that we don't fail in an actual test.
146-
func PrePullAllImages() error {
152+
func PrePullAllImages(ctx context.Context) error {
147153
puller, err := getPuller()
148154
if err != nil {
149155
return err
@@ -191,7 +197,7 @@ func PrePullAllImages() error {
191197
if retryCount > 0 {
192198
time.Sleep(imagePullRetryDelay)
193199
}
194-
if output, pullErr = puller.Pull(images[i]); pullErr == nil {
200+
if output, pullErr = puller.Pull(ctx, images[i]); pullErr == nil {
195201
break
196202
}
197203
klog.Warningf("Failed to pull %s as user %q, retrying in %s (%d of %d): %v",
@@ -211,6 +217,14 @@ func PrePullAllImages() error {
211217
return utilerrors.NewAggregate(pullErrs)
212218
}
213219

220+
func RemoveImage(ctx context.Context, image string) error {
221+
puller, err := getPuller()
222+
if err != nil {
223+
return err
224+
}
225+
return puller.Remove(ctx, image)
226+
}
227+
214228
func getContainerImageFromE2ETestDaemonset(dsYamlPath string) (string, error) {
215229
data, err := e2etestfiles.Read(dsYamlPath)
216230
if err != nil {

0 commit comments

Comments
 (0)