Skip to content

Commit e989183

Browse files
committed
Review feedback round 3
1 parent c531f8e commit e989183

File tree

1 file changed

+51
-55
lines changed

1 file changed

+51
-55
lines changed

internal/mode/static/state/graph/route_common.go

+51-55
Original file line numberDiff line numberDiff line change
@@ -253,76 +253,72 @@ func bindRouteToListeners(
253253
return
254254
}
255255

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
265262

266-
attachableListeners, listenerExists := findAttachableListeners(
267-
getSectionName(ref.SectionName),
268-
gw.Listeners,
269-
)
263+
path := field.NewPath("spec").Child("parentRefs").Index(ref.Idx)
270264

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+
)
277269

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+
}
279276

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
285278

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+
}
287284

288-
referencesWinningGw := ref.Gateway.Namespace == gw.Source.Namespace && ref.Gateway.Name == gw.Source.Name
285+
// Case 3: the parentRef references an ignored Gateway resource.
289286

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
294288

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+
}
296293

297-
if !gw.Valid {
298-
attachment.FailedCondition = staticConds.NewRouteInvalidGateway()
299-
continue
300-
}
294+
// Case 4: Attachment is not possible because Gateway is invalid
301295

302-
// Case 5 - winning Gateway
296+
if !gw.Valid {
297+
attachment.FailedCondition = staticConds.NewRouteInvalidGateway()
298+
continue
299+
}
303300

304-
// Try to attach Route to all matching listeners
301+
// Case 5 - winning Gateway
305302

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
320304

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)
322318
}
323-
}
324319

325-
bindRoutes(route)
320+
attachment.Attached = true
321+
}
326322
}
327323

328324
// tryToAttachRouteToListeners tries to attach the route to the listeners that match the parentRef and the hostnames.

0 commit comments

Comments
 (0)