@@ -253,76 +253,72 @@ func bindRouteToListeners(
253
253
return
254
254
}
255
255
256
- bindRoutes := func (r * L7Route ) {
257
- for i := 0 ; i < len (r .ParentRefs ); i ++ {
258
- attachment := & ParentRefAttachmentStatus {
259
- AcceptedHostnames : make (map [string ][]string ),
260
- }
261
- ref := & r .ParentRefs [i ]
262
- ref .Attachment = attachment
263
-
264
- path := field .NewPath ("spec" ).Child ("parentRefs" ).Index (ref .Idx )
256
+ for i := 0 ; i < len (route .ParentRefs ); i ++ {
257
+ attachment := & ParentRefAttachmentStatus {
258
+ AcceptedHostnames : make (map [string ][]string ),
259
+ }
260
+ ref := & route .ParentRefs [i ]
261
+ ref .Attachment = attachment
265
262
266
- attachableListeners , listenerExists := findAttachableListeners (
267
- getSectionName (ref .SectionName ),
268
- gw .Listeners ,
269
- )
263
+ path := field .NewPath ("spec" ).Child ("parentRefs" ).Index (ref .Idx )
270
264
271
- // Case 1: Attachment is not possible because the specified SectionName does not match any Listeners in the
272
- // Gateway.
273
- if ! listenerExists {
274
- attachment .FailedCondition = staticConds .NewRouteNoMatchingParent ()
275
- continue
276
- }
265
+ attachableListeners , listenerExists := findAttachableListeners (
266
+ getSectionName (ref .SectionName ),
267
+ gw .Listeners ,
268
+ )
277
269
278
- // Case 2: Attachment is not possible due to unsupported configuration
270
+ // Case 1: Attachment is not possible because the specified SectionName does not match any Listeners in the
271
+ // Gateway.
272
+ if ! listenerExists {
273
+ attachment .FailedCondition = staticConds .NewRouteNoMatchingParent ()
274
+ continue
275
+ }
279
276
280
- if ref .Port != nil {
281
- valErr := field .Forbidden (path .Child ("port" ), "cannot be set" )
282
- attachment .FailedCondition = staticConds .NewRouteUnsupportedValue (valErr .Error ())
283
- continue
284
- }
277
+ // Case 2: Attachment is not possible due to unsupported configuration
285
278
286
- // Case 3: the parentRef references an ignored Gateway resource.
279
+ if ref .Port != nil {
280
+ valErr := field .Forbidden (path .Child ("port" ), "cannot be set" )
281
+ attachment .FailedCondition = staticConds .NewRouteUnsupportedValue (valErr .Error ())
282
+ continue
283
+ }
287
284
288
- referencesWinningGw := ref . Gateway . Namespace == gw . Source . Namespace && ref . Gateway . Name == gw . Source . Name
285
+ // Case 3: the parentRef references an ignored Gateway resource.
289
286
290
- if ! referencesWinningGw {
291
- attachment .FailedCondition = staticConds .NewTODO ("Gateway is ignored" )
292
- continue
293
- }
287
+ referencesWinningGw := ref .Gateway .Namespace == gw .Source .Namespace && ref .Gateway .Name == gw .Source .Name
294
288
295
- // Case 4: Attachment is not possible because Gateway is invalid
289
+ if ! referencesWinningGw {
290
+ attachment .FailedCondition = staticConds .NewTODO ("Gateway is ignored" )
291
+ continue
292
+ }
296
293
297
- if ! gw .Valid {
298
- attachment .FailedCondition = staticConds .NewRouteInvalidGateway ()
299
- continue
300
- }
294
+ // Case 4: Attachment is not possible because Gateway is invalid
301
295
302
- // Case 5 - winning Gateway
296
+ if ! gw .Valid {
297
+ attachment .FailedCondition = staticConds .NewRouteInvalidGateway ()
298
+ continue
299
+ }
303
300
304
- // Try to attach Route to all matching listeners
301
+ // Case 5 - winning Gateway
305
302
306
- cond , attached := tryToAttachRouteToListeners (
307
- ref .Attachment ,
308
- attachableListeners ,
309
- r ,
310
- gw ,
311
- namespaces ,
312
- )
313
- if ! attached {
314
- attachment .FailedCondition = cond
315
- continue
316
- }
317
- if cond != (conditions.Condition {}) {
318
- r .Conditions = append (r .Conditions , cond )
319
- }
303
+ // Try to attach Route to all matching listeners
320
304
321
- attachment .Attached = true
305
+ cond , attached := tryToAttachRouteToListeners (
306
+ ref .Attachment ,
307
+ attachableListeners ,
308
+ route ,
309
+ gw ,
310
+ namespaces ,
311
+ )
312
+ if ! attached {
313
+ attachment .FailedCondition = cond
314
+ continue
315
+ }
316
+ if cond != (conditions.Condition {}) {
317
+ route .Conditions = append (route .Conditions , cond )
322
318
}
323
- }
324
319
325
- bindRoutes (route )
320
+ attachment .Attached = true
321
+ }
326
322
}
327
323
328
324
// tryToAttachRouteToListeners tries to attach the route to the listeners that match the parentRef and the hostnames.
0 commit comments