From 136849728ca984452c0b73120dc0ac4704d44e6c Mon Sep 17 00:00:00 2001 From: knight42 Date: Sat, 13 Jun 2020 09:30:20 +0800 Subject: [PATCH] address comments --- .../portallocator/controller/repair.go | 2 +- .../portallocator/controller/repair_test.go | 24 ++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/pkg/registry/core/service/portallocator/controller/repair.go b/pkg/registry/core/service/portallocator/controller/repair.go index 0b4d001010b..a7b6d28d2da 100644 --- a/pkg/registry/core/service/portallocator/controller/repair.go +++ b/pkg/registry/core/service/portallocator/controller/repair.go @@ -140,7 +140,7 @@ func (c *Repair) runOnce() error { case nil: if stored.Has(port) { // remove it from the old set, so we can find leaks - _ = stored.Release(port) + stored.Release(port) } else { // doesn't seem to be allocated c.recorder.Eventf(svc, corev1.EventTypeWarning, "PortNotAllocated", "Port %d is not allocated; repairing", port) diff --git a/pkg/registry/core/service/portallocator/controller/repair_test.go b/pkg/registry/core/service/portallocator/controller/repair_test.go index b936e150cfa..e9a4dc242b3 100644 --- a/pkg/registry/core/service/portallocator/controller/repair_test.go +++ b/pkg/registry/core/service/portallocator/controller/repair_test.go @@ -223,6 +223,28 @@ func TestCollectServiceNodePorts(t *testing.T) { }, expected: []int{111, 112, 113}, }, + { + name: "duplicated nodePort with TCP protocol", + serviceSpec: corev1.ServiceSpec{ + Ports: []corev1.ServicePort{ + {NodePort: 111, Protocol: corev1.ProtocolTCP}, + {NodePort: 111, Protocol: corev1.ProtocolTCP}, + {NodePort: 112, Protocol: corev1.ProtocolUDP}, + }, + }, + expected: []int{111, 111, 112}, + }, + { + name: "duplicated nodePort with UDP protocol", + serviceSpec: corev1.ServiceSpec{ + Ports: []corev1.ServicePort{ + {NodePort: 111, Protocol: corev1.ProtocolUDP}, + {NodePort: 111, Protocol: corev1.ProtocolUDP}, + {NodePort: 112, Protocol: corev1.ProtocolTCP}, + }, + }, + expected: []int{111, 111, 112}, + }, { name: "duplicated nodePort with different protocol", serviceSpec: corev1.ServiceSpec{ @@ -257,7 +279,7 @@ func TestCollectServiceNodePorts(t *testing.T) { expected: []int{111, 112}, }, { - name: "nodePort has same protocol with duplicated health check port", + name: "nodePort has same protocol as duplicated health check port", serviceSpec: corev1.ServiceSpec{ Ports: []corev1.ServicePort{ {NodePort: 111, Protocol: corev1.ProtocolUDP},