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

NET-4638: when multiple listeners have the same port, only add to K8s Service once #2413

Merged
merged 3 commits into from
Jul 11, 2023
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")),
},
Comment on lines +50 to +55
Copy link
Member Author

@nathancoleman nathancoleman Jun 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have multiple asserts on the Service being created. Adding a listener here with a duplicate port makes these tests more robust by ensuring our existing assertions pass where they previously would have failed with this additional listener.

}
)

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
sarahalsmiller marked this conversation as resolved.
Show resolved Hide resolved
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