@@ -41,25 +41,11 @@ type ListenersTranslator interface {
4141func (t * Translator ) ProcessListeners (gateways []* GatewayContext , xdsIR resource.XdsIRMap , infraIR resource.InfraIRMap , resources * resource.Resources ) {
4242 // Infra IR proxy ports must be unique.
4343 foundPorts := make (map [string ][]* protocolPort )
44- t .validateConflictedLayer7Listeners (gateways )
45- t .validateConflictedLayer4Listeners (gateways , gwapiv1 .TCPProtocolType )
46- t .validateConflictedLayer4Listeners (gateways , gwapiv1 .UDPProtocolType )
47- if t .MergeGateways {
48- t .validateConflictedMergedListeners (gateways )
49- }
5044
51- // Iterate through all listeners to validate spec
52- // and compute status for each, and add valid ones
53- // to the Xds IR .
45+ // Phase 1: Validate each listener's spec independently.
46+ // This must happen before conflict resolution so that invalid listeners
47+ // don't block valid ones during conflict detection .
5448 for _ , gateway := range gateways {
55- irKey := t .getIRKey (gateway .Gateway )
56-
57- if gateway .envoyProxy != nil {
58- infraIR [irKey ].Proxy .Config = gateway .envoyProxy
59- }
60- t .processProxyReadyListener (xdsIR [irKey ], gateway .envoyProxy )
61- t .processProxyObservability (gateway , xdsIR [irKey ], infraIR [irKey ].Proxy , resources )
62-
6349 for _ , listener := range gateway .listeners {
6450 // Process protocol & supported kinds
6551 switch listener .Protocol {
@@ -101,9 +87,35 @@ func (t *Translator) ProcessListeners(gateways []*GatewayContext, xdsIR resource
10187
10288 // Process Hostname configuration
10389 t .validateHostName (listener )
90+ }
91+ }
10492
93+ // Phase 2: Run conflict detection.
94+ // Only listeners that haven't been marked as invalid will participate in conflict resolution.
95+ t .validateConflictedLayer7Listeners (gateways )
96+ t .validateConflictedLayer4Listeners (gateways , gwapiv1 .TCPProtocolType )
97+ t .validateConflictedLayer4Listeners (gateways , gwapiv1 .UDPProtocolType )
98+ if t .MergeGateways {
99+ t .validateConflictedMergedListeners (gateways )
100+ }
101+
102+ // Phase 3: Build IR for valid listeners.
103+ for _ , gateway := range gateways {
104+ irKey := t .getIRKey (gateway .Gateway )
105+
106+ if gateway .envoyProxy != nil {
107+ infraIR [irKey ].Proxy .Config = gateway .envoyProxy
108+ }
109+ t .processProxyReadyListener (xdsIR [irKey ], gateway .envoyProxy )
110+ t .processProxyObservability (gateway , xdsIR [irKey ], infraIR [irKey ].Proxy , resources )
111+
112+ for _ , listener := range gateway .listeners {
105113 // Process conditions and check if the listener is ready
106- t .validateListenerConditions (listener )
114+ isReady := t .validateListenerConditions (listener )
115+ if ! isReady {
116+ // Skip invalid listeners from IR building
117+ continue
118+ }
107119
108120 address := netutils .IPv4ListenerAddress
109121 ipFamily := getEnvoyIPFamily (gateway .envoyProxy )
0 commit comments