Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix integration tests: wait for route to be accepted #339

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 4 additions & 26 deletions controllers/authpolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// attach policy to the gatewaay
gwPolicy := &api.AuthPolicy{
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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{}
Expand Down
16 changes: 16 additions & 0 deletions controllers/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
3 changes: 3 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(testRouteIsAccepted(client.ObjectKeyFromObject(httpRoute)), 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(testRouteIsAccepted(client.ObjectKeyFromObject(httpRoute)), 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(testRouteIsAccepted(client.ObjectKeyFromObject(httpRoute)), time.Minute, 5*time.Second).Should(BeTrue())

// create ratelimitpolicy
rlp := &kuadrantv1beta2.RateLimitPolicy{
Expand Down
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 @@
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"))

Check warning on line 126 in pkg/reconcilers/targetref_reconciler.go

View check run for this annotation

Codecov / codecov/patch

pkg/reconcilers/targetref_reconciler.go#L123-L126

Added lines #L123 - L126 were not covered by tests
}

return
Expand Down
Loading