Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport of NET-4638: when multiple listeners have the same port, only add to K8s Service once into release/1.2.x #2554

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/2413.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
api-gateway: Fix creation of invalid Kubernetes Service when multiple Gateway listeners have the same port.
```
7 changes: 7 additions & 0 deletions control-plane/api-gateway/gatekeeper/gatekeeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
},
}
)

Expand Down
8 changes: 8 additions & 0 deletions control-plane/api-gateway/gatekeeper/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down