Skip to content

Commit

Permalink
update node e2e of image pull per comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pacoxu committed Feb 28, 2024
1 parent 21eb8f3 commit 6ed590e
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 189 deletions.
2 changes: 1 addition & 1 deletion test/e2e_node/e2e_node_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ var _ = ginkgo.SynchronizedBeforeSuite(func(ctx context.Context) []byte {
if framework.TestContext.PrepullImages {
klog.Infof("Pre-pulling images so that they are cached for the tests.")
updateImageAllowList(ctx)
err := PrePullAllImages()
err := PrePullAllImages(ctx)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
}

Expand Down
3 changes: 2 additions & 1 deletion test/e2e_node/eviction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,8 @@ func runEvictionTest(f *framework.Framework, pressureTimeout time.Duration, expe
if expectedNodeCondition == v1.NodeDiskPressure && framework.TestContext.PrepullImages {
// The disk eviction test may cause the prepulled images to be evicted,
// prepull those images again to ensure this test not affect following tests.
PrePullAllImages()
err := PrePullAllImages(ctx)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
}
}
// Run prePull using a defer to make sure it is executed even when the assertions below fails
Expand Down
4 changes: 2 additions & 2 deletions test/e2e_node/image_gc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ var _ = SIGDescribe("ImageGarbageCollect", framework.WithSerial(), framework.Wit
_, is, err = getCRIClient()
framework.ExpectNoError(err)
})
ginkgo.AfterEach(func() {
framework.ExpectNoError(PrePullAllImages())
ginkgo.AfterEach(func(ctx context.Context) {
framework.ExpectNoError(PrePullAllImages(ctx))
})
ginkgo.Context("when ImageMaximumGCAge is set", func() {
tempSetCurrentKubeletConfig(f, func(ctx context.Context, initialConfig *kubeletconfig.KubeletConfiguration) {
Expand Down
24 changes: 12 additions & 12 deletions test/e2e_node/image_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ func getNodeProblemDetectorImage() string {
// puller represents a generic image puller
type puller interface {
// Pull pulls an image by name
Pull(image string) ([]byte, error)
// Remove remves an image by name
Remove(image string) error
Pull(ctx context.Context, image string) ([]byte, error)
// Remove removes an image by name
Remove(ctx context.Context, image string) error
// Name returns the name of the specific puller implementation
Name() string
}
Expand All @@ -131,17 +131,17 @@ func (rp *remotePuller) Name() string {
return "CRI"
}

func (rp *remotePuller) Pull(image string) ([]byte, error) {
resp, err := rp.imageService.ImageStatus(context.Background(), &runtimeapi.ImageSpec{Image: image}, false)
func (rp *remotePuller) Pull(ctx context.Context, image string) ([]byte, error) {
resp, err := rp.imageService.ImageStatus(ctx, &runtimeapi.ImageSpec{Image: image}, false)
if err == nil && resp.GetImage() != nil {
return nil, nil
}
_, err = rp.imageService.PullImage(context.Background(), &runtimeapi.ImageSpec{Image: image}, nil, nil)
_, err = rp.imageService.PullImage(ctx, &runtimeapi.ImageSpec{Image: image}, nil, nil)
return nil, err
}

func (rp *remotePuller) Remove(image string) error {
return rp.imageService.RemoveImage(context.Background(), &runtimeapi.ImageSpec{Image: image})
func (rp *remotePuller) Remove(ctx context.Context, image string) error {
return rp.imageService.RemoveImage(ctx, &runtimeapi.ImageSpec{Image: image})
}

func getPuller() (puller, error) {
Expand All @@ -155,7 +155,7 @@ func getPuller() (puller, error) {
}

// PrePullAllImages pre-fetches all images tests depend on so that we don't fail in an actual test.
func PrePullAllImages() error {
func PrePullAllImages(ctx context.Context) error {
puller, err := getPuller()
if err != nil {
return err
Expand Down Expand Up @@ -203,7 +203,7 @@ func PrePullAllImages() error {
if retryCount > 0 {
time.Sleep(imagePullRetryDelay)
}
if output, pullErr = puller.Pull(images[i]); pullErr == nil {
if output, pullErr = puller.Pull(ctx, images[i]); pullErr == nil {
break
}
klog.Warningf("Failed to pull %s as user %q, retrying in %s (%d of %d): %v",
Expand All @@ -223,12 +223,12 @@ func PrePullAllImages() error {
return utilerrors.NewAggregate(pullErrs)
}

func RemoveImage(image string) error {
func RemoveImage(ctx context.Context, image string) error {
puller, err := getPuller()
if err != nil {
return err
}
return puller.Remove(image)
return puller.Remove(ctx, image)
}

// getGPUDevicePluginImage returns the image of GPU device plugin.
Expand Down

0 comments on commit 6ed590e

Please sign in to comment.