Skip to content

Commit 916adfe

Browse files
committed
limitador_cluster_envoyfilter_controller e2e tests
1 parent 5b14d56 commit 916adfe

3 files changed

+145
-25
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
//go:build integration
2+
3+
package controllers
4+
5+
import (
6+
"context"
7+
"fmt"
8+
"time"
9+
10+
. "github.com/onsi/ginkgo/v2"
11+
. "github.com/onsi/gomega"
12+
istioclientnetworkingv1alpha3 "istio.io/client-go/pkg/apis/networking/v1alpha3"
13+
apierrors "k8s.io/apimachinery/pkg/api/errors"
14+
"k8s.io/apimachinery/pkg/api/meta"
15+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16+
"sigs.k8s.io/controller-runtime/pkg/client"
17+
logf "sigs.k8s.io/controller-runtime/pkg/log"
18+
gatewayapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
19+
gatewayapiv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
20+
21+
kuadrantv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2"
22+
"github.com/kuadrant/kuadrant-operator/pkg/common"
23+
limitadorv1alpha1 "github.com/kuadrant/limitador-operator/api/v1alpha1"
24+
)
25+
26+
var _ = Describe("Limitador Cluster EnvoyFilter controller", func() {
27+
var (
28+
testNamespace string
29+
gwName = "toystore-gw"
30+
rlpName = "toystore-rlp"
31+
efName = fmt.Sprintf("kuadrant-ratelimiting-cluster-%s", gwName)
32+
)
33+
34+
beforeEachCallback := func() {
35+
CreateNamespace(&testNamespace)
36+
gateway := testBuildBasicGateway(gwName, testNamespace)
37+
err := k8sClient.Create(context.Background(), gateway)
38+
Expect(err).ToNot(HaveOccurred())
39+
40+
Eventually(func() bool {
41+
existingGateway := &gatewayapiv1beta1.Gateway{}
42+
err := k8sClient.Get(context.Background(), client.ObjectKeyFromObject(gateway), existingGateway)
43+
if err != nil {
44+
logf.Log.V(1).Info("[WARN] Creating gateway failed", "error", err)
45+
return false
46+
}
47+
48+
if meta.IsStatusConditionFalse(existingGateway.Status.Conditions, common.GatewayProgrammedConditionType) {
49+
logf.Log.V(1).Info("[WARN] Gateway not ready")
50+
return false
51+
}
52+
53+
return true
54+
}, 15*time.Second, 5*time.Second).Should(BeTrue())
55+
56+
ApplyKuadrantCR(testNamespace)
57+
58+
// Check Limitador Status is Ready
59+
Eventually(func() bool {
60+
limitador := &limitadorv1alpha1.Limitador{}
61+
err := k8sClient.Get(context.Background(), client.ObjectKey{Name: common.LimitadorName, Namespace: testNamespace}, limitador)
62+
if err != nil {
63+
return false
64+
}
65+
if !meta.IsStatusConditionTrue(limitador.Status.Conditions, "Ready") {
66+
return false
67+
}
68+
return true
69+
}, time.Minute, 5*time.Second).Should(BeTrue())
70+
}
71+
72+
BeforeEach(beforeEachCallback)
73+
AfterEach(DeleteNamespaceCallback(&testNamespace))
74+
75+
Context("RLP targeting Gateway", func() {
76+
It("EnvoyFilter created when RLP exists and deleted with RLP is deleted", func() {
77+
// create ratelimitpolicy
78+
rlp := &kuadrantv1beta2.RateLimitPolicy{
79+
TypeMeta: metav1.TypeMeta{
80+
Kind: "RateLimitPolicy",
81+
APIVersion: kuadrantv1beta2.GroupVersion.String(),
82+
},
83+
ObjectMeta: metav1.ObjectMeta{
84+
Name: rlpName,
85+
Namespace: testNamespace,
86+
},
87+
Spec: kuadrantv1beta2.RateLimitPolicySpec{
88+
TargetRef: gatewayapiv1alpha2.PolicyTargetReference{
89+
Group: gatewayapiv1beta1.Group("gateway.networking.k8s.io"),
90+
Kind: "Gateway",
91+
Name: gatewayapiv1beta1.ObjectName(gwName),
92+
},
93+
Limits: map[string]kuadrantv1beta2.Limit{
94+
"l1": {
95+
Rates: []kuadrantv1beta2.Rate{
96+
{
97+
Limit: 1, Duration: 3, Unit: kuadrantv1beta2.TimeUnit("minute"),
98+
},
99+
},
100+
},
101+
},
102+
},
103+
}
104+
err := k8sClient.Create(context.Background(), rlp)
105+
Expect(err).ToNot(HaveOccurred())
106+
// Check RLP status is available
107+
rlpKey := client.ObjectKey{Name: rlpName, Namespace: testNamespace}
108+
Eventually(testRLPIsAvailable(rlpKey), time.Minute, 5*time.Second).Should(BeTrue())
109+
110+
// Check envoy filter
111+
Eventually(func() bool {
112+
existingEF := &istioclientnetworkingv1alpha3.EnvoyFilter{}
113+
efKey := client.ObjectKey{Name: efName, Namespace: testNamespace}
114+
err = k8sClient.Get(context.Background(), efKey, existingEF)
115+
if err != nil {
116+
return false
117+
}
118+
return true
119+
}, 15*time.Second, 5*time.Second).Should(BeTrue())
120+
121+
err = k8sClient.Delete(context.Background(), rlp)
122+
Expect(err).ToNot(HaveOccurred())
123+
124+
// Check envoy filter is gone
125+
Eventually(func() bool {
126+
existingEF := &istioclientnetworkingv1alpha3.EnvoyFilter{}
127+
efKey := client.ObjectKey{Name: efName, Namespace: testNamespace}
128+
err = k8sClient.Get(context.Background(), efKey, existingEF)
129+
return apierrors.IsNotFound(err)
130+
}, 15*time.Second, 5*time.Second).Should(BeTrue())
131+
})
132+
})
133+
})

controllers/ratelimitpolicy_controller_test.go

-25
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
. "github.com/onsi/ginkgo/v2"
1212
. "github.com/onsi/gomega"
1313
istioclientgoextensionv1alpha1 "istio.io/client-go/pkg/apis/extensions/v1alpha1"
14-
istioclientnetworkingv1alpha3 "istio.io/client-go/pkg/apis/networking/v1alpha3"
1514
corev1 "k8s.io/api/core/v1"
1615
apierrors "k8s.io/apimachinery/pkg/api/errors"
1716
"k8s.io/apimachinery/pkg/api/meta"
@@ -206,14 +205,6 @@ var _ = Describe("RateLimitPolicy controller", func() {
206205
Variables: []string{},
207206
}))
208207

209-
// Check envoy filter
210-
efName := fmt.Sprintf("kuadrant-ratelimiting-cluster-%s", gwName)
211-
efKey := client.ObjectKey{Name: efName, Namespace: testNamespace}
212-
existingEF := &istioclientnetworkingv1alpha3.EnvoyFilter{}
213-
err = k8sClient.Get(context.Background(), efKey, existingEF)
214-
// must exist
215-
Expect(err).ToNot(HaveOccurred())
216-
217208
// Check wasm plugin
218209
wpName := fmt.Sprintf("kuadrant-%s", gwName)
219210
wasmPluginKey := client.ObjectKey{Name: wpName, Namespace: testNamespace}
@@ -552,14 +543,6 @@ var _ = Describe("RateLimitPolicy controller", func() {
552543
Variables: []string{},
553544
}))
554545

555-
// Check envoy filter
556-
efName := fmt.Sprintf("kuadrant-ratelimiting-cluster-%s", gwName)
557-
efKey := client.ObjectKey{Name: efName, Namespace: testNamespace}
558-
existingEF := &istioclientnetworkingv1alpha3.EnvoyFilter{}
559-
err = k8sClient.Get(context.Background(), efKey, existingEF)
560-
// must exist
561-
Expect(err).ToNot(HaveOccurred())
562-
563546
// Check wasm plugin
564547
wpName := fmt.Sprintf("kuadrant-%s", gwName)
565548
wasmPluginKey := client.ObjectKey{Name: wpName, Namespace: testNamespace}
@@ -677,14 +660,6 @@ var _ = Describe("RateLimitPolicy controller", func() {
677660
Variables: []string{},
678661
}))
679662

680-
// Check envoy filter
681-
efName := fmt.Sprintf("kuadrant-ratelimiting-cluster-%s", gwName)
682-
efKey := client.ObjectKey{Name: efName, Namespace: testNamespace}
683-
existingEF := &istioclientnetworkingv1alpha3.EnvoyFilter{}
684-
err = k8sClient.Get(context.Background(), efKey, existingEF)
685-
// must exist
686-
Expect(err).ToNot(HaveOccurred())
687-
688663
// Check wasm plugin
689664
wpName := fmt.Sprintf("kuadrant-%s", gwName)
690665
wasmPluginKey := client.ObjectKey{Name: wpName, Namespace: testNamespace}

controllers/suite_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,18 @@ var _ = BeforeSuite(func() {
156156

157157
Expect(err).NotTo(HaveOccurred())
158158

159+
limitadorClusterEnvoyFilterBaseReconciler := reconcilers.NewBaseReconciler(
160+
mgr.GetClient(), mgr.GetScheme(), mgr.GetAPIReader(),
161+
log.Log.WithName("ratelimitpolicy").WithName("envoyfilter"),
162+
mgr.GetEventRecorderFor("LimitadorClusterEnvoyFilter"),
163+
)
164+
165+
err = (&LimitadorClusterEnvoyFilterReconciler{
166+
BaseReconciler: limitadorClusterEnvoyFilterBaseReconciler,
167+
}).SetupWithManager(mgr)
168+
169+
Expect(err).NotTo(HaveOccurred())
170+
159171
go func() {
160172
defer GinkgoRecover()
161173
err = mgr.Start(ctrl.SetupSignalHandler())

0 commit comments

Comments
 (0)