Copilot commented on code in PR #2703:
URL:
https://github.com/apache/apisix-ingress-controller/pull/2703#discussion_r2903131802
##########
internal/controller/utils.go:
##########
@@ -1168,6 +1179,23 @@ func isListenerHostnameEffective(listener
gatewayv1.Listener) bool {
listener.Protocol == gatewayv1.TLSProtocolType
}
+// appendUniqueListeners appends listeners to the target slice, skipping any
+// listener whose Name already exists in the target. Listener names are unique
+// within a Gateway per the Gateway API specification.
+func appendUniqueListeners(target []gatewayv1.Listener, source
...gatewayv1.Listener) []gatewayv1.Listener {
+ seen := make(map[gatewayv1.SectionName]struct{}, len(target))
+ for _, l := range target {
+ seen[l.Name] = struct{}{}
+ }
+ for _, l := range source {
+ if _, exists := seen[l.Name]; !exists {
+ seen[l.Name] = struct{}{}
+ target = append(target, l)
+ }
+ }
+ return target
Review Comment:
appendUniqueListeners de-dupes solely by listener Name. Listener names are
only guaranteed unique *within a single Gateway*, but a Route can reference
multiple Gateways via multiple parentRefs; two different Gateways can both have
a listener named "http" on different ports. In that case the current de-dupe
will drop one listener and its port, causing incorrect server_port var
injection (missing ports) and potentially wrong routing. Consider either (a)
not de-duping listeners at all when building tctx.Listeners (since downstream
logic already de-dupes ports via a map), or (b) de-dupe on a composite key that
can’t collide across Gateways (e.g., gateway namespace/name + listener name, or
at least listener name+port+protocol).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]