@@ -29,6 +29,7 @@ import (
29
29
"github.com/containerd/containerd/v2/pkg/cri/annotations"
30
30
criconfig "github.com/containerd/containerd/v2/pkg/cri/config"
31
31
"github.com/containerd/containerd/v2/pkg/cri/labels"
32
+ "github.com/containerd/containerd/v2/platforms"
32
33
)
33
34
34
35
func TestParseAuth (t * testing.T ) {
@@ -402,14 +403,13 @@ func TestSnapshotterFromPodSandboxConfig(t *testing.T) {
402
403
expectSnapshotter : defaultSnashotter ,
403
404
},
404
405
{
405
- desc : "should return error for runtime not found" ,
406
+ desc : "should return default snapshotter for runtime not found" ,
406
407
podSandboxConfig : & runtime.PodSandboxConfig {
407
408
Annotations : map [string ]string {
408
409
annotations .RuntimeHandler : "runtime-not-exists" ,
409
410
},
410
411
},
411
- expectErr : true ,
412
- expectSnapshotter : "" ,
412
+ expectSnapshotter : defaultSnashotter ,
413
413
},
414
414
{
415
415
desc : "should return snapshotter provided in podSandboxConfig.Annotations" ,
@@ -426,12 +426,10 @@ func TestSnapshotterFromPodSandboxConfig(t *testing.T) {
426
426
t .Run (tt .desc , func (t * testing.T ) {
427
427
cri , _ := newTestCRIService ()
428
428
cri .config .Snapshotter = defaultSnashotter
429
- /*
430
- cri.config.ContainerdConfig.Runtimes = make(map[string]criconfig.Runtime)
431
- cri.config.ContainerdConfig.Runtimes["exiting-runtime"] = criconfig.Runtime{
432
- Snapshotter: runtimeSnapshotter,
433
- }
434
- */
429
+ cri .runtimePlatforms ["exiting-runtime" ] = ImagePlatform {
430
+ Platform : platforms .DefaultSpec (),
431
+ Snapshotter : runtimeSnapshotter ,
432
+ }
435
433
snapshotter , err := cri .snapshotterFromPodSandboxConfig (context .Background (), "test-image" , tt .podSandboxConfig )
436
434
assert .Equal (t , tt .expectSnapshotter , snapshotter )
437
435
if tt .expectErr {
@@ -492,49 +490,51 @@ func TestImageGetLabels(t *testing.T) {
492
490
criService , _ := newTestCRIService ()
493
491
494
492
tests := []struct {
495
- name string
496
- expectedLabel map [string ]string
497
- configSandboxImage string
498
- pullImageName string
493
+ name string
494
+ expectedLabel map [string ]string
495
+ pinnedImages [] string
496
+ pullImageName string
499
497
}{
500
498
{
501
- name : "pinned image labels should get added on sandbox image" ,
502
- expectedLabel : map [string ]string {labels .ImageLabelKey : labels .ImageLabelValue , labels .PinnedImageLabelKey : labels .PinnedImageLabelValue },
503
- configSandboxImage : "k8s.gcr.io/pause:3.9" ,
504
- pullImageName : "k8s.gcr.io/pause:3.9" ,
499
+ name : "pinned image labels should get added on sandbox image" ,
500
+ expectedLabel : map [string ]string {labels .ImageLabelKey : labels .ImageLabelValue , labels .PinnedImageLabelKey : labels .PinnedImageLabelValue },
501
+ pinnedImages : [] string { "k8s.gcr.io/pause:3.9" } ,
502
+ pullImageName : "k8s.gcr.io/pause:3.9" ,
505
503
},
506
504
{
507
- name : "pinned image labels should get added on sandbox image without tag" ,
508
- expectedLabel : map [string ]string {labels .ImageLabelKey : labels .ImageLabelValue , labels .PinnedImageLabelKey : labels .PinnedImageLabelValue },
509
- configSandboxImage : "k8s.gcr.io/pause" ,
510
- pullImageName : "k8s.gcr.io/pause:latest" ,
505
+ name : "pinned image labels should get added on sandbox image without tag" ,
506
+ expectedLabel : map [string ]string {labels .ImageLabelKey : labels .ImageLabelValue , labels .PinnedImageLabelKey : labels .PinnedImageLabelValue },
507
+ pinnedImages : [] string { "k8s.gcr.io/pause" , "k8s.gcr.io/pause:latest" } ,
508
+ pullImageName : "k8s.gcr.io/pause:latest" ,
511
509
},
512
510
{
513
- name : "pinned image labels should get added on sandbox image specified with tag and digest both" ,
514
- expectedLabel : map [string ]string {labels .ImageLabelKey : labels .ImageLabelValue , labels .PinnedImageLabelKey : labels .PinnedImageLabelValue },
515
- configSandboxImage : "k8s.gcr.io/pause:3.9@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2" ,
516
- pullImageName : "k8s.gcr.io/pause@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2" ,
511
+ name : "pinned image labels should get added on sandbox image specified with tag and digest both" ,
512
+ expectedLabel : map [string ]string {labels .ImageLabelKey : labels .ImageLabelValue , labels .PinnedImageLabelKey : labels .PinnedImageLabelValue },
513
+ pinnedImages : []string {
514
+ "k8s.gcr.io/pause:3.9@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2" ,
515
+ "k8s.gcr.io/pause@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2" ,
516
+ },
517
+ pullImageName : "k8s.gcr.io/pause@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2" ,
517
518
},
518
519
519
520
{
520
- name : "pinned image labels should get added on sandbox image specified with digest" ,
521
- expectedLabel : map [string ]string {labels .ImageLabelKey : labels .ImageLabelValue , labels .PinnedImageLabelKey : labels .PinnedImageLabelValue },
522
- configSandboxImage : "k8s.gcr.io/pause@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2" ,
523
- pullImageName : "k8s.gcr.io/pause@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2" ,
521
+ name : "pinned image labels should get added on sandbox image specified with digest" ,
522
+ expectedLabel : map [string ]string {labels .ImageLabelKey : labels .ImageLabelValue , labels .PinnedImageLabelKey : labels .PinnedImageLabelValue },
523
+ pinnedImages : [] string { "k8s.gcr.io/pause@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2" } ,
524
+ pullImageName : "k8s.gcr.io/pause@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2" ,
524
525
},
525
526
526
527
{
527
- name : "pinned image labels should not get added on other image" ,
528
- expectedLabel : map [string ]string {labels .ImageLabelKey : labels .ImageLabelValue },
529
- configSandboxImage : "k8s.gcr.io/pause:3.9" ,
530
- pullImageName : "k8s.gcr.io/random:latest" ,
528
+ name : "pinned image labels should not get added on other image" ,
529
+ expectedLabel : map [string ]string {labels .ImageLabelKey : labels .ImageLabelValue },
530
+ pinnedImages : [] string { "k8s.gcr.io/pause:3.9" } ,
531
+ pullImageName : "k8s.gcr.io/random:latest" ,
531
532
},
532
533
}
533
534
534
535
for _ , tt := range tests {
535
536
t .Run (tt .name , func (t * testing.T ) {
536
- // Change this config name
537
- //criService.config.SandboxImage = tt.configSandboxImage
537
+ criService .config .PinnedImages = tt .pinnedImages
538
538
labels := criService .getLabels (context .Background (), tt .pullImageName )
539
539
assert .Equal (t , tt .expectedLabel , labels )
540
540
0 commit comments