mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #91007 from lsytj0413/fix-89443
test(e2e_node): Parallelize prepulling all images in `e2e_node` tests
This commit is contained in:
commit
9eced04014
@ -41,6 +41,7 @@ go_library(
|
|||||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/api/equality:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/api/equality:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
|
"//staging/src/k8s.io/apimachinery/pkg/util/errors:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
||||||
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
|
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
|
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
|
||||||
|
@ -17,14 +17,17 @@ limitations under the License.
|
|||||||
package e2enode
|
package e2enode
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/user"
|
"os/user"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
|
||||||
|
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
internalapi "k8s.io/cri-api/pkg/apis"
|
internalapi "k8s.io/cri-api/pkg/apis"
|
||||||
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||||
@ -41,6 +44,8 @@ const (
|
|||||||
maxImagePullRetries = 5
|
maxImagePullRetries = 5
|
||||||
// Sleep duration between image pull retry attempts.
|
// Sleep duration between image pull retry attempts.
|
||||||
imagePullRetryDelay = time.Second
|
imagePullRetryDelay = time.Second
|
||||||
|
// Number of parallel count to pull images.
|
||||||
|
maxParallelImagePullCount = 5
|
||||||
)
|
)
|
||||||
|
|
||||||
// NodePrePullImageList is a list of images used in node e2e test. These images will be prepulled
|
// NodePrePullImageList is a list of images used in node e2e test. These images will be prepulled
|
||||||
@ -151,27 +156,61 @@ func PrePullAllImages() error {
|
|||||||
}
|
}
|
||||||
images := framework.ImagePrePullList.List()
|
images := framework.ImagePrePullList.List()
|
||||||
klog.V(4).Infof("Pre-pulling images with %s %+v", puller.Name(), images)
|
klog.V(4).Infof("Pre-pulling images with %s %+v", puller.Name(), images)
|
||||||
for _, image := range images {
|
|
||||||
|
imageCh := make(chan int, len(images))
|
||||||
|
for i := range images {
|
||||||
|
imageCh <- i
|
||||||
|
}
|
||||||
|
close(imageCh)
|
||||||
|
|
||||||
|
pullErrs := make([]error, len(images))
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
parallelImagePullCount := maxParallelImagePullCount
|
||||||
|
if len(images) < parallelImagePullCount {
|
||||||
|
parallelImagePullCount = len(images)
|
||||||
|
}
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(parallelImagePullCount)
|
||||||
|
for i := 0; i < parallelImagePullCount; i++ {
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
|
||||||
|
for i := range imageCh {
|
||||||
var (
|
var (
|
||||||
err error
|
pullErr error
|
||||||
output []byte
|
output []byte
|
||||||
)
|
)
|
||||||
for i := 0; i < maxImagePullRetries; i++ {
|
for retryCount := 0; retryCount < maxImagePullRetries; retryCount++ {
|
||||||
if i > 0 {
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
if retryCount > 0 {
|
||||||
time.Sleep(imagePullRetryDelay)
|
time.Sleep(imagePullRetryDelay)
|
||||||
}
|
}
|
||||||
if output, err = puller.Pull(image); err == nil {
|
if output, pullErr = puller.Pull(images[i]); pullErr == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
klog.Warningf("Failed to pull %s as user %q, retrying in %s (%d of %d): %v",
|
klog.Warningf("Failed to pull %s as user %q, retrying in %s (%d of %d): %v",
|
||||||
image, usr.Username, imagePullRetryDelay.String(), i+1, maxImagePullRetries, err)
|
images[i], usr.Username, imagePullRetryDelay.String(), retryCount+1, maxImagePullRetries, pullErr)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if pullErr != nil {
|
||||||
klog.Warningf("Could not pre-pull image %s %v output: %s", image, err, output)
|
klog.Warningf("Could not pre-pull image %s %v output: %s", images[i], pullErr, output)
|
||||||
return err
|
pullErrs[i] = pullErr
|
||||||
|
cancel()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
return utilerrors.NewAggregate(pullErrs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getGPUDevicePluginImage returns the image of GPU device plugin.
|
// getGPUDevicePluginImage returns the image of GPU device plugin.
|
||||||
|
Loading…
Reference in New Issue
Block a user