From e06ce8e89448dcd8196883f9f76fced53e05738c Mon Sep 17 00:00:00 2001 From: Nathan Coleman Date: Wed, 21 Jun 2023 15:41:37 +0000 Subject: [PATCH 1/3] backport of commit 1c5e14b4e7184b1c14fde28e46e8d9194e8193dd --- control-plane/api-gateway/gatekeeper/gatekeeper_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/control-plane/api-gateway/gatekeeper/gatekeeper_test.go b/control-plane/api-gateway/gatekeeper/gatekeeper_test.go index ba58cb441f..069643e301 100644 --- a/control-plane/api-gateway/gatekeeper/gatekeeper_test.go +++ b/control-plane/api-gateway/gatekeeper/gatekeeper_test.go @@ -40,12 +40,19 @@ var ( Name: "Listener 1", Port: 8080, Protocol: "TCP", + Hostname: common.PointerTo(gwv1beta1.Hostname("example.com")), }, { Name: "Listener 2", Port: 8081, Protocol: "TCP", }, + { + Name: "Listener 3", + Port: 8080, + Protocol: "TCP", + Hostname: common.PointerTo(gwv1beta1.Hostname("example.net")), + }, } ) From d8d731c85bffe7d695e85c7bbbaa20004b5f0bff Mon Sep 17 00:00:00 2001 From: Nathan Coleman Date: Wed, 21 Jun 2023 15:23:19 +0000 Subject: [PATCH 2/3] backport of commit 07f1b68639dafd4f2ec8c1177622bef25b902096 --- control-plane/api-gateway/gatekeeper/service.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/control-plane/api-gateway/gatekeeper/service.go b/control-plane/api-gateway/gatekeeper/service.go index 80272b7495..ba6041c130 100644 --- a/control-plane/api-gateway/gatekeeper/service.go +++ b/control-plane/api-gateway/gatekeeper/service.go @@ -65,14 +65,22 @@ func (g *Gatekeeper) deleteService(ctx context.Context, gwName types.NamespacedN } func (g *Gatekeeper) service(gateway gwv1beta1.Gateway, gcc v1alpha1.GatewayClassConfig) *corev1.Service { + seenPorts := map[gwv1beta1.PortNumber]struct{}{} ports := []corev1.ServicePort{} for _, listener := range gateway.Spec.Listeners { + if _, seen := seenPorts[listener.Port]; seen { + // We've already added this listener's port to the Service + continue + } + ports = append(ports, corev1.ServicePort{ Name: string(listener.Name), // only TCP-based services are supported for now Protocol: corev1.ProtocolTCP, Port: int32(listener.Port), }) + + seenPorts[listener.Port] = struct{}{} } // Copy annotations from the Gateway, filtered by those allowed by the GatewayClassConfig. From 76a6e441146bcf9be20748d9db30c3146e7811ef Mon Sep 17 00:00:00 2001 From: Nathan Coleman Date: Wed, 21 Jun 2023 15:44:13 +0000 Subject: [PATCH 3/3] backport of commit a11e454162b0ba05e18667c6a623822cf2c57368 --- .changelog/2413.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/2413.txt diff --git a/.changelog/2413.txt b/.changelog/2413.txt new file mode 100644 index 0000000000..89755b23a7 --- /dev/null +++ b/.changelog/2413.txt @@ -0,0 +1,3 @@ +```release-note:bug +api-gateway: Fix creation of invalid Kubernetes Service when multiple Gateway listeners have the same port. +```