Skip to content

Commit 27cab20

Browse files
committed
Add cronJob envTests
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]>
1 parent 94bf45f commit 27cab20

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

controllers/glance_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ func (r *GlanceReconciler) ensureDBPurgeJob(
10161016
) (ctrl.Result, error) {
10171017

10181018
cronSpec := glance.CronJobSpec{
1019-
Name: fmt.Sprintf("%s-dbpurge", glance.ServiceName),
1019+
Name: fmt.Sprintf("%s-db-purge", instance.Name),
10201020
PvcClaim: nil,
10211021
Command: glance.GlanceManage,
10221022
Schedule: instance.Spec.DBPurge.Schedule,

test/functional/base_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ func GetGlanceAPI(name types.NamespacedName) *glancev1.GlanceAPI {
4747
return instance
4848
}
4949

50+
func GetCronJob(name types.NamespacedName) *batchv1.CronJob {
51+
cron := &batchv1.CronJob{}
52+
Eventually(func(g Gomega) {
53+
g.Expect(k8sClient.Get(ctx, name, cron)).Should(Succeed())
54+
}, timeout, interval).Should(Succeed())
55+
return cron
56+
}
57+
5058
func GlanceConditionGetter(name types.NamespacedName) condition.Conditions {
5159
instance := GetGlance(name)
5260
return instance.Status.Conditions

test/functional/glance_controller_test.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,26 @@ var _ = Describe("Glance controller", func() {
297297
It("should not have a cache pvc (no imageCacheSize provided)", func() {
298298
AssertPVCDoesNotExist(glanceTest.GlanceCache)
299299
})
300+
It("configures DB Purge job", func() {
301+
Eventually(func(g Gomega) {
302+
glance := GetGlance(glanceTest.Instance)
303+
cron := GetCronJob(glanceTest.DBPurgeCronJob)
304+
g.Expect(cron.Spec.Schedule).To(Equal(glance.Spec.DBPurge.Schedule))
305+
}, timeout, interval).Should(Succeed())
306+
})
307+
It("update DB Purge job", func() {
308+
Eventually(func(g Gomega) {
309+
glance := GetGlance(glanceTest.Instance)
310+
glance.Spec.DBPurge.Schedule = "*/30 * * * *"
311+
g.Expect(k8sClient.Update(ctx, glance)).To(Succeed())
312+
}, timeout, interval).Should(Succeed())
313+
314+
Eventually(func(g Gomega) {
315+
glance := GetGlance(glanceTest.Instance)
316+
cron := GetCronJob(glanceTest.DBPurgeCronJob)
317+
g.Expect(cron.Spec.Schedule).To(Equal(glance.Spec.DBPurge.Schedule))
318+
}, timeout, interval).Should(Succeed())
319+
})
300320
})
301321
When("Glance CR is deleted", func() {
302322
BeforeEach(func() {
@@ -487,5 +507,4 @@ var _ = Describe("Glance controller", func() {
487507
}
488508

489509
mariadbSuite.RunBasicSuite()
490-
491510
})

test/functional/glance_test_data.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ type GlanceTestData struct {
8585
MemcachedInstance string
8686
GlanceMemcached types.NamespacedName
8787
KeystoneService types.NamespacedName
88+
DBPurgeCronJob types.NamespacedName
8889
}
8990

9091
// GetGlanceTestData is a function that initialize the GlanceTestData
@@ -219,5 +220,9 @@ func GetGlanceTestData(glanceName types.NamespacedName) GlanceTestData {
219220
Namespace: glanceName.Namespace,
220221
Name: glance.ServiceName,
221222
},
223+
DBPurgeCronJob: types.NamespacedName{
224+
Namespace: glanceName.Namespace,
225+
Name: fmt.Sprintf("%s-db-purge", glanceName.Name),
226+
},
222227
}
223228
}

test/kuttl/tests/glance_single/01-assert.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# - glance-internal service
88
# - glance-public service
99
# - glance internal and public endpoints
10-
# - glance-dbpurge cronjob
10+
# - glance-db-purge cronjob
1111

1212
apiVersion: glance.openstack.org/v1beta1
1313
kind: Glance
@@ -145,7 +145,7 @@ spec:
145145
apiVersion: batch/v1
146146
kind: CronJob
147147
metadata:
148-
name: glance-dbpurge
148+
name: glance-db-purge
149149
spec:
150150
jobTemplate:
151151
metadata:

0 commit comments

Comments
 (0)