Skip to content

Commit 8debf44

Browse files
authored
Refactor pod config generation in tests (#1180)
Add SandboxConfigOpt func type, which enables pluggable configuration of PodSandboxConfig. Signed-off-by: Maksim An <[email protected]>
1 parent 057bebe commit 8debf44

19 files changed

Lines changed: 329 additions & 326 deletions

test/cri-containerd/container_downlevel_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func Test_CreateContainer_DownLevel_WCOW_Hypervisor(t *testing.T) {
1616

1717
pullRequiredImages(t, []string{imageWindowsNanoserver17763})
1818

19-
sandboxRequest := getRunPodSandboxRequest(t, wcowHypervisor17763RuntimeHandler, nil)
19+
sandboxRequest := getRunPodSandboxRequest(t, wcowHypervisor17763RuntimeHandler)
2020

2121
request := &runtime.CreateContainerRequest{
2222
Config: &runtime.ContainerConfig{

test/cri-containerd/container_layers_packing_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func Test_Container_Layer_Packing_On_VPMem(t *testing.T) {
8383
requireFeatures(t, featureLCOW)
8484

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

8888
type config struct {
8989
rootfsType string
@@ -104,7 +104,7 @@ func Test_Container_Layer_Packing_On_VPMem(t *testing.T) {
104104
annotations := map[string]string{
105105
oci.AnnotationPreferredRootFSType: scenario.rootfsType,
106106
}
107-
podReq := getRunPodSandboxRequest(t, lcowRuntimeHandler, annotations)
107+
podReq := getRunPodSandboxRequest(t, lcowRuntimeHandler, WithSandboxAnnotations(annotations))
108108
podID := runPodSandbox(t, client, ctx, podReq)
109109
defer removePodSandbox(t, client, ctx, podID)
110110

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

138138
requireFeatures(t, featureLCOW)
139139

140-
pullRequiredLcowImages(t, []string{imageLcowK8sPause, alpine70ExtraLayers, ubuntu70ExtraLayers})
140+
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, alpine70ExtraLayers, ubuntu70ExtraLayers})
141141

142-
podReq := getRunPodSandboxRequest(t, lcowRuntimeHandler, nil)
142+
podReq := getRunPodSandboxRequest(t, lcowRuntimeHandler)
143143
podID := runPodSandbox(t, client, ctx, podReq)
144144
defer removePodSandbox(t, client, ctx, podID)
145145

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

169169
requireFeatures(t, featureLCOW)
170170

171-
pullRequiredLcowImages(t, []string{imageLcowK8sPause, alpine70ExtraLayers})
171+
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, alpine70ExtraLayers})
172172

173173
annotations := map[string]string{
174174
oci.AnnotationVPMemNoMultiMapping: "true",
175175
}
176-
podReq := getRunPodSandboxRequest(t, lcowRuntimeHandler, annotations)
176+
podReq := getRunPodSandboxRequest(t, lcowRuntimeHandler, WithSandboxAnnotations(annotations))
177177
podID := runPodSandbox(t, client, ctx, podReq)
178178
defer removePodSandbox(t, client, ctx, podID)
179179

test/cri-containerd/container_network_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
func Test_Container_Network_LCOW(t *testing.T) {
1919
requireFeatures(t, featureLCOW)
2020

21-
pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
21+
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
2222

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

35-
sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler, nil)
35+
sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler)
3636

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

134134
if test.runtimeHandler == lcowRuntimeHandler {
135-
pullRequiredLcowImages(t, []string{test.sandboxImage, test.containerImage})
135+
pullRequiredLCOWImages(t, []string{test.sandboxImage, test.containerImage})
136136
} else {
137137
pullRequiredImages(t, []string{test.sandboxImage, test.containerImage})
138138
}
139139

140-
sandboxRequest := getRunPodSandboxRequest(t, test.runtimeHandler, nil)
140+
sandboxRequest := getRunPodSandboxRequest(t, test.runtimeHandler)
141141
sandboxRequest.Config.Hostname = "TestHost"
142142

143143
client := newTestRuntimeClient(t)

test/cri-containerd/container_test.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ func Test_RotateLogs_LCOW(t *testing.T) {
7878
log := filepath.Join(dir, "log.txt")
7979
logArchive := filepath.Join(dir, "log-archive.txt")
8080

81-
pullRequiredLcowImages(t, []string{imageLcowK8sPause, image})
81+
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, image})
8282
logrus.SetLevel(logrus.DebugLevel)
8383

84-
sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler, nil)
84+
sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler)
8585

