From f540c2a74d30d4ddf98d91cdf3e084a6d6e8f6d5 Mon Sep 17 00:00:00 2001 From: Lantao Liu Date: Tue, 11 Sep 2018 16:31:58 -0700 Subject: [PATCH] Skip sctp protocol hostport mapping. Signed-off-by: Lantao Liu --- pkg/server/sandbox_run.go | 3 +++ pkg/server/sandbox_run_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/pkg/server/sandbox_run.go b/pkg/server/sandbox_run.go index 0562f1aa5..b0514789c 100644 --- a/pkg/server/sandbox_run.go +++ b/pkg/server/sandbox_run.go @@ -558,6 +558,9 @@ func toCNIPortMappings(criPortMappings []*runtime.PortMapping) []cni.PortMapping if mapping.HostPort <= 0 { continue } + if mapping.Protocol != runtime.Protocol_TCP && mapping.Protocol != runtime.Protocol_UDP { + continue + } portMappings = append(portMappings, cni.PortMapping{ HostPort: mapping.HostPort, ContainerPort: mapping.ContainerPort, diff --git a/pkg/server/sandbox_run_test.go b/pkg/server/sandbox_run_test.go index b729f3042..c8cb72883 100644 --- a/pkg/server/sandbox_run_test.go +++ b/pkg/server/sandbox_run_test.go @@ -403,6 +403,30 @@ func TestToCNIPortMappings(t *testing.T) { }, }, }, + "CRI port mapping with unsupported protocol should be skipped": { + criPortMappings: []*runtime.PortMapping{ + { + Protocol: runtime.Protocol_SCTP, + ContainerPort: 1234, + HostPort: 5678, + HostIp: "123.124.125.126", + }, + { + Protocol: runtime.Protocol_TCP, + ContainerPort: 4321, + HostPort: 8765, + HostIp: "126.125.124.123", + }, + }, + cniPortMappings: []cni.PortMapping{ + { + HostPort: 8765, + ContainerPort: 4321, + Protocol: "tcp", + HostIP: "126.125.124.123", + }, + }, + }, } { t.Logf("TestCase %q", desc) assert.Equal(t, test.cniPortMappings, toCNIPortMappings(test.criPortMappings))