Fix command line parsing for image list
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
parent
a9514da757
commit
2b92c70fa4
@ -334,7 +334,7 @@ func TestImagePullAllPlatforms(t *testing.T) {
|
||||
defer cancel()
|
||||
|
||||
cs := client.ContentStore()
|
||||
img, err := client.Fetch(ctx, imagelist.PauseImage)
|
||||
img, err := client.Fetch(ctx, imagelist.Get(imagelist.Pause))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ import (
|
||||
)
|
||||
|
||||
func TestImageIsUnpacked(t *testing.T) {
|
||||
imageName := imagelist.PauseImage
|
||||
imageName := imagelist.Get(imagelist.Pause)
|
||||
ctx, cancel := testContext(t)
|
||||
defer cancel()
|
||||
|
||||
@ -138,7 +138,7 @@ func TestImageUsage(t *testing.T) {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
imageName := imagelist.PauseImage
|
||||
imageName := imagelist.Get(imagelist.Pause)
|
||||
ctx, cancel := testContext(t)
|
||||
defer cancel()
|
||||
|
||||
|
@ -56,7 +56,7 @@ func TestLeaseResources(t *testing.T) {
|
||||
defer ls.Delete(ctx, l, leases.SynchronousDelete)
|
||||
|
||||
// step 1: download image
|
||||
imageName := imagelist.PauseImage
|
||||
imageName := imagelist.Get(imagelist.Pause)
|
||||
|
||||
image, err := client.Pull(ctx, imageName, WithPullUnpack, WithPullSnapshotter(snapshotterName))
|
||||
if err != nil {
|
||||
|
@ -29,12 +29,13 @@ func TestContainerRestart(t *testing.T) {
|
||||
t.Logf("Create a pod config and run sandbox container")
|
||||
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox1", "restart")
|
||||
|
||||
EnsureImageExists(t, images.PauseImage)
|
||||
pauseImage := images.Get(images.Pause)
|
||||
EnsureImageExists(t, pauseImage)
|
||||
|
||||
t.Logf("Create a container config and run container in a pod")
|
||||
containerConfig := ContainerConfig(
|
||||
"container1",
|
||||
images.PauseImage,
|
||||
pauseImage,
|
||||
WithTestLabels(),
|
||||
WithTestAnnotations(),
|
||||
)
|
||||
@ -63,12 +64,13 @@ func TestFailedContainerRestart(t *testing.T) {
|
||||
t.Logf("Create a pod config and run sandbox container")
|
||||
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox1", "restart")
|
||||
|
||||
EnsureImageExists(t, images.PauseImage)
|
||||
pauseImage := images.Get(images.Pause)
|
||||
EnsureImageExists(t, pauseImage)
|
||||
|
||||
t.Logf("Create a container config in a pod with a command that fails")
|
||||
containerConfig := ContainerConfig(
|
||||
"container1",
|
||||
images.PauseImage,
|
||||
pauseImage,
|
||||
WithCommand("something-that-doesnt-exist"),
|
||||
WithTestLabels(),
|
||||
WithTestAnnotations(),
|
||||
@ -89,7 +91,7 @@ func TestFailedContainerRestart(t *testing.T) {
|
||||
|
||||
containerConfig = ContainerConfig(
|
||||
"container1",
|
||||
images.PauseImage,
|
||||
pauseImage,
|
||||
WithTestLabels(),
|
||||
WithTestAnnotations(),
|
||||
)
|
||||
|
@ -34,12 +34,13 @@ func TestContainerStats(t *testing.T) {
|
||||
t.Logf("Create a pod config and run sandbox container")
|
||||
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox1", "stats")
|
||||
|
||||
EnsureImageExists(t, images.PauseImage)
|
||||
pauseImage := images.Get(images.Pause)
|
||||
EnsureImageExists(t, pauseImage)
|
||||
|
||||
t.Logf("Create a container config and run container in a pod")
|
||||
containerConfig := ContainerConfig(
|
||||
"container1",
|
||||
images.PauseImage,
|
||||
pauseImage,
|
||||
WithTestLabels(),
|
||||
WithTestAnnotations(),
|
||||
)
|
||||
@ -146,7 +147,8 @@ func TestContainerListStats(t *testing.T) {
|
||||
t.Logf("Create a pod config and run sandbox container")
|
||||
sb, sbConfig := PodSandboxConfigWithCleanup(t, "running-pod", "statsls")
|
||||
|
||||
EnsureImageExists(t, images.PauseImage)
|
||||
pauseImage := images.Get(images.Pause)
|
||||
EnsureImageExists(t, pauseImage)
|
||||
|
||||
t.Logf("Create a container config and run containers in a pod")
|
||||
containerConfigMap := make(map[string]*runtime.ContainerConfig)
|
||||
@ -154,7 +156,7 @@ func TestContainerListStats(t *testing.T) {
|
||||
cName := fmt.Sprintf("container%d", i)
|
||||
containerConfig := ContainerConfig(
|
||||
cName,
|
||||
images.PauseImage,
|
||||
pauseImage,
|
||||
WithTestLabels(),
|
||||
WithTestAnnotations(),
|
||||
)
|
||||
@ -200,7 +202,8 @@ func TestContainerListStatsWithIdFilter(t *testing.T) {
|
||||
t.Logf("Create a pod config and run sandbox container")
|
||||
sb, sbConfig := PodSandboxConfigWithCleanup(t, "running-pod", "statsls")
|
||||
|
||||
EnsureImageExists(t, images.PauseImage)
|
||||
pauseImage := images.Get(images.Pause)
|
||||
EnsureImageExists(t, pauseImage)
|
||||
|
||||
t.Logf("Create a container config and run containers in a pod")
|
||||
containerConfigMap := make(map[string]*runtime.ContainerConfig)
|
||||
@ -208,7 +211,7 @@ func TestContainerListStatsWithIdFilter(t *testing.T) {
|
||||
cName := fmt.Sprintf("container%d", i)
|
||||
containerConfig := ContainerConfig(
|
||||
cName,
|
||||
images.PauseImage,
|
||||
pauseImage,
|
||||
WithTestLabels(),
|
||||
WithTestAnnotations(),
|
||||
)
|
||||
@ -259,7 +262,8 @@ func TestContainerListStatsWithSandboxIdFilter(t *testing.T) {
|
||||
t.Logf("Create a pod config and run sandbox container")
|
||||
sb, sbConfig := PodSandboxConfigWithCleanup(t, "running-pod", "statsls")
|
||||
|
||||
EnsureImageExists(t, images.PauseImage)
|
||||
pauseImage := images.Get(images.Pause)
|
||||
EnsureImageExists(t, pauseImage)
|
||||
|
||||
t.Logf("Create a container config and run containers in a pod")
|
||||
containerConfigMap := make(map[string]*runtime.ContainerConfig)
|
||||
@ -267,7 +271,7 @@ func TestContainerListStatsWithSandboxIdFilter(t *testing.T) {
|
||||
cName := fmt.Sprintf("container%d", i)
|
||||
containerConfig := ContainerConfig(
|
||||
cName,
|
||||
images.PauseImage,
|
||||
pauseImage,
|
||||
WithTestLabels(),
|
||||
WithTestAnnotations(),
|
||||
)
|
||||
@ -319,7 +323,8 @@ func TestContainerListStatsWithIdSandboxIdFilter(t *testing.T) {
|
||||
t.Logf("Create a pod config and run sandbox container")
|
||||
sb, sbConfig := PodSandboxConfigWithCleanup(t, "running-pod", "statsls")
|
||||
|
||||
EnsureImageExists(t, images.PauseImage)
|
||||
pauseImage := images.Get(images.Pause)
|
||||
EnsureImageExists(t, pauseImage)
|
||||
|
||||
t.Logf("Create container config and run containers in a pod")
|
||||
containerConfigMap := make(map[string]*runtime.ContainerConfig)
|
||||
@ -327,7 +332,7 @@ func TestContainerListStatsWithIdSandboxIdFilter(t *testing.T) {
|
||||
cName := fmt.Sprintf("container%d", i)
|
||||
containerConfig := ContainerConfig(
|
||||
cName,
|
||||
images.PauseImage,
|
||||
pauseImage,
|
||||
WithTestLabels(),
|
||||
WithTestAnnotations(),
|
||||
)
|
||||
|
@ -152,7 +152,8 @@ func TestUpdateContainerResources_MemorySwap(t *testing.T) {
|
||||
t.Log("Create a sandbox")
|
||||
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox", "update-container-swap-resources")
|
||||
|
||||
EnsureImageExists(t, images.PauseImage)
|
||||
pauseImage := images.Get(images.Pause)
|
||||
EnsureImageExists(t, pauseImage)
|
||||
|
||||
memoryLimit := int64(128 * 1024 * 1024)
|
||||
baseSwapLimit := int64(200 * 1024 * 1024)
|
||||
@ -169,7 +170,7 @@ func TestUpdateContainerResources_MemorySwap(t *testing.T) {
|
||||
t.Log("Create a container with memory limit but no swap")
|
||||
cnConfig := ContainerConfig(
|
||||
"container",
|
||||
images.PauseImage,
|
||||
pauseImage,
|
||||
WithResources(&runtime.LinuxContainerResources{
|
||||
MemoryLimitInBytes: memoryLimit,
|
||||
MemorySwapLimitInBytes: baseSwapLimit,
|
||||
@ -224,12 +225,13 @@ func TestUpdateContainerResources_MemoryLimit(t *testing.T) {
|
||||
t.Log("Create a sandbox")
|
||||
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox", "update-container-resources")
|
||||
|
||||
EnsureImageExists(t, images.PauseImage)
|
||||
pauseImage := images.Get(images.Pause)
|
||||
EnsureImageExists(t, pauseImage)
|
||||
|
||||
t.Log("Create a container with memory limit")
|
||||
cnConfig := ContainerConfig(
|
||||
"container",
|
||||
images.PauseImage,
|
||||
pauseImage,
|
||||
WithResources(&runtime.LinuxContainerResources{
|
||||
MemoryLimitInBytes: 200 * 1024 * 1024,
|
||||
}),
|
||||
|
@ -31,12 +31,13 @@ func TestDuplicateName(t *testing.T) {
|
||||
_, err := runtimeService.RunPodSandbox(sbConfig, *runtimeHandler)
|
||||
require.Error(t, err)
|
||||
|
||||
EnsureImageExists(t, images.PauseImage)
|
||||
pauseImage := images.Get(images.Pause)
|
||||
EnsureImageExists(t, pauseImage)
|
||||
|
||||
t.Logf("Create a container")
|
||||
cnConfig := ContainerConfig(
|
||||
"container",
|
||||
images.PauseImage,
|
||||
pauseImage,
|
||||
)
|
||||
_, err = runtimeService.CreateContainer(sb, cnConfig, sbConfig)
|
||||
require.NoError(t, err)
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/pelletier/go-toml"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -38,14 +39,11 @@ type ImageList struct {
|
||||
}
|
||||
|
||||
var (
|
||||
imageMap map[int]string
|
||||
imageList ImageList
|
||||
PauseImage string // This is the same with default sandbox image
|
||||
imageMap map[int]string
|
||||
imageList ImageList
|
||||
)
|
||||
|
||||
func init() {
|
||||
initImages(*imageListFile)
|
||||
}
|
||||
var initOnce sync.Once
|
||||
|
||||
func initImages(imageListFile string) {
|
||||
imageList = ImageList{
|
||||
@ -58,6 +56,8 @@ func initImages(imageListFile string) {
|
||||
}
|
||||
|
||||
if imageListFile != "" {
|
||||
logrus.Infof("loading image list from file: %s", imageListFile)
|
||||
|
||||
fileContent, err := os.ReadFile(imageListFile)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("error reading '%v' file contents: %v", imageList, err))
|
||||
@ -70,9 +70,7 @@ func initImages(imageListFile string) {
|
||||
}
|
||||
|
||||
logrus.Infof("Using the following image list: %+v", imageList)
|
||||
|
||||
imageMap = initImageMap(imageList)
|
||||
PauseImage = Get(Pause)
|
||||
}
|
||||
|
||||
const (
|
||||
@ -105,5 +103,9 @@ func initImageMap(imageList ImageList) map[int]string {
|
||||
|
||||
// Get returns the fully qualified URI to an image (including version)
|
||||
func Get(image int) string {
|
||||
initOnce.Do(func() {
|
||||
initImages(*imageListFile)
|
||||
})
|
||||
|
||||
return imageMap[image]
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ import (
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
cri "github.com/containerd/containerd/integration/cri-api/pkg/apis"
|
||||
_ "github.com/containerd/containerd/integration/images" // Keep this around to parse `imageListFile` command line var
|
||||
"github.com/containerd/containerd/integration/remote"
|
||||
dialer "github.com/containerd/containerd/integration/remote/util"
|
||||
criconfig "github.com/containerd/containerd/pkg/cri/config"
|
||||
|
@ -109,12 +109,13 @@ func TestContainerdRestart(t *testing.T) {
|
||||
runtimeService.RemovePodSandbox(sid)
|
||||
}()
|
||||
|
||||
EnsureImageExists(t, images.PauseImage)
|
||||
pauseImage := images.Get(images.Pause)
|
||||
EnsureImageExists(t, pauseImage)
|
||||
|
||||
s.id = sid
|
||||
for j := range s.containers {
|
||||
c := &s.containers[j]
|
||||
cfg := ContainerConfig(c.name, images.PauseImage,
|
||||
cfg := ContainerConfig(c.name, pauseImage,
|
||||
// Set pid namespace as per container, so that container won't die
|
||||
// when sandbox container is killed.
|
||||
WithPidNamespace(runtime.NamespaceMode_CONTAINER),
|
||||
|
@ -38,7 +38,7 @@ var (
|
||||
|
||||
// Tests to verify the Windows HostProcess
|
||||
func TestWindowsHostProcess(t *testing.T) {
|
||||
pauseImage := images.PauseImage
|
||||
pauseImage := images.Get(images.Pause)
|
||||
EnsureImageExists(t, pauseImage)
|
||||
|
||||
t.Run("run as Local Service", func(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user