diff --git a/controllers/glance_controller.go b/controllers/glance_controller.go index 5949c8f9..53e07969 100644 --- a/controllers/glance_controller.go +++ b/controllers/glance_controller.go @@ -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, diff --git a/test/functional/base_test.go b/test/functional/base_test.go index cc5bb404..fd18f3bc 100644 --- a/test/functional/base_test.go +++ b/test/functional/base_test.go @@ -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 diff --git a/test/functional/glance_controller_test.go b/test/functional/glance_controller_test.go index e5bb47dc..302707fe 100644 --- a/test/functional/glance_controller_test.go +++ b/test/functional/glance_controller_test.go @@ -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() { @@ -487,5 +507,4 @@ var _ = Describe("Glance controller", func() { } mariadbSuite.RunBasicSuite() - }) diff --git a/test/functional/glance_test_data.go b/test/functional/glance_test_data.go index ccbdbfc5..a4178013 100644 --- a/test/functional/glance_test_data.go +++ b/test/functional/glance_test_data.go @@ -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 @@ -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), + }, } } diff --git a/test/kuttl/tests/glance_single/01-assert.yaml b/test/kuttl/tests/glance_single/01-assert.yaml index 1be4a233..a0293b7c 100644 --- a/test/kuttl/tests/glance_single/01-assert.yaml +++ b/test/kuttl/tests/glance_single/01-assert.yaml @@ -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 @@ -145,7 +145,7 @@ spec: apiVersion: batch/v1 kind: CronJob metadata: - name: glance-dbpurge + name: glance-db-purge spec: jobTemplate: metadata: