-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add kuadrant CR configuration to limitador CR configuration
- Loading branch information
Showing
1 changed file
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
//go:build integration | ||
Check failure on line 1 in controllers/kuadrant_controller_test.go GitHub Actions / Auto-format and Check (goimports)
|
||
|
||
package controllers | ||
|
||
import ( | ||
"context" | ||
kuadrantv1beta1 "github.com/kuadrant/kuadrant-operator/api/v1beta1" | ||
"github.com/kuadrant/kuadrant-operator/pkg/common" | ||
"github.com/kuadrant/limitador-operator/api/v1alpha1" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"k8s.io/utils/ptr" | ||
"reflect" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"time" | ||
) | ||
|
||
var _ = FDescribe("Kuadrant controller", func() { | ||
var ( | ||
testNamespace string | ||
kuadrant = "kuadrant-sample" | ||
) | ||
Context("Reconcile limitador resources", func() { | ||
BeforeEach(func() { | ||
CreateNamespace(&testNamespace) | ||
ApplyKuadrantCR(testNamespace) | ||
}) | ||
|
||
AfterEach(DeleteNamespaceCallback(&testNamespace)) | ||
It("Copy configuration from Kuadrant CR to Limitador CR", func() { | ||
kObj := &kuadrantv1beta1.Kuadrant{} | ||
lObj := &v1alpha1.Limitador{} | ||
|
||
Eventually(func() bool { | ||
err := k8sClient.Get(context.Background(), client.ObjectKey{Name: kuadrant, Namespace: testNamespace}, kObj) | ||
return err == nil | ||
}, time.Minute, 5*time.Second).Should(BeTrue()) | ||
|
||
Eventually(func() bool { | ||
err := k8sClient.Get(context.Background(), client.ObjectKey{Name: common.LimitadorName, Namespace: testNamespace}, lObj) | ||
return err == nil | ||
}, time.Minute, 5*time.Second).Should(BeTrue()) | ||
var tmp *int | ||
Expect(lObj.Spec.Replicas).Should(Equal(tmp)) | ||
|
||
kObj.Spec.Limitador = &kuadrantv1beta1.LimitadorSpec{Replicas: ptr.To(1)} | ||
err := k8sClient.Update(context.Background(), kObj) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
Eventually(func() bool { | ||
err := k8sClient.Get(context.Background(), client.ObjectKey{Name: common.LimitadorName, Namespace: testNamespace}, lObj) | ||
if err != nil { | ||
return false | ||
} | ||
if reflect.DeepEqual(lObj.Spec.Replicas, ptr.To(1)) { | ||
return false | ||
} | ||
return true | ||
}, time.Minute, 5*time.Second).Should(BeTrue()) | ||
}) | ||
|
||
It("Kuadrant CR configuration overrides Limitador CR configuration", func() { | ||
kObj := &kuadrantv1beta1.Kuadrant{} | ||
lObj := &v1alpha1.Limitador{} | ||
|
||
Eventually(func() bool { | ||
err := k8sClient.Get(context.Background(), client.ObjectKey{Name: common.LimitadorName, Namespace: testNamespace}, lObj) | ||
return err == nil | ||
}, time.Minute, 5*time.Second).Should(BeTrue()) | ||
lObj.Spec.Replicas = ptr.To(1) | ||
err := k8sClient.Update(context.Background(), lObj) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
Eventually(func() bool { | ||
err := k8sClient.Get(context.Background(), client.ObjectKey{Name: kuadrant, Namespace: testNamespace}, kObj) | ||
return err == nil | ||
}, time.Minute, 5*time.Second).Should(BeTrue()) | ||
|
||
kObj.Spec.Limitador = &kuadrantv1beta1.LimitadorSpec{Replicas: ptr.To(2)} | ||
err = k8sClient.Update(context.Background(), kObj) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
Eventually(func() bool { | ||
err := k8sClient.Get(context.Background(), client.ObjectKey{Name: common.LimitadorName, Namespace: testNamespace}, lObj) | ||
if err != nil { | ||
return false | ||
} | ||
if reflect.DeepEqual(lObj.Spec.Replicas, ptr.To(2)) { | ||
return false | ||
} | ||
return true | ||
}, time.Minute, 5*time.Second).Should(BeTrue()) | ||
}) | ||
}) | ||
}) |