@@ -175,30 +175,53 @@ func (t *Translator) ProcessListeners(gateways []*GatewayContext, xdsIR resource
175
175
foundPorts [irKey ] = append (foundPorts [irKey ], servicePort )
176
176
}
177
177
}
178
-
179
- checkOverlappingTLSConfig (gateway )
180
178
}
179
+
180
+ t .checkOverlappingTLSConfig (gateways )
181
181
}
182
182
183
183
// checkOverlappingTLSConfig checks for overlapping hostnames and certificates between listeners and sets
184
184
// the `OverlappingTLSConfig` condition if there are overlapping hostnames or certificates.
185
- func checkOverlappingTLSConfig (gateway * GatewayContext ) {
186
- // Note: order of processing matters here.
187
- // According to the Gateway API spec, If both hostname and certificate overlap,
188
- // the controller SHOULD set the "OverlappingCertificates" Reason.
189
- checkOverlappingHostnames (gateway )
190
- checkOverlappingCertificates (gateway )
191
- }
192
-
193
- func checkOverlappingHostnames (gateway * GatewayContext ) {
194
- httpsListeners := []* ListenerContext {}
195
- for _ , listener := range gateway .listeners {
196
- if listener .Protocol == gwapiv1 .HTTPSProtocolType {
197
- httpsListeners = append (httpsListeners , listener )
185
+ func (t * Translator ) checkOverlappingTLSConfig (gateways []* GatewayContext ) {
186
+ // If merging gateways, check overlapping hostnames and certificates between listeners in all merged gateways.
187
+ if t .MergeGateways {
188
+ httpsListeners := []* ListenerContext {}
189
+ for _ , gateway := range gateways {
190
+ for _ , listener := range gateway .listeners {
191
+ if listener .Protocol == gwapiv1 .HTTPSProtocolType {
192
+ httpsListeners = append (httpsListeners , listener )
193
+ }
194
+ }
195
+ }
196
+ // Note: order of processing matters here.
197
+ // According to the Gateway API spec, If both hostname and certificate overlap,
198
+ // the controller SHOULD set the "OverlappingCertificates" Reason.
199
+ checkOverlappingHostnames (httpsListeners )
200
+ checkOverlappingCertificates (httpsListeners )
201
+ } else {
202
+ // Check overlapping hostnames and certificates between listeners in each gateway.
203
+ for _ , gateway := range gateways {
204
+ httpsListeners := []* ListenerContext {}
205
+ for _ , listener := range gateway .listeners {
206
+ if listener .Protocol == gwapiv1 .HTTPSProtocolType {
207
+ httpsListeners = append (httpsListeners , listener )
208
+ }
209
+ }
210
+ // Note: order of processing matters here.
211
+ // According to the Gateway API spec, If both hostname and certificate overlap,
212
+ // the controller SHOULD set the "OverlappingCertificates" Reason.
213
+ checkOverlappingHostnames (httpsListeners )
214
+ checkOverlappingCertificates (httpsListeners )
198
215
}
199
216
}
217
+ }
200
218
219
+ // checkOverlappingHostnames checks for overlapping hostnames between HTTPS listeners and sets
220
+ // the `OverlappingTLSConfig` condition if there are overlapping hostnames.
221
+ func checkOverlappingHostnames (httpsListeners []* ListenerContext ) {
201
222
type overlappingListener struct {
223
+ gateway1 * GatewayContext
224
+ gateway2 * GatewayContext
202
225
listener1 string
203
226
listener2 string
204
227
hostname1 string
@@ -219,12 +242,16 @@ func checkOverlappingHostnames(gateway *GatewayContext) {
219
242
if isOverlappingHostname (httpsListeners [i ].Hostname , httpsListeners [j ].Hostname ) {
220
243
// Overlapping listeners can be more than two, we only report the first two for simplicity.
221
244
overlappingListeners [i ] = & overlappingListener {
245
+ gateway1 : httpsListeners [i ].gateway ,
246
+ gateway2 : httpsListeners [j ].gateway ,
222
247
listener1 : string (httpsListeners [i ].Name ),
223
248
listener2 : string (httpsListeners [j ].Name ),
224
249
hostname1 : string (ptr .Deref (httpsListeners [i ].Hostname , "" )),
225
250
hostname2 : string (ptr .Deref (httpsListeners [j ].Hostname , "" )),
226
251
}
227
252
overlappingListeners [j ] = & overlappingListener {
253
+ gateway1 : httpsListeners [j ].gateway ,
254
+ gateway2 : httpsListeners [i ].gateway ,
228
255
listener1 : string (httpsListeners [j ].Name ),
229
256
listener2 : string (httpsListeners [i ].Name ),
230
257
hostname1 : string (ptr .Deref (httpsListeners [j ].Hostname , "" )),
@@ -236,17 +263,33 @@ func checkOverlappingHostnames(gateway *GatewayContext) {
236
263
237
264
for i , listener := range httpsListeners {
238
265
if overlappingListeners [i ] != nil {
239
- status . SetGatewayListenerStatusCondition ( gateway . Gateway ,
240
- listener . listenerStatusIdx ,
241
- gwapiv1 . ListenerConditionOverlappingTLSConfig ,
242
- metav1 . ConditionTrue ,
243
- gwapiv1 . ListenerReasonOverlappingHostnames ,
244
- fmt .Sprintf (
266
+ var message string
267
+ gateway1 := overlappingListeners [ i ]. gateway1
268
+ gateway2 := overlappingListeners [ i ]. gateway2
269
+ if gateway1 . Name == gateway2 . Name &&
270
+ gateway1 . Namespace == gateway2 . Namespace {
271
+ message = fmt .Sprintf (
245
272
"The hostname %s overlaps with the hostname %s in listener %s. ALPN is set to HTTP/1.1 to prevent HTTP/2 connection coalescing" ,
246
273
overlappingListeners [i ].hostname1 ,
247
274
overlappingListeners [i ].hostname2 ,
248
275
overlappingListeners [i ].listener2 ,
249
- ),
276
+ )
277
+ } else {
278
+ message = fmt .Sprintf (
279
+ "The hostname %s overlaps with the hostname %s in listener %s of gateway %s. ALPN is set to HTTP/1.1 to prevent HTTP/2 connection coalescing" ,
280
+ overlappingListeners [i ].hostname1 ,
281
+ overlappingListeners [i ].hostname2 ,
282
+ overlappingListeners [i ].listener2 ,
283
+ gateway2 .GetName (),
284
+ )
285
+ }
286
+
287
+ status .SetGatewayListenerStatusCondition (listener .gateway .Gateway ,
288
+ listener .listenerStatusIdx ,
289
+ gwapiv1 .ListenerConditionOverlappingTLSConfig ,
290
+ metav1 .ConditionTrue ,
291
+ gwapiv1 .ListenerReasonOverlappingHostnames ,
292
+ message ,
250
293
)
251
294
if listener .httpIR != nil {
252
295
listener .httpIR .TLSOverlaps = true
@@ -255,15 +298,12 @@ func checkOverlappingHostnames(gateway *GatewayContext) {
255
298
}
256
299
}
257
300
258
- func checkOverlappingCertificates (gateway * GatewayContext ) {
259
- httpsListeners := []* ListenerContext {}
260
- for _ , listener := range gateway .listeners {
261
- if listener .Protocol == gwapiv1 .HTTPSProtocolType {
262
- httpsListeners = append (httpsListeners , listener )
263
- }
264
- }
265
-
301
+ // checkOverlappingCertificates checks for overlapping certificates SANs between HTTPSlisteners and sets
302
+ // the `OverlappingTLSConfig` condition if there are overlapping certificates.
303
+ func checkOverlappingCertificates (httpsListeners []* ListenerContext ) {
266
304
type overlappingListener struct {
305
+ gateway1 * GatewayContext
306
+ gateway2 * GatewayContext
267
307
listener1 string
268
308
listener2 string
269
309
san1 string
@@ -287,12 +327,16 @@ func checkOverlappingCertificates(gateway *GatewayContext) {
287
327
if overlappingCertificate != nil {
288
328
// Overlapping listeners can be more than two, we only report the first two for simplicity.
289
329
overlappingListeners [i ] = & overlappingListener {
330
+ gateway1 : httpsListeners [i ].gateway ,
331
+ gateway2 : httpsListeners [j ].gateway ,
290
332
listener1 : string (httpsListeners [i ].Name ),
291
333
listener2 : string (httpsListeners [j ].Name ),
292
334
san1 : overlappingCertificate .san1 ,
293
335
san2 : overlappingCertificate .san2 ,
294
336
}
295
337
overlappingListeners [j ] = & overlappingListener {
338
+ gateway1 : httpsListeners [j ].gateway ,
339
+ gateway2 : httpsListeners [i ].gateway ,
296
340
listener1 : string (httpsListeners [j ].Name ),
297
341
listener2 : string (httpsListeners [i ].Name ),
298
342
san1 : overlappingCertificate .san2 ,
@@ -304,17 +348,33 @@ func checkOverlappingCertificates(gateway *GatewayContext) {
304
348
305
349
for i , listener := range httpsListeners {
306
350
if overlappingListeners [i ] != nil {
307
- status . SetGatewayListenerStatusCondition ( gateway . Gateway ,
308
- listener . listenerStatusIdx ,
309
- gwapiv1 . ListenerConditionOverlappingTLSConfig ,
310
- metav1 . ConditionTrue ,
311
- gwapiv1 . ListenerReasonOverlappingCertificates ,
312
- fmt .Sprintf (
351
+ var message string
352
+ gateway1 := overlappingListeners [ i ]. gateway1
353
+ gateway2 := overlappingListeners [ i ]. gateway2
354
+ if gateway1 . Name == gateway2 . Name &&
355
+ gateway1 . Namespace == gateway2 . Namespace {
356
+ message = fmt .Sprintf (
313
357
"The certificate san %s overlaps with the certificate san %s in listener %s. ALPN is set to HTTP/1.1 to prevent HTTP/2 connection coalescing" ,
314
358
overlappingListeners [i ].san1 ,
315
359
overlappingListeners [i ].san2 ,
316
360
overlappingListeners [i ].listener2 ,
317
- ),
361
+ )
362
+ } else {
363
+ message = fmt .Sprintf (
364
+ "The certificate san %s overlaps with the certificate san %s in listener %s of gateway %s. ALPN is set to HTTP/1.1 to prevent HTTP/2 connection coalescing" ,
365
+ overlappingListeners [i ].san1 ,
366
+ overlappingListeners [i ].san2 ,
367
+ overlappingListeners [i ].listener2 ,
368
+ gateway2 .GetName (),
369
+ )
370
+ }
371
+
372
+ status .SetGatewayListenerStatusCondition (listener .gateway .Gateway ,
373
+ listener .listenerStatusIdx ,
374
+ gwapiv1 .ListenerConditionOverlappingTLSConfig ,
375
+ metav1 .ConditionTrue ,
376
+ gwapiv1 .ListenerReasonOverlappingCertificates ,
377
+ message ,
318
378
)
319
379
if listener .httpIR != nil {
320
380
listener .httpIR .TLSOverlaps = true
0 commit comments