8686
request := &runtime.CreateContainerRequest{
8787
Config: &runtime.ContainerConfig{
@@ -136,14 +136,14 @@ func Test_RotateLogs_LCOW(t *testing.T) {
136136
func Test_RunContainer_Events_LCOW(t *testing.T) {
137137
requireFeatures(t, featureLCOW)
138138

139-
pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
139+
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
140140
client := newTestRuntimeClient(t)
141141

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

146-
sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler, nil)
146+
sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler)
147147

148148
podID := runPodSandbox(t, client, podctx, sandboxRequest)
149149
defer removePodSandbox(t, client, podctx, podID)
@@ -207,12 +207,12 @@ func Test_RunContainer_Events_LCOW(t *testing.T) {
207207
func Test_RunContainer_ForksThenExits_ShowsAsExited_LCOW(t *testing.T) {
208208
requireFeatures(t, featureLCOW)
209209

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

215-
podRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler, nil)
215+
podRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler)
216216
podID := runPodSandbox(t, client, ctx, podRequest)
217217
defer removePodSandbox(t, client, ctx, podID)
218218
defer stopPodSandbox(t, client, ctx, podID)
@@ -258,7 +258,7 @@ func Test_RunContainer_ForksThenExits_ShowsAsExited_LCOW(t *testing.T) {
258258
func Test_RunContainer_ZeroVPMEM_LCOW(t *testing.T) {
259259
requireFeatures(t, featureLCOW)
260260

261-
pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
261+
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
262262

263263
client := newTestRuntimeClient(t)
264264
ctx, cancel := context.WithCancel(context.Background())
@@ -267,10 +267,10 @@ func Test_RunContainer_ZeroVPMEM_LCOW(t *testing.T) {
267267
sandboxRequest := getRunPodSandboxRequest(
268268
t,
269269
lcowRuntimeHandler,
270-
map[string]string{
270+
WithSandboxAnnotations(map[string]string{
271271
oci.AnnotationPreferredRootFSType: "initrd",
272272
oci.AnnotationVPMemCount: "0",
273-
},
273+
}),
274274
)
275275

276276
podID := runPodSandbox(t, client, ctx, sandboxRequest)
@@ -300,7 +300,7 @@ func Test_RunContainer_ZeroVPMEM_LCOW(t *testing.T) {
300300
func Test_RunContainer_ZeroVPMEM_Multiple_LCOW(t *testing.T) {
301301
requireFeatures(t, featureLCOW)
302302

303-
pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
303+
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
304304

305305
client := newTestRuntimeClient(t)
306306
ctx, cancel := context.WithCancel(context.Background())
@@ -309,10 +309,10 @@ func Test_RunContainer_ZeroVPMEM_Multiple_LCOW(t *testing.T) {
309309
sandboxRequest := getRunPodSandboxRequest(
310310
t,
311311
lcowRuntimeHandler,
312-
map[string]string{
312+
WithSandboxAnnotations(map[string]string{
313313
oci.AnnotationPreferredRootFSType: "initrd",
314314
oci.AnnotationVPMemCount: "0",
315-
},
315+
}),
316316
)
317317

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

360-
sandboxRequest := getRunPodSandboxRequest(t, wcowProcessRuntimeHandler, nil)
360+
sandboxRequest := getRunPodSandboxRequest(t, wcowProcessRuntimeHandler)
361361

362362
podID := runPodSandbox(t, client, ctx, sandboxRequest)
363363
defer removePodSandbox(t, client, ctx, podID)
@@ -421,7 +421,7 @@ func Test_RunContainer_GMSA_WCOW_Hypervisor(t *testing.T) {
421421
ctx, cancel := context.WithCancel(context.Background())
422422
defer cancel()
423423

424-
sandboxRequest := getRunPodSandboxRequest(t, wcowHypervisorRuntimeHandler, nil)
424+
sandboxRequest := getRunPodSandboxRequest(t, wcowHypervisorRuntimeHandler)
425425

426426
podID := runPodSandbox(t, client, ctx, sandboxRequest)
427427
defer removePodSandbox(t, client, ctx, podID)
@@ -479,13 +479,13 @@ func Test_RunContainer_GMSA_WCOW_Hypervisor(t *testing.T) {
479479
func Test_RunContainer_SandboxDevice_LCOW(t *testing.T) {
480480
requireFeatures(t, featureLCOW)
481481

482-
pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
482+
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
483483

484484
client := newTestRuntimeClient(t)
485485
ctx, cancel := context.WithCancel(context.Background())
486486
defer cancel()
487487

488-
sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler, nil)
488+
sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler)
489489
sandboxRequest.Config.Linux = &runtime.LinuxPodSandboxConfig{
490490
SecurityContext: &runtime.LinuxSandboxSecurityContext{
491491
Privileged: true,
@@ -549,9 +549,9 @@ func Test_RunContainer_NonDefault_User(t *testing.T) {
549549
ctx, cancel := context.WithCancel(context.Background())
550550
defer cancel()
551551

552-
pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
552+
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
553553

554-
podReq := getRunPodSandboxRequest(t, lcowRuntimeHandler, nil)
554+
podReq := getRunPodSandboxRequest(t, lcowRuntimeHandler)
555555
podID := runPodSandbox(t, client, ctx, podReq)
556556
defer removePodSandbox(t, client, ctx, podID)
557557
defer stopPodSandbox(t, client, ctx, podID)
@@ -605,13 +605,13 @@ func Test_RunContainer_NonDefault_User(t *testing.T) {
605605
func Test_RunContainer_ShareScratch_LCOW(t *testing.T) {
606606
requireFeatures(t, featureLCOW)
607607

608-
pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
608+
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
609609

610610
client := newTestRuntimeClient(t)
611611
ctx, cancel := context.WithCancel(context.Background())
612612
defer cancel()
613613

614-
sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler, nil)
614+
sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler)
615615

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

698-
pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
698+
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
699699

700700
client := newTestRuntimeClient(t)
701701
ctx, cancel := context.WithCancel(context.Background())
702702
defer cancel()
703703

704-
sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler, nil)
704+
sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler)
705705

706706
podID := runPodSandbox(t, client, ctx, sandboxRequest)
707707
defer removePodSandbox(t, client, ctx, podID)
@@ -779,13 +779,13 @@ func Test_RunContainer_ShareScratch_CheckSize_LCOW(t *testing.T) {
779779
func Test_CreateContainer_DevShmSize(t *testing.T) {
780780
requireFeatures(t, featureLCOW)
781781

782-
pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
782+
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
783783

784784
client := newTestRuntimeClient(t)
785785
ctx, cancel := context.WithCancel(context.Background())
786786
defer cancel()
787787

788-
podReq := getRunPodSandboxRequest(t, lcowRuntimeHandler, nil)
788+
podReq := getRunPodSandboxRequest(t, lcowRuntimeHandler)
789789
podID := runPodSandbox(t, client, ctx, podReq)
790790
defer removePodSandbox(t, client, ctx, podID)
791791

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

837-
pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
837+
pullRequiredLCOWImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
838838

839839
annotations := map[string]string{
840840
oci.AnnotationFullyPhysicallyBacked: "true",
841841
oci.AnnotationMemorySizeInMB: "2048",
842842
oci.AnnotationKernelBootOptions: "hugepagesz=2M hugepages=10",
843843
}
844-
sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler, annotations)
844+
sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler, WithSandboxAnnotations(annotations))
845845

846846
podID := runPodSandbox(t, client, ctx, sandboxRequest)
847847
defer removePodSandbox(t, client, ctx, podID)

test/cri-containerd/container_update_test.go

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,12 @@ func Test_Container_UpdateResources_CPUShare(t *testing.T) {
7272
requireFeatures(t, test.requiredFeatures...)
7373

7474
if test.runtimeHandler == lcowRuntimeHandler {
75-
pullRequiredLcowImages(t, []string{test.sandboxImage})
75+
pullRequiredLCOWImages(t, []string{test.sandboxImage})
7676
} else if test.runtimeHandler == wcowHypervisorRuntimeHandler {
7777
pullRequiredImages(t, []string{test.sandboxImage})
7878
}
7979

80-
podRequest := &runtime.RunPodSandboxRequest{
81-
Config: &runtime.PodSandboxConfig{
82-
Metadata: &runtime.PodSandboxMetadata{
83-
Name: t.Name(),
84-
Namespace: testNamespace,
85-
},
86-
},
87-
RuntimeHandler: test.runtimeHandler,
88-
}
80+
podRequest := getRunPodSandboxRequest(t, test.runtimeHandler)
8981

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

189181
if test.runtimeHandler == lcowRuntimeHandler {
190-
pullRequiredLcowImages(t, []string{test.sandboxImage})
182+
pullRequiredLCOWImages(t, []string{test.sandboxImage})
191183
} else if test.runtimeHandler == wcowHypervisorRuntimeHandler {
192184
pullRequiredImages(t, []string{test.sandboxImage})
193185
}
194186

195-
podRequest := &runtime.RunPodSandboxRequest{
196-
Config: &runtime.PodSandboxConfig{
197-
Metadata: &runtime.PodSandboxMetadata{
198-
Name: t.Name(),
199-
Namespace: testNamespace,
200-
},
201-
},
202-
RuntimeHandler: test.runtimeHandler,
203-
}
187+
podRequest := getRunPodSandboxRequest(t, test.runtimeHandler)
204188

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

304288
if test.runtimeHandler == lcowRuntimeHandler {
305-
pullRequiredLcowImages(t, []string{test.sandboxImage})
289+
pullRequiredLCOWImages(t, []string{test.sandboxImage})
306290
} else if test.runtimeHandler == wcowHypervisorRuntimeHandler {
307291
pullRequiredImages(t, []string{test.sandboxImage})
308292
}
309293

310-
podRequest := &runtime.RunPodSandboxRequest{
311-
Config: &runtime.PodSandboxConfig{
312-
Metadata: &runtime.PodSandboxMetadata{
313-
Name: t.Name(),
314-
Namespace: testNamespace,
315-
},
316-
},
317-
RuntimeHandler: test.runtimeHandler,
318-
}
294+
podRequest := getRunPodSandboxRequest(t, test.runtimeHandler)
319295

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

0 commit comments

Comments
 (0)