This repository was archived by the owner on Mar 9, 2022. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -558,6 +558,9 @@ func toCNIPortMappings(criPortMappings []*runtime.PortMapping) []cni.PortMapping
558558 if mapping .HostPort <= 0 {
559559 continue
560560 }
561+ if mapping .Protocol != runtime .Protocol_TCP && mapping .Protocol != runtime .Protocol_UDP {
562+ continue
563+ }
561564 portMappings = append (portMappings , cni.PortMapping {
562565 HostPort : mapping .HostPort ,
563566 ContainerPort : mapping .ContainerPort ,
Original file line number Diff line number Diff line change @@ -403,6 +403,30 @@ func TestToCNIPortMappings(t *testing.T) {
403403 },
404404 },
405405 },
406+ "CRI port mapping with unsupported protocol should be skipped" : {
407+ criPortMappings : []* runtime.PortMapping {
408+ {
409+ Protocol : runtime .Protocol_SCTP ,
410+ ContainerPort : 1234 ,
411+ HostPort : 5678 ,
412+ HostIp : "123.124.125.126" ,
413+ },
414+ {
415+ Protocol : runtime .Protocol_TCP ,
416+ ContainerPort : 4321 ,
417+ HostPort : 8765 ,
418+ HostIp : "126.125.124.123" ,
419+ },
420+ },
421+ cniPortMappings : []cni.PortMapping {
422+ {
423+ HostPort : 8765 ,
424+ ContainerPort : 4321 ,
425+ Protocol : "tcp" ,
426+ HostIP : "126.125.124.123" ,
427+ },
428+ },
429+ },
406430 } {
407431 t .Logf ("TestCase %q" , desc )
408432 assert .Equal (t , test .cniPortMappings , toCNIPortMappings (test .criPortMappings ))
You can’t perform that action at this time.
0 commit comments