Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration tests for configuration reconcile #404

Merged
merged 6 commits into from
May 15, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions controllers/kuadrant_controller_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//go:build integration

package controllers

import (
"reflect"
"time"

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"
"sigs.k8s.io/controller-runtime/pkg/client"
Boomatang marked this conversation as resolved.
Show resolved Hide resolved
)

var _ = Describe("Kuadrant controller", func() {
var (
testNamespace string
)
const (
afterEachTimeOut = NodeTimeout(3 * time.Minute)
kuadrant = "kuadrant-sample"
)
Context("Reconcile limitador resources", func() {
BeforeEach(func(ctx SpecContext) {
testNamespace = CreateNamespaceWithContext(ctx)
ApplyKuadrantCR(testNamespace)
})

AfterEach(func(ctx SpecContext) {
DeleteNamespaceCallbackWithContext(ctx, testNamespace)
}, afterEachTimeOut)
It("Copy configuration from Kuadrant CR to Limitador CR", func(ctx SpecContext) {
kObj := &kuadrantv1beta1.Kuadrant{}
lObj := &v1alpha1.Limitador{}

Eventually(func() bool {
err := k8sClient.Get(ctx, client.ObjectKey{Name: kuadrant, Namespace: testNamespace}, kObj)
return err == nil
}).WithContext(ctx).Should(BeTrue())

Eventually(func() bool {
err := k8sClient.Get(ctx, client.ObjectKey{Name: common.LimitadorName, Namespace: testNamespace}, lObj)
return err == nil
}).WithContext(ctx).Should(BeTrue())
var tmp *int
Expect(lObj.Spec.Replicas).Should(Equal(tmp))

kObj.Spec.Limitador = &kuadrantv1beta1.LimitadorSpec{Replicas: ptr.To(1)}
err := k8sClient.Update(ctx, kObj)
Expect(err).ToNot(HaveOccurred())

Eventually(func() bool {
err := k8sClient.Get(ctx, 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
}).WithContext(ctx).Should(BeTrue())
})

It("Kuadrant CR configuration overrides Limitador CR configuration", func(ctx SpecContext) {
kObj := &kuadrantv1beta1.Kuadrant{}
lObj := &v1alpha1.Limitador{}

Eventually(func() bool {
err := k8sClient.Get(ctx, client.ObjectKey{Name: common.LimitadorName, Namespace: testNamespace}, lObj)
return err == nil
}).WithContext(ctx).Should(BeTrue())
lObj.Spec.Replicas = ptr.To(1)
err := k8sClient.Update(ctx, lObj)
Expect(err).ToNot(HaveOccurred())

Eventually(func() bool {
err := k8sClient.Get(ctx, client.ObjectKey{Name: kuadrant, Namespace: testNamespace}, kObj)
return err == nil
}).WithContext(ctx).Should(BeTrue())

kObj.Spec.Limitador = &kuadrantv1beta1.LimitadorSpec{Replicas: ptr.To(2)}
err = k8sClient.Update(ctx, kObj)
Expect(err).ToNot(HaveOccurred())

Eventually(func() bool {
err := k8sClient.Get(ctx, 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
}).WithContext(ctx).Should(BeTrue())
})
})
})
Loading