@@ -533,10 +533,18 @@ func TestGetSandboxRuntime(t *testing.T) {
533533 Root : "" ,
534534 }
535535
536+ fooRuntime := criconfig.Runtime {
537+ Type : "io.containerd.runtime.v1.linux" ,
538+ Engine : "foo-bar" ,
539+ Root : "" ,
540+ }
541+
536542 for desc , test := range map [string ]struct {
537543 sandboxConfig * runtime.PodSandboxConfig
544+ runtimeHandler string
538545 defaultRuntime criconfig.Runtime
539546 untrustedWorkloadRuntime criconfig.Runtime
547+ runtimes map [string ]criconfig.Runtime
540548 expectErr bool
541549 expectedRuntime criconfig.Runtime
542550 }{
@@ -595,6 +603,54 @@ func TestGetSandboxRuntime(t *testing.T) {
595603 defaultRuntime : defaultRuntime ,
596604 expectErr : true ,
597605 },
606+ "should use 'untrusted' runtime for untrusted workload" : {
607+ sandboxConfig : & runtime.PodSandboxConfig {
608+ Annotations : map [string ]string {
609+ annotations .UntrustedWorkload : "true" ,
610+ },
611+ },
612+ defaultRuntime : defaultRuntime ,
613+ runtimes : map [string ]criconfig.Runtime {criconfig .RuntimeUntrusted : untrustedWorkloadRuntime },
614+ expectedRuntime : untrustedWorkloadRuntime ,
615+ },
616+ "should use 'untrusted' runtime for untrusted workload & handler" : {
617+ sandboxConfig : & runtime.PodSandboxConfig {
618+ Annotations : map [string ]string {
619+ annotations .UntrustedWorkload : "true" ,
620+ },
621+ },
622+ runtimeHandler : "untrusted" ,
623+ defaultRuntime : defaultRuntime ,
624+ runtimes : map [string ]criconfig.Runtime {criconfig .RuntimeUntrusted : untrustedWorkloadRuntime },
625+ expectedRuntime : untrustedWorkloadRuntime ,
626+ },
627+ "should return an error if untrusted annotation with conflicting handler" : {
628+ sandboxConfig : & runtime.PodSandboxConfig {
629+ Annotations : map [string ]string {
630+ annotations .UntrustedWorkload : "true" ,
631+ },
632+ },
633+ runtimeHandler : "foo" ,
634+ defaultRuntime : defaultRuntime ,
635+ untrustedWorkloadRuntime : untrustedWorkloadRuntime ,
636+ runtimes : map [string ]criconfig.Runtime {"foo" : fooRuntime },
637+ expectErr : true ,
638+ },
639+ "should use correct runtime for a runtime handler" : {
640+ sandboxConfig : & runtime.PodSandboxConfig {},
641+ runtimeHandler : "foo" ,
642+ defaultRuntime : defaultRuntime ,
643+ untrustedWorkloadRuntime : untrustedWorkloadRuntime ,
644+ runtimes : map [string ]criconfig.Runtime {"foo" : fooRuntime },
645+ expectedRuntime : fooRuntime ,
646+ },
647+ "should return error if runtime handler is required but not configured" : {
648+ sandboxConfig : & runtime.PodSandboxConfig {},
649+ runtimeHandler : "bar" ,
650+ defaultRuntime : defaultRuntime ,
651+ runtimes : map [string ]criconfig.Runtime {"foo" : fooRuntime },
652+ expectErr : true ,
653+ },
598654 } {
599655 t .Run (desc , func (t * testing.T ) {
600656 cri := newTestCRIService ()
@@ -603,7 +659,8 @@ func TestGetSandboxRuntime(t *testing.T) {
603659 }
604660 cri .config .ContainerdConfig .DefaultRuntime = test .defaultRuntime
605661 cri .config .ContainerdConfig .UntrustedWorkloadRuntime = test .untrustedWorkloadRuntime
606- r , err := cri .getSandboxRuntime (test .sandboxConfig )
662+ cri .config .ContainerdConfig .Runtimes = test .runtimes
663+ r , err := cri .getSandboxRuntime (test .sandboxConfig , test .runtimeHandler )
607664 assert .Equal (t , test .expectErr , err != nil )
608665 assert .Equal (t , test .expectedRuntime , r )
609666 })
0 commit comments