Skip to content

Commit

Permalink
Add cronJob envTests
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
fmount committed Sep 23, 2024
1 parent 052e250 commit a47b9c2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
9 changes: 9 additions & 0 deletions test/functional/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
26 changes: 23 additions & 3 deletions test/functional/manila_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
5 changes: 5 additions & 0 deletions test/functional/manila_test_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
},
}
}

0 comments on commit a47b9c2

Please sign in to comment.