func()

in pkg/controllers/route_controller.go [541:581]


func (r *routeReconciler) validateBackedRefs(ctx context.Context, route core.Route) (metav1.Condition, error) {
	var empty metav1.Condition
	for _, rule := range route.Spec().Rules() {
		for _, ref := range rule.BackendRefs() {
			kind := "Service"
			if ref.Kind() != nil {
				kind = string(*ref.Kind())
			}
			if !validBackendKinds.Contains(kind) {
				return r.newCondition(route, gwv1.RouteConditionResolvedRefs, gwv1.RouteReasonInvalidKind, kind), nil
			}

			namespace := route.Namespace()
			if ref.Namespace() != nil {
				namespace = string(*ref.Namespace())
			}
			objKey := types.NamespacedName{
				Namespace: namespace,
				Name:      string(ref.Name()),
			}
			var obj client.Object

			switch kind {
			case "Service":
				obj = &corev1.Service{}
			case "ServiceImport":
				obj = &anv1alpha1.ServiceImport{}
			default:
				return empty, fmt.Errorf("invalid backed end ref kind, must be validated before, kind=%s", kind)
			}
			err := r.client.Get(ctx, objKey, obj)
			if err != nil {
				if apierrors.IsNotFound(err) {
					msg := fmt.Sprintf("backendRef name: %s", ref.Name())
					return r.newCondition(route, gwv1.RouteConditionResolvedRefs, gwv1.RouteReasonBackendNotFound, msg), nil
				}
			}
		}
	}
	return r.newCondition(route, gwv1.RouteConditionResolvedRefs, gwv1.RouteReasonResolvedRefs, ""), nil
}