Skip to content

Commit

Permalink
Refactor pod config generation in tests (#1180)
Browse files Browse the repository at this point in the history
Add SandboxConfigOpt func type, which enables pluggable configuration
of PodSandboxConfig.

Signed-off-by: Maksim An <maksiman@microsoft.com>
  • Loading branch information
anmaxvl authored Sep 29, 2021
1 parent 057bebe commit 8debf44
Show file tree
Hide file tree
Showing 19 changed files with 329 additions and 326 deletions.
2 changes: 1 addition & 1 deletion test/cri-containerd/container_downlevel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func Test_CreateContainer_DownLevel_WCOW_Hypervisor(t *testing.T) {

pullRequiredImages(t, []string{imageWindowsNanoserver17763})

sandboxRequest := getRunPodSandboxRequest(t, wcowHypervisor17763RuntimeHandler, nil)
sandboxRequest := getRunPodSandboxRequest(t, wcowHypervisor17763RuntimeHandler)

request := &runtime.CreateContainerRequest{
Config: &runtime.ContainerConfig{
Expand Down
12 changes: 6 additions & 6 deletions test/cri-containerd/container_layers_packing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func Test_Container_Layer_Packing_On_VPMem(t *testing.T) {
requireFeatures(t, featureLCOW)

// use ubuntu to make sure that multiple container layers will be mapped properly
pullRequiredLcowImages(t, []string{imageLcowK8sPause, ubuntu1804})
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, ubuntu1804})

type config struct {
rootfsType string
Expand All @@ -104,7 +104,7 @@ func Test_Container_Layer_Packing_On_VPMem(t *testing.T) {
annotations := map[string]string{
oci.AnnotationPreferredRootFSType: scenario.rootfsType,
}
podReq := getRunPodSandboxRequest(t, lcowRuntimeHandler, annotations)
podReq := getRunPodSandboxRequest(t, lcowRuntimeHandler, WithSandboxAnnotations(annotations))
podID := runPodSandbox(t, client, ctx, podReq)
defer removePodSandbox(t, client, ctx, podID)

Expand Down Expand Up @@ -137,9 +137,9 @@ func Test_Many_Container_Layers_Supported_On_VPMem(t *testing.T) {

requireFeatures(t, featureLCOW)

pullRequiredLcowImages(t, []string{imageLcowK8sPause, alpine70ExtraLayers, ubuntu70ExtraLayers})
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, alpine70ExtraLayers, ubuntu70ExtraLayers})

podReq := getRunPodSandboxRequest(t, lcowRuntimeHandler, nil)
podReq := getRunPodSandboxRequest(t, lcowRuntimeHandler)
podID := runPodSandbox(t, client, ctx, podReq)
defer removePodSandbox(t, client, ctx, podID)

Expand Down Expand Up @@ -168,12 +168,12 @@ func Test_Annotation_Disable_Multi_Mapping(t *testing.T) {

requireFeatures(t, featureLCOW)

pullRequiredLcowImages(t, []string{imageLcowK8sPause, alpine70ExtraLayers})
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, alpine70ExtraLayers})

annotations := map[string]string{
oci.AnnotationVPMemNoMultiMapping: "true",
}
podReq := getRunPodSandboxRequest(t, lcowRuntimeHandler, annotations)
podReq := getRunPodSandboxRequest(t, lcowRuntimeHandler, WithSandboxAnnotations(annotations))
podID := runPodSandbox(t, client, ctx, podReq)
defer removePodSandbox(t, client, ctx, podID)

Expand Down
8 changes: 4 additions & 4 deletions test/cri-containerd/container_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
func Test_Container_Network_LCOW(t *testing.T) {
requireFeatures(t, featureLCOW)

pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, imageLcowAlpine})

// create a directory and log file
dir, err := ioutil.TempDir("", "")
Expand All @@ -32,7 +32,7 @@ func Test_Container_Network_LCOW(t *testing.T) {
}()
log := filepath.Join(dir, "ping.txt")

sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler, nil)
sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler)

client := newTestRuntimeClient(t)
ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -132,12 +132,12 @@ func Test_Container_Network_Hostname(t *testing.T) {
requireFeatures(t, test.requiredFeatures...)

if test.runtimeHandler == lcowRuntimeHandler {
pullRequiredLcowImages(t, []string{test.sandboxImage, test.containerImage})
pullRequiredLCOWImages(t, []string{test.sandboxImage, test.containerImage})
} else {
pullRequiredImages(t, []string{test.sandboxImage, test.containerImage})
}

sandboxRequest := getRunPodSandboxRequest(t, test.runtimeHandler, nil)
sandboxRequest := getRunPodSandboxRequest(t, test.runtimeHandler)
sandboxRequest.Config.Hostname = "TestHost"

client := newTestRuntimeClient(t)
Expand Down
52 changes: 26 additions & 26 deletions test/cri-containerd/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ func Test_RotateLogs_LCOW(t *testing.T) {
log := filepath.Join(dir, "log.txt")
logArchive := filepath.Join(dir, "log-archive.txt")

pullRequiredLcowImages(t, []string{imageLcowK8sPause, image})
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, image})
logrus.SetLevel(logrus.DebugLevel)

sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler, nil)
sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler)

request := &runtime.CreateContainerRequest{
Config: &runtime.ContainerConfig{
Expand Down Expand Up @@ -136,14 +136,14 @@ func Test_RotateLogs_LCOW(t *testing.T) {
func Test_RunContainer_Events_LCOW(t *testing.T) {
requireFeatures(t, featureLCOW)

pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
client := newTestRuntimeClient(t)

podctx, podcancel := context.WithCancel(context.Background())
defer podcancel()
targetNamespace := "k8s.io"

sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler, nil)
sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler)

podID := runPodSandbox(t, client, podctx, sandboxRequest)
defer removePodSandbox(t, client, podctx, podID)
Expand Down Expand Up @@ -207,12 +207,12 @@ func Test_RunContainer_Events_LCOW(t *testing.T) {
func Test_RunContainer_ForksThenExits_ShowsAsExited_LCOW(t *testing.T) {
requireFeatures(t, featureLCOW)

pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
client := newTestRuntimeClient(t)
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()

podRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler, nil)
podRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler)
podID := runPodSandbox(t, client, ctx, podRequest)
defer removePodSandbox(t, client, ctx, podID)
defer stopPodSandbox(t, client, ctx, podID)
Expand Down Expand Up @@ -258,7 +258,7 @@ func Test_RunContainer_ForksThenExits_ShowsAsExited_LCOW(t *testing.T) {
func Test_RunContainer_ZeroVPMEM_LCOW(t *testing.T) {
requireFeatures(t, featureLCOW)

pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, imageLcowAlpine})

client := newTestRuntimeClient(t)
ctx, cancel := context.WithCancel(context.Background())
Expand All @@ -267,10 +267,10 @@ func Test_RunContainer_ZeroVPMEM_LCOW(t *testing.T) {
sandboxRequest := getRunPodSandboxRequest(
t,
lcowRuntimeHandler,
map[string]string{
WithSandboxAnnotations(map[string]string{
oci.AnnotationPreferredRootFSType: "initrd",
oci.AnnotationVPMemCount: "0",
},
}),
)

podID := runPodSandbox(t, client, ctx, sandboxRequest)
Expand Down Expand Up @@ -300,7 +300,7 @@ func Test_RunContainer_ZeroVPMEM_LCOW(t *testing.T) {
func Test_RunContainer_ZeroVPMEM_Multiple_LCOW(t *testing.T) {
requireFeatures(t, featureLCOW)

pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, imageLcowAlpine})

client := newTestRuntimeClient(t)
ctx, cancel := context.WithCancel(context.Background())
Expand All @@ -309,10 +309,10 @@ func Test_RunContainer_ZeroVPMEM_Multiple_LCOW(t *testing.T) {
sandboxRequest := getRunPodSandboxRequest(
t,
lcowRuntimeHandler,
map[string]string{
WithSandboxAnnotations(map[string]string{
oci.AnnotationPreferredRootFSType: "initrd",
oci.AnnotationVPMemCount: "0",
},
}),
)

podID := runPodSandbox(t, client, ctx, sandboxRequest)
Expand Down Expand Up @@ -357,7 +357,7 @@ func Test_RunContainer_GMSA_WCOW_Process(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

sandboxRequest := getRunPodSandboxRequest(t, wcowProcessRuntimeHandler, nil)
sandboxRequest := getRunPodSandboxRequest(t, wcowProcessRuntimeHandler)

podID := runPodSandbox(t, client, ctx, sandboxRequest)
defer removePodSandbox(t, client, ctx, podID)
Expand Down Expand Up @@ -421,7 +421,7 @@ func Test_RunContainer_GMSA_WCOW_Hypervisor(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

sandboxRequest := getRunPodSandboxRequest(t, wcowHypervisorRuntimeHandler, nil)
sandboxRequest := getRunPodSandboxRequest(t, wcowHypervisorRuntimeHandler)

podID := runPodSandbox(t, client, ctx, sandboxRequest)
defer removePodSandbox(t, client, ctx, podID)
Expand Down Expand Up @@ -479,13 +479,13 @@ func Test_RunContainer_GMSA_WCOW_Hypervisor(t *testing.T) {
func Test_RunContainer_SandboxDevice_LCOW(t *testing.T) {
requireFeatures(t, featureLCOW)

pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, imageLcowAlpine})

client := newTestRuntimeClient(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler, nil)
sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler)
sandboxRequest.Config.Linux = &runtime.LinuxPodSandboxConfig{
SecurityContext: &runtime.LinuxSandboxSecurityContext{
Privileged: true,
Expand Down Expand Up @@ -549,9 +549,9 @@ func Test_RunContainer_NonDefault_User(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, imageLcowAlpine})

podReq := getRunPodSandboxRequest(t, lcowRuntimeHandler, nil)
podReq := getRunPodSandboxRequest(t, lcowRuntimeHandler)
podID := runPodSandbox(t, client, ctx, podReq)
defer removePodSandbox(t, client, ctx, podID)
defer stopPodSandbox(t, client, ctx, podID)
Expand Down Expand Up @@ -605,13 +605,13 @@ func Test_RunContainer_NonDefault_User(t *testing.T) {
func Test_RunContainer_ShareScratch_LCOW(t *testing.T) {
requireFeatures(t, featureLCOW)

pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, imageLcowAlpine})

client := newTestRuntimeClient(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler, nil)
sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler)

podID := runPodSandbox(t, client, ctx, sandboxRequest)
defer removePodSandbox(t, client, ctx, podID)
Expand Down Expand Up @@ -695,13 +695,13 @@ func findOverlaySize(t *testing.T, ctx context.Context, client runtime.RuntimeSe
func Test_RunContainer_ShareScratch_CheckSize_LCOW(t *testing.T) {
requireFeatures(t, featureLCOW)

pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, imageLcowAlpine})

client := newTestRuntimeClient(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler, nil)
sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler)

podID := runPodSandbox(t, client, ctx, sandboxRequest)
defer removePodSandbox(t, client, ctx, podID)
Expand Down Expand Up @@ -779,13 +779,13 @@ func Test_RunContainer_ShareScratch_CheckSize_LCOW(t *testing.T) {
func Test_CreateContainer_DevShmSize(t *testing.T) {
requireFeatures(t, featureLCOW)

pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, imageLcowAlpine})

client := newTestRuntimeClient(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

podReq := getRunPodSandboxRequest(t, lcowRuntimeHandler, nil)
podReq := getRunPodSandboxRequest(t, lcowRuntimeHandler)
podID := runPodSandbox(t, client, ctx, podReq)
defer removePodSandbox(t, client, ctx, podID)

Expand Down Expand Up @@ -834,14 +834,14 @@ func Test_CreateContainer_HugePageMount_LCOW(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, imageLcowAlpine})

annotations := map[string]string{
oci.AnnotationFullyPhysicallyBacked: "true",
oci.AnnotationMemorySizeInMB: "2048",
oci.AnnotationKernelBootOptions: "hugepagesz=2M hugepages=10",
}
sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler, annotations)
sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler, WithSandboxAnnotations(annotations))

podID := runPodSandbox(t, client, ctx, sandboxRequest)
defer removePodSandbox(t, client, ctx, podID)
Expand Down
36 changes: 6 additions & 30 deletions test/cri-containerd/container_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,12 @@ func Test_Container_UpdateResources_CPUShare(t *testing.T) {
requireFeatures(t, test.requiredFeatures...)

if test.runtimeHandler == lcowRuntimeHandler {
pullRequiredLcowImages(t, []string{test.sandboxImage})
pullRequiredLCOWImages(t, []string{test.sandboxImage})
} else if test.runtimeHandler == wcowHypervisorRuntimeHandler {
pullRequiredImages(t, []string{test.sandboxImage})
}

podRequest := &runtime.RunPodSandboxRequest{
Config: &runtime.PodSandboxConfig{
Metadata: &runtime.PodSandboxMetadata{
Name: t.Name(),
Namespace: testNamespace,
},
},
RuntimeHandler: test.runtimeHandler,
}
podRequest := getRunPodSandboxRequest(t, test.runtimeHandler)

client := newTestRuntimeClient(t)
ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -187,20 +179,12 @@ func Test_Container_UpdateResources_CPUShare_NotRunning(t *testing.T) {
requireFeatures(t, test.requiredFeatures...)

if test.runtimeHandler == lcowRuntimeHandler {
pullRequiredLcowImages(t, []string{test.sandboxImage})
pullRequiredLCOWImages(t, []string{test.sandboxImage})
} else if test.runtimeHandler == wcowHypervisorRuntimeHandler {
pullRequiredImages(t, []string{test.sandboxImage})
}

podRequest := &runtime.RunPodSandboxRequest{
Config: &runtime.PodSandboxConfig{
Metadata: &runtime.PodSandboxMetadata{
Name: t.Name(),
Namespace: testNamespace,
},
},
RuntimeHandler: test.runtimeHandler,
}
podRequest := getRunPodSandboxRequest(t, test.runtimeHandler)

client := newTestRuntimeClient(t)
ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -302,20 +286,12 @@ func Test_Container_UpdateResources_Memory(t *testing.T) {
requireFeatures(t, test.requiredFeatures...)

if test.runtimeHandler == lcowRuntimeHandler {
pullRequiredLcowImages(t, []string{test.sandboxImage})
pullRequiredLCOWImages(t, []string{test.sandboxImage})
} else if test.runtimeHandler == wcowHypervisorRuntimeHandler {
pullRequiredImages(t, []string{test.sandboxImage})
}

podRequest := &runtime.RunPodSandboxRequest{
Config: &runtime.PodSandboxConfig{
Metadata: &runtime.PodSandboxMetadata{
Name: t.Name(),
Namespace: testNamespace,
},
},
RuntimeHandler: test.runtimeHandler,
}
podRequest := getRunPodSandboxRequest(t, test.runtimeHandler)

client := newTestRuntimeClient(t)
ctx, cancel := context.WithCancel(context.Background())
Expand Down
Loading

0 comments on commit 8debf44

Please sign in to comment.