diff --git a/controllers/authpolicy_controller_test.go b/controllers/authpolicy_controller_test.go index e25d068ed..dba7cd1fd 100644 --- a/controllers/authpolicy_controller_test.go +++ b/controllers/authpolicy_controller_test.go @@ -26,7 +26,6 @@ import ( authorinoapi "github.com/kuadrant/authorino/api/v1beta2" api "github.com/kuadrant/kuadrant-operator/api/v1beta2" - "github.com/kuadrant/kuadrant-operator/pkg/common" ) const ( @@ -59,12 +58,7 @@ var _ = Describe("AuthPolicy controller", func() { route := testBuildBasicHttpRoute(testHTTPRouteName, testGatewayName, testNamespace, []string{"*.toystore.com"}) err = k8sClient.Create(context.Background(), route) Expect(err).ToNot(HaveOccurred()) - - Eventually(func() bool { - existingRoute := &gatewayapiv1.HTTPRoute{} - err := k8sClient.Get(context.Background(), client.ObjectKeyFromObject(route), existingRoute) - return err == nil && common.IsHTTPRouteAccepted(existingRoute) - }, 15*time.Second, 5*time.Second).Should(BeTrue()) + Eventually(testRouteIsAccepted(client.ObjectKeyFromObject(route)), time.Minute, 5*time.Second).Should(BeTrue()) }) It("Attaches policy to the Gateway", func() { @@ -144,11 +138,7 @@ var _ = Describe("AuthPolicy controller", func() { route := testBuildBasicHttpRoute(routeName, gatewayName, testNamespace, []string{"*.api.example.com"}) err = k8sClient.Create(context.Background(), route) Expect(err).ToNot(HaveOccurred()) - Eventually(func() bool { - existingRoute := &gatewayapiv1.HTTPRoute{} - err := k8sClient.Get(context.Background(), client.ObjectKeyFromObject(route), existingRoute) - return err == nil && common.IsHTTPRouteAccepted(existingRoute) - }, 15*time.Second, 5*time.Second).Should(BeTrue()) + Eventually(testRouteIsAccepted(client.ObjectKeyFromObject(route)), time.Minute, 5*time.Second).Should(BeTrue()) policy := &api.AuthPolicy{ ObjectMeta: metav1.ObjectMeta{ @@ -282,6 +272,7 @@ var _ = Describe("AuthPolicy controller", func() { } err = k8sClient.Create(context.Background(), otherRoute) Expect(err).ToNot(HaveOccurred()) + Eventually(testRouteIsAccepted(client.ObjectKeyFromObject(otherRoute)), time.Minute, 5*time.Second).Should(BeTrue()) // attach policy to the gatewaay gwPolicy := &api.AuthPolicy{ @@ -835,12 +826,7 @@ var _ = Describe("AuthPolicy controller", func() { route := testBuildMultipleRulesHttpRoute(testHTTPRouteName, testGatewayName, testNamespace, []string{"*.toystore.com", "*.admin.toystore.com"}) err = k8sClient.Create(context.Background(), route) Expect(err).ToNot(HaveOccurred()) - - Eventually(func() bool { - existingRoute := &gatewayapiv1.HTTPRoute{} - err := k8sClient.Get(context.Background(), client.ObjectKeyFromObject(route), existingRoute) - return err == nil && common.IsHTTPRouteAccepted(existingRoute) - }, 15*time.Second, 5*time.Second).Should(BeTrue()) + Eventually(testRouteIsAccepted(client.ObjectKeyFromObject(route)), time.Minute, 5*time.Second).Should(BeTrue()) }) It("Attaches simple policy to the HTTPRoute", func() { @@ -1299,14 +1285,6 @@ func testBasicAuthScheme() api.AuthSchemeSpec { } } -func testGatewayIsReady(gateway *gatewayapiv1.Gateway) func() bool { - return func() bool { - existingGateway := &gatewayapiv1.Gateway{} - err := k8sClient.Get(context.Background(), client.ObjectKeyFromObject(gateway), existingGateway) - return err == nil && meta.IsStatusConditionTrue(existingGateway.Status.Conditions, common.GatewayProgrammedConditionType) - } -} - func testPolicyIsReady(policy *api.AuthPolicy) func() bool { return func() bool { existingPolicy := &api.AuthPolicy{} diff --git a/controllers/helper_test.go b/controllers/helper_test.go index 3dcd62805..dd7b8583f 100644 --- a/controllers/helper_test.go +++ b/controllers/helper_test.go @@ -280,3 +280,19 @@ func testBuildMultipleRulesHttpRoute(routeName, gwName, ns string, hostnames []s } return route } + +func testRouteIsAccepted(routeKey client.ObjectKey) func() bool { + return func() bool { + route := &gatewayapiv1.HTTPRoute{} + err := k8sClient.Get(context.Background(), routeKey, route) + return err == nil && common.IsHTTPRouteAccepted(route) + } +} + +func testGatewayIsReady(gateway *gatewayapiv1.Gateway) func() bool { + return func() bool { + existingGateway := &gatewayapiv1.Gateway{} + err := k8sClient.Get(context.Background(), client.ObjectKeyFromObject(gateway), existingGateway) + return err == nil && meta.IsStatusConditionTrue(existingGateway.Status.Conditions, common.GatewayProgrammedConditionType) + } +} diff --git a/controllers/ratelimitpolicy_controller_test.go b/controllers/ratelimitpolicy_controller_test.go index eb6181dce..b59dc0fd3 100644 --- a/controllers/ratelimitpolicy_controller_test.go +++ b/controllers/ratelimitpolicy_controller_test.go @@ -82,7 +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()) + Eventually(testRouteIsAccepted(client.ObjectKeyFromObject(httpRoute)), time.Minute, 5*time.Second).Should(BeTrue()) // create ratelimitpolicy rlp := &kuadrantv1beta2.RateLimitPolicy{ @@ -239,7 +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()) + Eventually(testRouteIsAccepted(client.ObjectKeyFromObject(httpRoute)), time.Minute, 5*time.Second).Should(BeTrue()) // create ratelimitpolicy rlp := &kuadrantv1beta2.RateLimitPolicy{ @@ -423,7 +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()) + Eventually(testRouteIsAccepted(client.ObjectKeyFromObject(httpRoute)), time.Minute, 5*time.Second).Should(BeTrue()) // create ratelimitpolicy rlp := &kuadrantv1beta2.RateLimitPolicy{ @@ -654,29 +654,3 @@ 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 - } -}