Skip to content

Commit

Permalink
rlp integration tests: wait for route to be accepted
Browse files Browse the repository at this point in the history
  • Loading branch information
eguzki committed Nov 27, 2023
1 parent 050f417 commit 249b441
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
29 changes: 29 additions & 0 deletions controllers/ratelimitpolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
}
}
6 changes: 5 additions & 1 deletion pkg/reconcilers/targetref_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 249b441

Please sign in to comment.