From a47b9c218563d07bd0b49d565949a4a79e61782c Mon Sep 17 00:00:00 2001 From: Francesco Pantano Date: Mon, 23 Sep 2024 09:09:29 +0200 Subject: [PATCH] Add cronJob envTests This patch improves the existing envTest bucket to include cronJob verification and update. It shows how an update in the Manila top level CR is reflected in an update of the CronJob schedule. Signed-off-by: Francesco Pantano --- test/functional/base_test.go | 9 ++++++++ test/functional/manila_controller_test.go | 26 ++++++++++++++++++++--- test/functional/manila_test_data.go | 5 +++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/test/functional/base_test.go b/test/functional/base_test.go index 7f76e2a2..ad9852e6 100644 --- a/test/functional/base_test.go +++ b/test/functional/base_test.go @@ -18,6 +18,7 @@ import ( . "github.com/onsi/gomega" //revive:disable:dot-imports "golang.org/x/exp/maps" + batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" k8s_errors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -325,3 +326,11 @@ func ManilaShareNotExists(name types.NamespacedName) { g.Expect(k8s_errors.IsNotFound(err)).To(BeTrue()) }, timeout, interval).Should(Succeed()) } + +func GetCronJob(name types.NamespacedName) *batchv1.CronJob { + cron := &batchv1.CronJob{} + Eventually(func(g Gomega) { + g.Expect(k8sClient.Get(ctx, name, cron)).Should(Succeed()) + }, timeout, interval).Should(Succeed()) + return cron +} diff --git a/test/functional/manila_controller_test.go b/test/functional/manila_controller_test.go index 836aa246..19cd49f8 100644 --- a/test/functional/manila_controller_test.go +++ b/test/functional/manila_controller_test.go @@ -55,10 +55,10 @@ var _ = Describe("Manila controller", func() { }) It("initializes the status fields", func() { Eventually(func(g Gomega) { - glance := GetManila(manilaName) - g.Expect(glance.Status.Conditions).To(HaveLen(14)) + manila := GetManila(manilaName) + g.Expect(manila.Status.Conditions).To(HaveLen(14)) - g.Expect(glance.Status.DatabaseHostname).To(Equal("")) + g.Expect(manila.Status.DatabaseHostname).To(Equal("")) }, timeout*2, interval).Should(Succeed()) }) It("is not Ready", func() { @@ -297,6 +297,26 @@ var _ = Describe("Manila controller", func() { th.AssertServiceExists(manilaTest.ManilaServicePublic) th.AssertServiceExists(manilaTest.ManilaServiceInternal) }) + It("configures DB Purge job", func() { + Eventually(func(g Gomega) { + manila := GetManila(manilaTest.Instance) + cron := GetCronJob(manilaTest.DBPurgeCronJob) + g.Expect(cron.Spec.Schedule).To(Equal(manila.Spec.DBPurge.Schedule)) + }, timeout, interval).Should(Succeed()) + }) + It("update DB Purge job", func() { + Eventually(func(g Gomega) { + manila := GetManila(manilaTest.Instance) + manila.Spec.DBPurge.Schedule = "*/30 * * * *" + g.Expect(k8sClient.Update(ctx, manila)).To(Succeed()) + }, timeout, interval).Should(Succeed()) + + Eventually(func(g Gomega) { + manila := GetManila(manilaTest.Instance) + cron := GetCronJob(manilaTest.DBPurgeCronJob) + g.Expect(cron.Spec.Schedule).To(Equal(manila.Spec.DBPurge.Schedule)) + }, timeout, interval).Should(Succeed()) + }) }) When("Manila CR instance is deleted", func() { BeforeEach(func() { diff --git a/test/functional/manila_test_data.go b/test/functional/manila_test_data.go index 89ab1ec5..4fa402d1 100644 --- a/test/functional/manila_test_data.go +++ b/test/functional/manila_test_data.go @@ -69,6 +69,7 @@ type ManilaTestData struct { CABundleSecret types.NamespacedName InternalCertSecret types.NamespacedName PublicCertSecret types.NamespacedName + DBPurgeCronJob types.NamespacedName } // GetManilaTestData is a function that initialize the ManilaTestData @@ -191,5 +192,9 @@ func GetManilaTestData(manilaName types.NamespacedName) ManilaTestData { Namespace: manilaName.Namespace, Name: PublicCertSecretName, }, + DBPurgeCronJob: types.NamespacedName{ + Namespace: manilaName.Namespace, + Name: fmt.Sprintf("%s-db-purge", manilaName.Name), + }, } }