Skip to content

Commit 5847340

Browse files
committed
tests: Refactors container image usage
Currently, the cri-integration tests do not work on Windows due to various reasons. One of the reasons is because all the tests are using Linux-specific images. This commit refactors the image pulling / usage in the cri-integration tests, making it easier to update, and easier to configure the a custom registry to pull those images from. For Windows runs, custom registries can be created, which will also contain Windows images, and the cri-integration tests can be configured to use those registries by specifying the "--image-list" argument, a TOML file which will contain an alternative mapping of the default images. Signed-off-by: Claudiu Belu <[email protected]>
1 parent b0fb8a5 commit 5847340

17 files changed

Lines changed: 139 additions & 31 deletions

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ROOTDIR=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
1818

1919
# Base path used to install.
2020
DESTDIR ?= /usr/local
21+
TEST_IMAGE_LIST ?=
2122

2223
# Used to populate variables in version package.
2324
VERSION=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always)

integration/addition_gids_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ func TestAdditionalGids(t *testing.T) {
4545
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
4646
}()
4747

48-
const (
49-
testImage = "busybox"
48+
var (
49+
testImage = GetImage(BusyBox)
5050
containerName = "test-container"
5151
)
5252
t.Logf("Pull test image %q", testImage)
@@ -59,7 +59,7 @@ func TestAdditionalGids(t *testing.T) {
5959
t.Log("Create a container to print id")
6060
cnConfig := ContainerConfig(
6161
containerName,
62-
"busybox",
62+
testImage,
6363
WithCommand("id"),
6464
WithLogPath(containerName),
6565
WithSupplementalGroups([]int64{1 /*daemon*/, 1234 /*new group*/}),

integration/common.go

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// +build linux
2+
3+
/*
4+
Copyright The containerd Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package integration
20+
21+
import (
22+
"fmt"
23+
"io/ioutil"
24+
25+
"github.com/pelletier/go-toml"
26+
"github.com/sirupsen/logrus"
27+
cri "k8s.io/cri-api/pkg/apis"
28+
)
29+
30+
// ImageList holds public image references
31+
type ImageList struct {
32+
Alpine string
33+
BusyBox string
34+
Pause string
35+
VolumeCopyUp string
36+
VolumeOwnership string
37+
}
38+
39+
var (
40+
imageService cri.ImageManagerService
41+
imageMap map[int]string
42+
imageList ImageList
43+
pauseImage string // This is the same with default sandbox image
44+
)
45+
46+
func initImages(imageListFile string) {
47+
imageList = ImageList{
48+
Alpine: "docker.io/library/alpine:latest",
49+
BusyBox: "docker.io/library/busybox:latest",
50+
Pause: "k8s.gcr.io/pause:3.5",
51+
VolumeCopyUp: "gcr.io/k8s-cri-containerd/volume-copy-up:2.0",
52+
VolumeOwnership: "gcr.io/k8s-cri-containerd/volume-ownership:2.0",
53+
}
54+
55+
if imageListFile != "" {
56+
fileContent, err := ioutil.ReadFile(imageListFile)
57+
if err != nil {
58+
panic(fmt.Errorf("Error reading '%v' file contents: %v", imageList, err))
59+
}
60+
61+
err = toml.Unmarshal(fileContent, &imageList)
62+
if err != nil {
63+
panic(fmt.Errorf("Error unmarshalling '%v' TOML file: %v", imageList, err))
64+
}
65+
}
66+
67+
logrus.Infof("Using the following image list: %+v", imageList)
68+
69+
imageMap = initImageMap(imageList)
70+
pauseImage = GetImage(Pause)
71+
}
72+
73+
const (
74+
// None is to be used for unset/default images
75+
None = iota
76+
// Alpine image
77+
Alpine
78+
// BusyBox image
79+
BusyBox
80+
// Pause image
81+
Pause
82+
// VolumeCopyUp image
83+
VolumeCopyUp
84+
// VolumeOwnership image
85+
VolumeOwnership
86+
)
87+
88+
func initImageMap(imageList ImageList) map[int]string {
89+
images := map[int]string{}
90+
images[Alpine] = imageList.Alpine
91+
images[BusyBox] = imageList.BusyBox
92+
images[Pause] = imageList.Pause
93+
images[VolumeCopyUp] = imageList.VolumeCopyUp
94+
images[VolumeOwnership] = imageList.VolumeOwnership
95+
return images
96+
}
97+
98+
// GetImage returns the fully qualified URI to an image (including version)
99+
func GetImage(image int) string {
100+
return imageMap[image]
101+
}

integration/container_log_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ func TestContainerLogWithoutTailingNewLine(t *testing.T) {
4848
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
4949
}()
5050

51-
const (
52-
testImage = "busybox"
51+
var (
52+
testImage = GetImage(BusyBox)
5353
containerName = "test-container"
5454
)
5555
t.Logf("Pull test image %q", testImage)
@@ -108,8 +108,8 @@ func TestLongContainerLog(t *testing.T) {
108108
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
109109
}()
110110

111-
const (
112-
testImage = "busybox"
111+
var (
112+
testImage = GetImage(BusyBox)
113113
containerName = "test-container"
114114
)
115115
t.Logf("Pull test image %q", testImage)

integration/container_stop_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ func TestSharedPidMultiProcessContainerStop(t *testing.T) {
4242
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
4343
}()
4444

45-
const (
46-
testImage = "busybox"
45+
var (
46+
testImage = GetImage(BusyBox)
4747
containerName = "test-container"
4848
)
4949
t.Logf("Pull test image %q", testImage)
@@ -86,8 +86,8 @@ func TestContainerStopCancellation(t *testing.T) {
8686
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
8787
}()
8888

89-
const (
90-
testImage = "busybox"
89+
var (
90+
testImage = GetImage(BusyBox)
9191
containerName = "test-container"
9292
)
9393
t.Logf("Pull test image %q", testImage)

integration/container_without_image_ref_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ func TestContainerLifecycleWithoutImageRef(t *testing.T) {
3737
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
3838
}()
3939

40-
const (
41-
testImage = "busybox"
40+
var (
41+
testImage = GetImage(BusyBox)
4242
containerName = "test-container"
4343
)
4444
t.Log("Pull test image")

integration/containerd_image_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535

3636
// Test to test the CRI plugin should see image pulled into containerd directly.
3737
func TestContainerdImage(t *testing.T) {
38-
const testImage = "docker.io/library/busybox:latest"
38+
var testImage = GetImage(BusyBox)
3939
ctx := context.Background()
4040

4141
t.Logf("make sure the test image doesn't exist in the cri plugin")
@@ -153,7 +153,7 @@ func TestContainerdImage(t *testing.T) {
153153

154154
// Test image managed by CRI plugin shouldn't be affected by images in other namespaces.
155155
func TestContainerdImageInOtherNamespaces(t *testing.T) {
156-
const testImage = "docker.io/library/busybox:latest"
156+
var testImage = GetImage(BusyBox)
157157
ctx := context.Background()
158158

159159
t.Logf("make sure the test image doesn't exist in the cri plugin")

integration/image_list.sample.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
alpine = "docker.io/library/alpine:latest"
2+
busybox = "docker.io/library/busybox:latest"
3+
pause = "k8s.gcr.io/pause:3.5"
4+
VolumeCopyUp = "gcr.io/k8s-cri-containerd/volume-copy-up:2.0"
5+
VolumeOwnership = "gcr.io/k8s-cri-containerd/volume-ownership:2.0"

integration/image_load_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ import (
3232

3333
// Test to load an image from tarball.
3434
func TestImageLoad(t *testing.T) {
35-
testImage := "busybox:latest"
36-
loadedImage := "docker.io/library/" + testImage
35+
testImage := GetImage(BusyBox)
36+
loadedImage := testImage
3737
_, err := exec.LookPath("docker")
3838
if err != nil {
3939
t.Skipf("Docker is not available: %v", err)

integration/imagefs_info_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestImageFSInfo(t *testing.T) {
3333
config := PodSandboxConfig("running-pod", "imagefs")
3434

3535
t.Logf("Pull an image to make sure image fs is not empty")
36-
img, err := imageService.PullImage(&runtime.ImageSpec{Image: "busybox"}, nil, config)
36+
img, err := imageService.PullImage(&runtime.ImageSpec{Image: GetImage(BusyBox)}, nil, config)
3737
require.NoError(t, err)
3838
defer func() {
3939
err := imageService.RemoveImage(&runtime.ImageSpec{Image: img})

0 commit comments

Comments
 (0)