diff --git a/controllers/ratelimitpolicy_controller_test.go b/controllers/ratelimitpolicy_controller_test.go index c635bef3b..eb6181dce 100644 --- a/controllers/ratelimitpolicy_controller_test.go +++ b/controllers/ratelimitpolicy_controller_test.go @@ -82,6 +82,7 @@ var _ = Describe("RateLimitPolicy controller", func() { httpRoute := testBuildBasicHttpRoute(routeName, gwName, testNamespace, []string{"*.example.com"}) err := k8sClient.Create(context.Background(), httpRoute) Expect(err).ToNot(HaveOccurred()) + Eventually(testRouteIsAcceptedByGateway(client.ObjectKeyFromObject(httpRoute), gateway), time.Minute, 5*time.Second).Should(BeTrue()) // create ratelimitpolicy rlp := &kuadrantv1beta2.RateLimitPolicy{ @@ -238,6 +239,7 @@ var _ = Describe("RateLimitPolicy controller", func() { } err := k8sClient.Create(context.Background(), httpRoute) Expect(err).ToNot(HaveOccurred()) + Eventually(testRouteIsAcceptedByGateway(client.ObjectKeyFromObject(httpRoute), gateway), time.Minute, 5*time.Second).Should(BeTrue()) // create ratelimitpolicy rlp := &kuadrantv1beta2.RateLimitPolicy{ @@ -421,6 +423,7 @@ var _ = Describe("RateLimitPolicy controller", func() { httpRoute := testBuildBasicHttpRoute(routeName, gwName, testNamespace, []string{"*.example.com"}) err := k8sClient.Create(context.Background(), httpRoute) Expect(err).ToNot(HaveOccurred()) + Eventually(testRouteIsAcceptedByGateway(client.ObjectKeyFromObject(httpRoute), gateway), time.Minute, 5*time.Second).Should(BeTrue()) // create ratelimitpolicy rlp := &kuadrantv1beta2.RateLimitPolicy{ @@ -651,3 +654,29 @@ func testWasmPluginIsAvailable(key client.ObjectKey) func() bool { return true } } + +func testRouteIsAcceptedByGateway(key client.ObjectKey, gateway *gatewayapiv1.Gateway) func() bool { + return func() bool { + route := &gatewayapiv1.HTTPRoute{} + err := k8sClient.Get(context.Background(), key, route) + if err != nil { + return false + } + + routeParentStatus, found := common.Find(route.Status.RouteStatus.Parents, func(p gatewayapiv1.RouteParentStatus) bool { + return *p.ParentRef.Kind == ("Gateway") && + ((p.ParentRef.Namespace == nil && route.GetNamespace() == gateway.Namespace) || string(*p.ParentRef.Namespace) == gateway.Namespace) && + string(p.ParentRef.Name) == gateway.Name + }) + + if !found { + return false + } + + if !meta.IsStatusConditionTrue(routeParentStatus.Conditions, "Accepted") { + return false + } + + return true + } +} diff --git a/pkg/reconcilers/targetref_reconciler.go b/pkg/reconcilers/targetref_reconciler.go index fd605c4ab..01040cb57 100644 --- a/pkg/reconcilers/targetref_reconciler.go +++ b/pkg/reconcilers/targetref_reconciler.go @@ -119,7 +119,11 @@ func (r *TargetRefReconciler) FetchAcceptedGatewayHTTPRoutes(ctx context.Context routes = append(routes, route) continue } - logger.V(1).Info("skipping route, not attached to gateway", "httproute", client.ObjectKeyFromObject(&route)) + + logger.V(1).Info("skipping route, not attached to gateway", + "httproute", client.ObjectKeyFromObject(&route), + "isChildRoute", found, + "isAccepted", routeParentStatus != nil && meta.IsStatusConditionTrue(routeParentStatus.Conditions, "Accepted")) } return