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 Glance top level
CR is reflected in an update of the CronJob schedule. In addition, the
cronJob name now uses instance.Name instead of hardcoding the
ServiceName (if the "unique CR" name feature is used it will reflect the
name of the global CR).

Signed-off-by: Francesco Pantano <[email protected]>
  • Loading branch information
fmount committed Sep 27, 2024
1 parent b19cd99 commit 069adfb
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion controllers/glance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ func (r *GlanceReconciler) ensureDBPurgeJob(
) (ctrl.Result, error) {

cronSpec := glance.CronJobSpec{
Name: fmt.Sprintf("%s-dbpurge", glance.ServiceName),
Name: fmt.Sprintf("%s-db-purge", instance.Name),
PvcClaim: nil,
Command: glance.GlanceManage,
Schedule: instance.Spec.DBPurge.Schedule,
Expand Down
8 changes: 8 additions & 0 deletions test/functional/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ func GetGlanceAPI(name types.NamespacedName) *glancev1.GlanceAPI {
return instance
}

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
}

func GlanceConditionGetter(name types.NamespacedName) condition.Conditions {
instance := GetGlance(name)
return instance.Status.Conditions
Expand Down
21 changes: 20 additions & 1 deletion test/functional/glance_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,26 @@ var _ = Describe("Glance controller", func() {
It("should not have a cache pvc (no imageCacheSize provided)", func() {
AssertPVCDoesNotExist(glanceTest.GlanceCache)
})
It("configures DB Purge job", func() {
Eventually(func(g Gomega) {
glance := GetGlance(glanceTest.Instance)
cron := GetCronJob(glanceTest.DBPurgeCronJob)
g.Expect(cron.Spec.Schedule).To(Equal(glance.Spec.DBPurge.Schedule))
}, timeout, interval).Should(Succeed())
})
It("update DB Purge job", func() {
Eventually(func(g Gomega) {
glance := GetGlance(glanceTest.Instance)
glance.Spec.DBPurge.Schedule = "*/30 * * * *"
g.Expect(k8sClient.Update(ctx, glance)).To(Succeed())
}, timeout, interval).Should(Succeed())

Eventually(func(g Gomega) {
glance := GetGlance(glanceTest.Instance)
cron := GetCronJob(glanceTest.DBPurgeCronJob)
g.Expect(cron.Spec.Schedule).To(Equal(glance.Spec.DBPurge.Schedule))
}, timeout, interval).Should(Succeed())
})
})
When("Glance CR is deleted", func() {
BeforeEach(func() {
Expand Down Expand Up @@ -487,5 +507,4 @@ var _ = Describe("Glance controller", func() {
}

mariadbSuite.RunBasicSuite()

})
5 changes: 5 additions & 0 deletions test/functional/glance_test_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ type GlanceTestData struct {
MemcachedInstance string
GlanceMemcached types.NamespacedName
KeystoneService types.NamespacedName
DBPurgeCronJob types.NamespacedName
}

// GetGlanceTestData is a function that initialize the GlanceTestData
Expand Down Expand Up @@ -219,5 +220,9 @@ func GetGlanceTestData(glanceName types.NamespacedName) GlanceTestData {
Namespace: glanceName.Namespace,
Name: glance.ServiceName,
},
DBPurgeCronJob: types.NamespacedName{
Namespace: glanceName.Namespace,
Name: fmt.Sprintf("%s-db-purge", glanceName.Name),
},
}
}
4 changes: 2 additions & 2 deletions test/kuttl/tests/glance_single/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# - glance-internal service
# - glance-public service
# - glance internal and public endpoints
# - glance-dbpurge cronjob
# - glance-db-purge cronjob

apiVersion: glance.openstack.org/v1beta1
kind: Glance
Expand Down Expand Up @@ -145,7 +145,7 @@ spec:
apiVersion: batch/v1
kind: CronJob
metadata:
name: glance-dbpurge
name: glance-db-purge
spec:
jobTemplate:
metadata:
Expand Down

0 comments on commit 069adfb

Please sign in to comment.