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