Skip to content

Commit 0dcd6c9

Browse files
committed
chore: move into pre-existing conditions check
1 parent 11ca783 commit 0dcd6c9

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

source/gateway.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,8 @@ func (c *gatewayRouteResolver) resolve(rt gatewayRoute) (map[string]endpoint.Tar
307307
for _, rps := range rt.RouteStatus().Parents {
308308
// Confirm the Parent is the standard Gateway kind.
309309
ref := rps.ParentRef
310-
311310
namespace := strVal((*string)(ref.Namespace), meta.Namespace)
312311

313-
// Ensure that the parent reference is for the current generation
314-
if len(rps.Conditions) > 0 && rps.Conditions[0].ObservedGeneration != meta.Generation {
315-
log.Debugf("Ignoring parent %s/%s of %s/%s as generation %d does not match current generation %d", namespace, ref.Name, meta.Namespace, meta.Name, rps.Conditions[0].ObservedGeneration, meta.Generation)
316-
continue
317-
}
318-
319312
// Ensure that the parent reference is in the routeParentRefs list
320313
if !gwRouteHasParentRef(routeParentRefs, ref, meta) {
321314
log.Debugf("Parent reference %s/%s not found in routeParentRefs for %s %s/%s", namespace, string(ref.Name), c.src.rtKind, meta.Namespace, meta.Name)
@@ -341,10 +334,11 @@ func (c *gatewayRouteResolver) resolve(rt gatewayRoute) (map[string]endpoint.Tar
341334
}
342335

343336
// Confirm the Gateway has accepted the Route.
344-
if !gwRouteIsAccepted(rps.Conditions) {
345-
log.Debugf("Gateway %s/%s has not accepted %s %s/%s", namespace, ref.Name, c.src.rtKind, meta.Namespace, meta.Name)
337+
if !gwRouteIsAccepted(rps.Conditions, meta) {
338+
log.Debugf("Gateway %s/%s has not accepted the current generation %s %s/%s", namespace, ref.Name, c.src.rtKind, meta.Namespace, meta.Name)
346339
continue
347340
}
341+
348342
// Match the Route to all possible Listeners.
349343
match := false
350344
section := sectionVal(ref.SectionName, "")
@@ -502,10 +496,10 @@ func gwRouteHasParentRef(routeParentRefs []v1.ParentReference, ref v1.ParentRefe
502496
return false
503497
}
504498

505-
func gwRouteIsAccepted(conds []metav1.Condition) bool {
499+
func gwRouteIsAccepted(conds []metav1.Condition, meta *metav1.ObjectMeta) bool {
506500
for _, c := range conds {
507501
if v1.RouteConditionType(c.Type) == v1.RouteConditionAccepted {
508-
return c.Status == metav1.ConditionTrue
502+
return c.Status == metav1.ConditionTrue && c.ObservedGeneration == meta.Generation
509503
}
510504
}
511505
return false

source/gateway_httproute_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
246246
newTestEndpoint("test.example.internal", "A", "1.2.3.4"),
247247
},
248248
logExpectations: []string{
249-
"level=debug msg=\"Ignoring parent gateway-namespace/gateway-name of route-namespace/old-test as generation 4 does not match current generation 5\"",
249+
"level=debug msg=\"Gateway gateway-namespace/gateway-name has not accepted the current generation HTTPRoute route-namespace/old-test\"",
250250
},
251251
},
252252
{

0 commit comments

Comments
 (0)