Merge pull request #5313 from claudiubelu/pull-images-once

cri-integration tests: Pull images once
This commit is contained in:
Fu Wei
2021-05-13 11:10:52 +08:00
committed by GitHub
12 changed files with 45 additions and 78 deletions

View File

@@ -21,10 +21,13 @@ package integration
import (
"fmt"
"io/ioutil"
"testing"
"github.com/pelletier/go-toml"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
cri "k8s.io/cri-api/pkg/apis"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
)
// ImageList holds public image references
@@ -104,3 +107,20 @@ func initImageMap(imageList ImageList) map[int]string {
func GetImage(image int) string {
return imageMap[image]
}
// EnsureImageExists pulls the given image, ensures that no error was encountered
// while pulling it.
func EnsureImageExists(t *testing.T, imageName string) string {
img, err := imageService.ImageStatus(&runtime.ImageSpec{Image: imageName})
require.NoError(t, err)
if img != nil {
t.Logf("Image %q already exists, not pulling.", imageName)
return img.Id
}
t.Logf("Pull test image %q", imageName)
imgID, err := imageService.PullImage(&runtime.ImageSpec{Image: imageName}, nil, nil)
require.NoError(t, err)
return imgID
}