func()

in pkg/controllers/route_controller.go [492:534]


func (r *routeReconciler) validateRouteParentRefs(ctx context.Context, route core.Route) ([]gwv1.RouteParentStatus, error) {
	if len(route.Spec().ParentRefs()) == 0 {
		return nil, ErrParentRefsNotFound
	}

	parentStatuses := []gwv1.RouteParentStatus{}
	gws, err := k8s.FindControlledParents(ctx, r.client, route)
	if len(gws) <= 0 {
		return nil, fmt.Errorf("failed to get gateway for route %s: %w", route.Name(), err)
	}
	// TODO assume one parent for now and point to service network
	gw := gws[0]
	for _, parentRef := range route.Spec().ParentRefs() {
		noMatchingParent := true
		for _, listener := range gw.Spec.Listeners {
			if parentRef.Port != nil && *parentRef.Port != listener.Port {
				continue
			}
			if parentRef.SectionName != nil && *parentRef.SectionName != listener.Name {
				continue
			}
			noMatchingParent = false
		}

		parentStatus := gwv1.RouteParentStatus{
			ParentRef:      parentRef,
			ControllerName: config.LatticeGatewayControllerName,
			Conditions:     []metav1.Condition{},
		}

		var cnd metav1.Condition
		switch {
		case noMatchingParent:
			cnd = r.newCondition(route, gwv1.RouteConditionAccepted, gwv1.RouteReasonNoMatchingParent, "")
		default:
			cnd = r.newCondition(route, gwv1.RouteConditionAccepted, gwv1.RouteReasonAccepted, "")
		}
		meta.SetStatusCondition(&parentStatus.Conditions, cnd)
		parentStatuses = append(parentStatuses, parentStatus)
	}

	return parentStatuses, nil
}