Skip to content

Commit

Permalink
picking changes when rebasing
Browse files Browse the repository at this point in the history
  • Loading branch information
eguzki committed Feb 21, 2024
1 parent 42b7fb2 commit a733363
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 36 deletions.
3 changes: 3 additions & 0 deletions controllers/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
47 changes: 14 additions & 33 deletions controllers/rate_limiting_wasmplugin_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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"})
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"})
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
3 changes: 0 additions & 3 deletions controllers/ratelimitpolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 4 additions & 0 deletions pkg/common/kuadrant_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a733363

Please sign in to comment.