Skip to content

Commit

Permalink
tests: add testing enforced condition to other integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KevFan committed Apr 22, 2024
1 parent 92565f5 commit 5ca771b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ var _ = Describe("Limitador Cluster EnvoyFilter controller", func() {
// Check RLP status is available
rlpKey := client.ObjectKey{Name: rlpName, Namespace: testNamespace}
Eventually(testRLPIsAccepted(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())

// Check envoy filter
Eventually(func() bool {
Expand Down
19 changes: 19 additions & 0 deletions controllers/rate_limiting_wasmplugin_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

kuadrantv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2"
"github.com/kuadrant/kuadrant-operator/pkg/common"
"github.com/kuadrant/kuadrant-operator/pkg/library/kuadrant"
"github.com/kuadrant/kuadrant-operator/pkg/rlptools"
"github.com/kuadrant/kuadrant-operator/pkg/rlptools/wasm"
)
Expand Down Expand Up @@ -93,6 +94,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
// Check RLP status is available
rlpKey := client.ObjectKeyFromObject(rlp)
Eventually(testRLPIsAccepted(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())

// Check wasm plugin
wasmPluginKey := client.ObjectKey{Name: rlptools.WASMPluginName(gateway), Namespace: testNamespace}
Expand Down Expand Up @@ -253,6 +255,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
// Check RLP status is available
rlpKey := client.ObjectKeyFromObject(rlp)
Eventually(testRLPIsAccepted(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())

// Check wasm plugin
wasmPluginKey := client.ObjectKey{Name: rlptools.WASMPluginName(gateway), Namespace: testNamespace}
Expand Down Expand Up @@ -396,6 +399,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
// Check RLP status is available
rlpKey := client.ObjectKey{Name: rlpName, Namespace: testNamespace}
Eventually(testRLPIsAccepted(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())

// Check wasm plugin
wasmPluginKey := client.ObjectKey{Name: rlptools.WASMPluginName(gateway), Namespace: testNamespace}
Expand Down Expand Up @@ -496,6 +500,8 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
// Check RLP status is available
rlpKey := client.ObjectKey{Name: rlpName, Namespace: testNamespace}
Eventually(testRLPIsAccepted(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpKey), time.Minute, 5*time.Second).Should(BeFalse())
Expect(testRLPEnforcedCondition(rlpKey, kuadrant.PolicyReasonUnknown, "RateLimitPolicy has encountered some issues: no free routes to enforce policy"))

// Check wasm plugin
wasmPluginKey := client.ObjectKey{Name: rlptools.WASMPluginName(gateway), Namespace: testNamespace}
Expand Down Expand Up @@ -575,6 +581,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
// Check RLP status is available
rlpKey := client.ObjectKeyFromObject(rlp)
Eventually(testRLPIsAccepted(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())

// Check wasm plugin
wasmPluginKey := client.ObjectKey{Name: rlptools.WASMPluginName(gateway), Namespace: testNamespace}
Expand Down Expand Up @@ -637,6 +644,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
// Check RLP status is available
rlpAKey := client.ObjectKey{Name: rlpAName, Namespace: testNamespace}
Eventually(testRLPIsAccepted(rlpAKey), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpAKey), time.Minute, 5*time.Second).Should(BeTrue())

// create httproute C
httpRouteC := testBuildBasicHttpRoute(routeCName, gwName, testNamespace, []string{"*.c.example.com"})
Expand Down Expand Up @@ -701,6 +709,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
// Check RLP status is available
rlpBKey := client.ObjectKey{Name: rlpBName, Namespace: testNamespace}
Eventually(testRLPIsAccepted(rlpBKey), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpBKey), time.Minute, 5*time.Second).Should(BeTrue())

// Check wasm plugin only has configuration ONLY from the RLP targeting the gateway
// it may take some reconciliation loops to get to that, so checking it with eventually
Expand Down Expand Up @@ -834,12 +843,15 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
// Check RLP status is available
rlpKey := client.ObjectKey{Name: rlpName, Namespace: testNamespace}
Eventually(testRLPIsAccepted(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpKey), time.Minute, 5*time.Second).Should(BeFalse())
Expect(testRLPEnforcedCondition(rlpKey, kuadrant.PolicyReasonUnknown, "RateLimitPolicy has encountered some issues: no free routes to enforce policy"))

// create Route A -> Gw A
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())
Eventually(testRLPIsEnforced(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())

// create Gateway B
gwB := testBuildBasicGateway(gwBName, testNamespace)
Expand Down Expand Up @@ -1039,6 +1051,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
// Check RLP status is available
rlpKey := client.ObjectKey{Name: rlpName, Namespace: testNamespace}
Eventually(testRLPIsAccepted(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())

// Initial state set.
// Check wasm plugin for gateway A has configuration from the route
Expand Down Expand Up @@ -1334,6 +1347,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
// Check RLP status is available
rlpKey := client.ObjectKey{Name: rlpName, Namespace: testNamespace}
Eventually(testRLPIsAccepted(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())

// Initial state set.
// Check wasm plugin has configuration from the route A
Expand Down Expand Up @@ -1567,6 +1581,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
// Check RLP status is available
rlp1Key := client.ObjectKey{Name: rlp1Name, Namespace: testNamespace}
Eventually(testRLPIsAccepted(rlp1Key), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlp1Key), time.Minute, 5*time.Second).Should(BeTrue())

// Initial state set.
// Check wasm plugin for gateway A has configuration from the route 1
Expand Down Expand Up @@ -1671,6 +1686,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
// Check RLP status is available
rlp2Key := client.ObjectKey{Name: rlp2Name, Namespace: testNamespace}
Eventually(testRLPIsAccepted(rlp2Key), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlp2Key), time.Minute, 5*time.Second).Should(BeTrue())

// Check wasm plugin has configuration from the route A and RLP 2.
// RLP 1 should not add any config to the wasm plugin
Expand Down Expand Up @@ -1830,6 +1846,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
// Check RLP status is available
rlp1Key := client.ObjectKey{Name: rlp1Name, Namespace: testNamespace}
Eventually(testRLPIsAccepted(rlp1Key), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlp1Key), time.Minute, 5*time.Second).Should(BeTrue())

// create RLP 2 -> Route A
rlp2 := &kuadrantv1beta2.RateLimitPolicy{
Expand Down Expand Up @@ -1861,6 +1878,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
// Check RLP status is available
rlp2Key := client.ObjectKey{Name: rlp2Name, Namespace: testNamespace}
Eventually(testRLPIsAccepted(rlp2Key), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlp2Key), time.Minute, 5*time.Second).Should(BeTrue())

// Initial state set.
// Check wasm plugin for gateway A has configuration from the route A only affected by RLP 2
Expand Down Expand Up @@ -2127,6 +2145,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
// Check RLP status is available
rlpKey := client.ObjectKeyFromObject(rlp)
Eventually(testRLPIsAccepted(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())

// Check wasm plugin
wasmPluginKey := client.ObjectKey{Name: rlptools.WASMPluginName(gateway), Namespace: testNamespace}
Expand Down
21 changes: 20 additions & 1 deletion controllers/ratelimitpolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ var _ = Describe("RateLimitPolicy controller", func() {
// Check RLP status is available
rlpKey := client.ObjectKeyFromObject(rlp)
Eventually(testRLPIsAccepted(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())

// Check HTTPRoute direct back reference
routeKey := client.ObjectKey{Name: routeName, Namespace: testNamespace}
Expand Down Expand Up @@ -184,6 +185,7 @@ var _ = Describe("RateLimitPolicy controller", func() {
// Check RLP status is available
rlpKey := client.ObjectKey{Name: rlpName, Namespace: testNamespace}
Eventually(testRLPIsAccepted(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())

// Check Gateway direct back reference
gwKey := client.ObjectKeyFromObject(gateway)
Expand Down Expand Up @@ -231,6 +233,8 @@ var _ = Describe("RateLimitPolicy controller", func() {
// Check RLP status is available
rlpKey := client.ObjectKey{Name: rlpName, Namespace: testNamespace}
Eventually(testRLPIsAccepted(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpKey), time.Minute, 5*time.Second).Should(BeFalse())
Expect(testRLPEnforcedCondition(rlpKey, kuadrant.PolicyReasonUnknown, "RateLimitPolicy has encountered some issues: no free routes to enforce policy"))

// Check Gateway direct back reference
gwKey := client.ObjectKeyFromObject(gateway)
Expand Down Expand Up @@ -283,6 +287,7 @@ var _ = Describe("RateLimitPolicy controller", func() {
Expect(k8sClient.Create(ctx, gwRLP)).To(Succeed())
rlpKey := client.ObjectKey{Name: gwRLP.Name, Namespace: testNamespace}
Eventually(testRLPIsAccepted(rlpKey)).WithContext(ctx).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpKey)).WithContext(ctx).Should(BeTrue())

// Create HTTPRoute RLP with new default limits
routeRLP := policyFactory(func(policy *kuadrantv1beta2.RateLimitPolicy) {
Expand All @@ -300,6 +305,7 @@ var _ = Describe("RateLimitPolicy controller", func() {
Expect(k8sClient.Create(ctx, routeRLP)).To(Succeed())
rlpKey = client.ObjectKey{Name: routeRLP.Name, Namespace: testNamespace}
Eventually(testRLPIsAccepted(rlpKey)).WithContext(ctx).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpKey)).WithContext(ctx).Should(BeTrue())

// Check Gateway direct back reference
gwKey := client.ObjectKeyFromObject(gateway)
Expand Down Expand Up @@ -653,7 +659,7 @@ var _ = Describe("RateLimitPolicy controller", func() {
).WithContext(ctx).Should(Succeed())
}, SpecTimeout(2*time.Minute))

It("Validation reason", func(ctx SpecContext) {
It("RLP Validation reason", func(ctx SpecContext) {
const targetRefName, targetRefNamespace = "istio-ingressgateway", "istio-system"

rlp := policyFactory(func(policy *kuadrantv1beta2.RateLimitPolicy) {
Expand Down Expand Up @@ -763,6 +769,7 @@ var _ = Describe("RateLimitPolicy controller", func() {
// Check RLP status is available
rlpKey := client.ObjectKeyFromObject(rlp)
Eventually(testRLPIsAccepted(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())

// Check HTTPRoute A direct back reference
routeAKey := client.ObjectKey{Name: routeAName, Namespace: testNamespace}
Expand Down Expand Up @@ -791,6 +798,7 @@ var _ = Describe("RateLimitPolicy controller", func() {
Expect(err).ToNot(HaveOccurred())
// Check RLP status is available
Eventually(testRLPIsAccepted(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())

// Check HTTPRoute A direct back reference is gone
Eventually(
Expand Down Expand Up @@ -841,6 +849,8 @@ var _ = Describe("RateLimitPolicy controller", func() {
// Check RLP status is available
rlpKey := client.ObjectKeyFromObject(rlp)
Eventually(testRLPIsAccepted(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpKey), time.Minute, 5*time.Second).Should(BeFalse())
Expect(testRLPEnforcedCondition(rlpKey, kuadrant.PolicyReasonUnknown, "RateLimitPolicy has encountered some issues: no free routes to enforce policy"))

// Check Gateway direct back reference
gwAKey := client.ObjectKey{Name: gwAName, Namespace: testNamespace}
Expand Down Expand Up @@ -869,6 +879,8 @@ var _ = Describe("RateLimitPolicy controller", func() {
Expect(err).ToNot(HaveOccurred())
// Check RLP status is available
Eventually(testRLPIsAccepted(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpKey), time.Minute, 5*time.Second).Should(BeFalse())
Expect(testRLPEnforcedCondition(rlpKey, kuadrant.PolicyReasonUnknown, "RateLimitPolicy has encountered some issues: no free routes to enforce policy"))

// Check Gw A direct back reference is gone
Eventually(
Expand Down Expand Up @@ -930,6 +942,7 @@ var _ = Describe("RateLimitPolicy controller", func() {

rlpAKey := client.ObjectKeyFromObject(rlpA)
Eventually(testRLPIsAccepted(rlpAKey), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpAKey), time.Minute, 5*time.Second).Should(BeTrue())

// create rlpB
rlpB := policyFactory(func(policy *kuadrantv1beta2.RateLimitPolicy) {
Expand All @@ -943,6 +956,7 @@ var _ = Describe("RateLimitPolicy controller", func() {
// Check RLP status is available
rlpBKey := client.ObjectKeyFromObject(rlpB)
Eventually(testRLPIsAccepted(rlpBKey), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpBKey), time.Minute, 5*time.Second).Should(BeTrue())

// Check HTTPRoute A direct back reference
routeAKey := client.ObjectKey{Name: routeAName, Namespace: testNamespace}
Expand Down Expand Up @@ -1019,6 +1033,7 @@ var _ = Describe("RateLimitPolicy controller", func() {

rlpKey := client.ObjectKeyFromObject(rlp)
Eventually(testRLPIsAccepted(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())

// Check HTTPRoute A direct back reference
routeKey := client.ObjectKey{Name: routeName, Namespace: testNamespace}
Expand Down Expand Up @@ -1081,6 +1096,7 @@ var _ = Describe("RateLimitPolicy controller", func() {

rlpAKey := client.ObjectKeyFromObject(rlpA)
Eventually(testRLPIsAccepted(rlpAKey), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpAKey), time.Minute, 5*time.Second).Should(BeTrue())

// Proceed with the update:
// new RLP B -> Route A (already taken)
Expand All @@ -1097,6 +1113,7 @@ var _ = Describe("RateLimitPolicy controller", func() {
// Check RLP status is not available
rlpBKey := client.ObjectKeyFromObject(rlpB)
Eventually(testRLPIsNotAccepted(rlpBKey), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpBKey), time.Minute, 5*time.Second).Should(BeFalse())

// Check HTTPRoute A direct back reference to RLP A
routeAKey := client.ObjectKey{Name: routeAName, Namespace: testNamespace}
Expand Down Expand Up @@ -1135,6 +1152,7 @@ var _ = Describe("RateLimitPolicy controller", func() {
time.Minute, 5*time.Second).Should(BeTrue())

Eventually(testRLPIsAccepted(rlpBKey), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpBKey), time.Minute, 5*time.Second).Should(BeTrue())

routeBKey := client.ObjectKey{Name: routeBName, Namespace: testNamespace}
// Check HTTPRoute B direct back reference to RLP A
Expand All @@ -1146,6 +1164,7 @@ var _ = Describe("RateLimitPolicy controller", func() {
time.Minute, 5*time.Second).Should(BeTrue())

Eventually(testRLPIsAccepted(rlpAKey), time.Minute, 5*time.Second).Should(BeTrue())
Eventually(testRLPIsEnforced(rlpAKey), time.Minute, 5*time.Second).Should(BeTrue())
})
})
})
Expand Down

0 comments on commit 5ca771b

Please sign in to comment.