diff --git a/controllers/helper_test.go b/controllers/helper_test.go index 0c9095e48..822e04b10 100644 --- a/controllers/helper_test.go +++ b/controllers/helper_test.go @@ -344,6 +344,7 @@ func testWasmPluginIsAvailable(key client.ObjectKey) func() bool { wp := &istioclientgoextensionv1alpha1.WasmPlugin{} err := k8sClient.Get(context.Background(), key, wp) if err != nil { + logf.Log.V(1).Info("wasmplugin not read", "key", key, "error", err) return false } @@ -362,9 +363,11 @@ func testRLPIsAccepted(rlpKey client.ObjectKey) func() bool { existingRLP := &kuadrantv1beta2.RateLimitPolicy{} err := k8sClient.Get(context.Background(), rlpKey, existingRLP) if err != nil { + logf.Log.V(1).Info("ratelimitpolicy not read", "rlp", rlpKey, "error", err) return false } if !meta.IsStatusConditionTrue(existingRLP.Status.Conditions, string(gatewayapiv1alpha2.PolicyConditionAccepted)) { + logf.Log.V(1).Info("ratelimitpolicy not available", "rlp", rlpKey) return false } diff --git a/controllers/rate_limiting_wasmplugin_controller_test.go b/controllers/rate_limiting_wasmplugin_controller_test.go index f38a9aeb3..e010e1e97 100644 --- a/controllers/rate_limiting_wasmplugin_controller_test.go +++ b/controllers/rate_limiting_wasmplugin_controller_test.go @@ -85,7 +85,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() { // Check RLP status is available rlpKey := client.ObjectKeyFromObject(rlp) - Eventually(testRLPIsAvailable(rlpKey), time.Minute, 5*time.Second).Should(BeTrue()) + Eventually(testRLPIsAccepted(rlpKey), time.Minute, 5*time.Second).Should(BeTrue()) // Check wasm plugin wasmPluginKey := client.ObjectKey{Name: rlptools.WASMPluginName(gateway), Namespace: testNamespace} @@ -243,7 +243,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() { // Check RLP status is available rlpKey := client.ObjectKeyFromObject(rlp) - Eventually(testRLPIsAvailable(rlpKey), time.Minute, 5*time.Second).Should(BeTrue()) + Eventually(testRLPIsAccepted(rlpKey), time.Minute, 5*time.Second).Should(BeTrue()) // Check wasm plugin wasmPluginKey := client.ObjectKey{Name: rlptools.WASMPluginName(gateway), Namespace: testNamespace} @@ -384,7 +384,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() { // Check RLP status is available rlpKey := client.ObjectKey{Name: rlpName, Namespace: testNamespace} - Eventually(testRLPIsAvailable(rlpKey), time.Minute, 5*time.Second).Should(BeTrue()) + Eventually(testRLPIsAccepted(rlpKey), time.Minute, 5*time.Second).Should(BeTrue()) // Check wasm plugin wasmPluginKey := client.ObjectKey{Name: rlptools.WASMPluginName(gateway), Namespace: testNamespace} @@ -471,7 +471,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() { // Check RLP status is available rlpKey := client.ObjectKey{Name: rlpName, Namespace: testNamespace} - Eventually(testRLPIsAvailable(rlpKey), time.Minute, 5*time.Second).Should(BeTrue()) + Eventually(testRLPIsAccepted(rlpKey), time.Minute, 5*time.Second).Should(BeTrue()) // Check wasm plugin wasmPluginKey := client.ObjectKey{Name: rlptools.WASMPluginName(gateway), Namespace: testNamespace} @@ -537,7 +537,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() { // Check RLP status is available rlpKey := client.ObjectKeyFromObject(rlp) - Eventually(testRLPIsAvailable(rlpKey), time.Minute, 5*time.Second).Should(BeTrue()) + Eventually(testRLPIsAccepted(rlpKey), time.Minute, 5*time.Second).Should(BeTrue()) // Check wasm plugin wasmPluginKey := client.ObjectKey{Name: rlptools.WASMPluginName(gateway), Namespace: testNamespace} @@ -597,7 +597,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() { // Check RLP status is available rlpAKey := client.ObjectKey{Name: rlpAName, Namespace: testNamespace} - Eventually(testRLPIsAvailable(rlpAKey), time.Minute, 5*time.Second).Should(BeTrue()) + Eventually(testRLPIsAccepted(rlpAKey), time.Minute, 5*time.Second).Should(BeTrue()) // create httproute C httpRouteC := testBuildBasicHttpRoute(routeCName, gwName, testNamespace, []string{"*.c.example.com"}) @@ -659,7 +659,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() { // Check RLP status is available rlpBKey := client.ObjectKey{Name: rlpBName, Namespace: testNamespace} - Eventually(testRLPIsAvailable(rlpBKey), time.Minute, 5*time.Second).Should(BeTrue()) + Eventually(testRLPIsAccepted(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 @@ -779,7 +779,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() { Expect(err).ToNot(HaveOccurred()) // Check RLP status is available rlpKey := client.ObjectKey{Name: rlpName, Namespace: testNamespace} - Eventually(testRLPIsAvailable(rlpKey), time.Minute, 5*time.Second).Should(BeTrue()) + Eventually(testRLPIsAccepted(rlpKey), time.Minute, 5*time.Second).Should(BeTrue()) // create Route A -> Gw A httpRoute := testBuildBasicHttpRoute(routeName, gwName, testNamespace, []string{"*.example.com"}) @@ -982,7 +982,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() { Expect(err).ToNot(HaveOccurred()) // Check RLP status is available rlpKey := client.ObjectKey{Name: rlpName, Namespace: testNamespace} - Eventually(testRLPIsAvailable(rlpKey), time.Minute, 5*time.Second).Should(BeTrue()) + Eventually(testRLPIsAccepted(rlpKey), time.Minute, 5*time.Second).Should(BeTrue()) // Initial state set. // Check wasm plugin for gateway A has configuration from the route @@ -1261,7 +1261,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() { Expect(err).ToNot(HaveOccurred()) // Check RLP status is available rlpKey := client.ObjectKey{Name: rlpName, Namespace: testNamespace} - Eventually(testRLPIsAvailable(rlpKey), time.Minute, 5*time.Second).Should(BeTrue()) + Eventually(testRLPIsAccepted(rlpKey), time.Minute, 5*time.Second).Should(BeTrue()) // Initial state set. // Check wasm plugin has configuration from the route A @@ -1478,7 +1478,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() { Expect(err).ToNot(HaveOccurred()) // Check RLP status is available rlp1Key := client.ObjectKey{Name: rlp1Name, Namespace: testNamespace} - Eventually(testRLPIsAvailable(rlp1Key), time.Minute, 5*time.Second).Should(BeTrue()) + Eventually(testRLPIsAccepted(rlp1Key), time.Minute, 5*time.Second).Should(BeTrue()) // Initial state set. // Check wasm plugin for gateway A has configuration from the route 1 @@ -1580,7 +1580,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() { Expect(err).ToNot(HaveOccurred()) // Check RLP status is available rlp2Key := client.ObjectKey{Name: rlp2Name, Namespace: testNamespace} - Eventually(testRLPIsAvailable(rlp2Key), time.Minute, 5*time.Second).Should(BeTrue()) + Eventually(testRLPIsAccepted(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 @@ -1723,7 +1723,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() { Expect(err).ToNot(HaveOccurred()) // Check RLP status is available rlp1Key := client.ObjectKey{Name: rlp1Name, Namespace: testNamespace} - Eventually(testRLPIsAvailable(rlp1Key), time.Minute, 5*time.Second).Should(BeTrue()) + Eventually(testRLPIsAccepted(rlp1Key), time.Minute, 5*time.Second).Should(BeTrue()) // create RLP 2 -> Route A rlp2 := &kuadrantv1beta2.RateLimitPolicy{ @@ -1752,7 +1752,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() { Expect(err).ToNot(HaveOccurred()) // Check RLP status is available rlp2Key := client.ObjectKey{Name: rlp2Name, Namespace: testNamespace} - Eventually(testRLPIsAvailable(rlp2Key), time.Minute, 5*time.Second).Should(BeTrue()) + Eventually(testRLPIsAccepted(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 @@ -1953,22 +1953,3 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() { }) }) }) - -func testWasmPluginIsAvailable(key client.ObjectKey) func() bool { - return func() bool { - wp := &istioclientgoextensionv1alpha1.WasmPlugin{} - err := k8sClient.Get(context.Background(), key, wp) - if err != nil { - logf.Log.V(1).Info("wasmplugin not read", "key", key, "error", err) - return false - } - - // Unfortunately, WasmPlugin does not have status yet - // Leaving this here for future use - //if !meta.IsStatusConditionTrue(wp.Status.Conditions, "Available") { - // return false - //} - - return true - } -} diff --git a/controllers/ratelimitpolicy_controller_test.go b/controllers/ratelimitpolicy_controller_test.go index e978c66ce..4ddf5d691 100644 --- a/controllers/ratelimitpolicy_controller_test.go +++ b/controllers/ratelimitpolicy_controller_test.go @@ -5,18 +5,15 @@ package controllers import ( "context" "encoding/json" - "fmt" "strings" "time" limitadorv1alpha1 "github.com/kuadrant/limitador-operator/api/v1alpha1" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" - logf "sigs.k8s.io/controller-runtime/pkg/log" gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" gatewayapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" diff --git a/pkg/common/kuadrant_policy_test.go b/pkg/common/kuadrant_policy_test.go index fe07f31d1..91c679950 100644 --- a/pkg/common/kuadrant_policy_test.go +++ b/pkg/common/kuadrant_policy_test.go @@ -32,6 +32,10 @@ func (p *TestPolicy) GetRulesHostnames() []string { return nil } +func (p *TestPolicy) Kind() string { + return p.TypeMeta.Kind +} + func (p *TestPolicy) DeepCopyObject() runtime.Object { if c := p.DeepCopy(); c != nil { return c