Skip to content

Commit 9854a0e

Browse files
committed
validate group and kind on the spec.parentRef. Move check into gwRouteHasParentRef
1 parent 1476fe1 commit 9854a0e

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

source/gateway.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -307,16 +307,11 @@ 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-
// Ensure that the parent reference is in the routeParentRefs list
311-
found := false
312-
for _, rpr := range routeParentRefs {
313-
if string(rpr.Name) == string(ref.Name) && string(*rpr.Namespace) == string(*ref.Namespace) {
314-
found = true
315-
break
316-
}
317-
}
318310
namespace := strVal((*string)(ref.Namespace), meta.Namespace)
319-
if !found {
311+
// Ensure that the parent reference is in the routeParentRefs list
312+
hasParentRef := gwRouteHasParentRef(routeParentRefs, ref, meta)
313+
314+
if !hasParentRef {
320315
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)
321316
continue
322317
}
@@ -481,6 +476,26 @@ func (c *gatewayRouteResolver) routeIsAllowed(gw *v1beta1.Gateway, lis *v1.Liste
481476
return false
482477
}
483478

479+
func gwRouteHasParentRef(routeParentRefs []v1.ParentReference, ref v1.ParentReference, meta *metav1.ObjectMeta) bool {
480+
// Ensure that the parent reference is in the routeParentRefs list
481+
namespace := strVal((*string)(ref.Namespace), meta.Namespace)
482+
group := strVal((*string)(ref.Group), gatewayGroup)
483+
kind := strVal((*string)(ref.Kind), gatewayKind)
484+
for _, rpr := range routeParentRefs {
485+
rprGroup := strVal((*string)(rpr.Group), gatewayGroup)
486+
rprKind := strVal((*string)(rpr.Kind), gatewayKind)
487+
if rprGroup != group || rprKind != kind {
488+
continue
489+
}
490+
rprNamespace := strVal((*string)(rpr.Namespace), meta.Namespace)
491+
if string(rpr.Name) != string(ref.Name) || rprNamespace != namespace {
492+
continue
493+
}
494+
return true
495+
}
496+
return false
497+
}
498+
484499
func gwRouteIsAccepted(conds []metav1.Condition) bool {
485500
for _, c := range conds {
486501
if v1.RouteConditionType(c.Type) == v1.RouteConditionAccepted {

0 commit comments

Comments
 (0)