@@ -60,6 +60,51 @@ var _ = Describe("getSnapshotName", func() {
6060 })
6161})
6262
63+ // newProvisionedSnapshots builds a VolumeSnapshotList for a PG_DATA/PG_WAL pair
64+ // of snapshots belonging to the given backup, with the given readiness.
65+ func newProvisionedSnapshots (namespace , backupName string , readyToUse bool ) volumesnapshotv1.VolumeSnapshotList {
66+ return volumesnapshotv1.VolumeSnapshotList {
67+ Items : []volumesnapshotv1.VolumeSnapshot {
68+ {
69+ ObjectMeta : metav1.ObjectMeta {
70+ Namespace : namespace ,
71+ Name : backupName ,
72+ Labels : map [string ]string {
73+ utils .BackupNameLabelName : backupName ,
74+ },
75+ Annotations : map [string ]string {
76+ "avoid" : "nil" ,
77+ },
78+ },
79+ Status : & volumesnapshotv1.VolumeSnapshotStatus {
80+ ReadyToUse : ptr .To (readyToUse ),
81+ Error : nil ,
82+ BoundVolumeSnapshotContentName : ptr .To (fmt .Sprintf ("%s-content" , backupName )),
83+ CreationTime : ptr .To (metav1 .Now ()),
84+ },
85+ },
86+ {
87+ ObjectMeta : metav1.ObjectMeta {
88+ Namespace : namespace ,
89+ Name : backupName + "-wal" ,
90+ Labels : map [string ]string {
91+ utils .BackupNameLabelName : backupName ,
92+ },
93+ Annotations : map [string ]string {
94+ "avoid" : "nil" ,
95+ },
96+ },
97+ Status : & volumesnapshotv1.VolumeSnapshotStatus {
98+ ReadyToUse : ptr .To (readyToUse ),
99+ Error : nil ,
100+ BoundVolumeSnapshotContentName : ptr .To (fmt .Sprintf ("%s-wal-content" , backupName )),
101+ CreationTime : ptr .To (metav1 .Now ()),
102+ },
103+ },
104+ },
105+ }
106+ }
107+
63108var _ = Describe ("Volumesnapshot reconciler" , func () {
64109 const (
65110 namespace = "test-namespace"
@@ -216,46 +261,7 @@ var _ = Describe("Volumesnapshot reconciler", func() {
216261 })
217262
218263 It ("should unfence the target pod when the snapshots have been provisioned" , func (ctx SpecContext ) {
219- snapshots := volumesnapshotv1.VolumeSnapshotList {
220- Items : []volumesnapshotv1.VolumeSnapshot {
221- {
222- ObjectMeta : metav1.ObjectMeta {
223- Namespace : namespace ,
224- Name : backup .Name ,
225- Labels : map [string ]string {
226- utils .BackupNameLabelName : backup .Name ,
227- },
228- Annotations : map [string ]string {
229- "avoid" : "nil" ,
230- },
231- },
232- Status : & volumesnapshotv1.VolumeSnapshotStatus {
233- ReadyToUse : ptr .To (false ),
234- Error : nil ,
235- BoundVolumeSnapshotContentName : ptr .To (fmt .Sprintf ("%s-content" , backup .Name )),
236- CreationTime : ptr .To (metav1 .Now ()),
237- },
238- },
239- {
240- ObjectMeta : metav1.ObjectMeta {
241- Namespace : namespace ,
242- Name : backup .Name + "-wal" ,
243- Labels : map [string ]string {
244- utils .BackupNameLabelName : backup .Name ,
245- },
246- Annotations : map [string ]string {
247- "avoid" : "nil" ,
248- },
249- },
250- Status : & volumesnapshotv1.VolumeSnapshotStatus {
251- ReadyToUse : ptr .To (false ),
252- Error : nil ,
253- BoundVolumeSnapshotContentName : ptr .To (fmt .Sprintf ("%s-wal-content" , backup .Name )),
254- CreationTime : ptr .To (metav1 .Now ()),
255- },
256- },
257- },
258- }
264+ snapshots := newProvisionedSnapshots (namespace , backup .Name , false )
259265
260266 cluster .Annotations [utils .FencedInstanceAnnotation ] = fmt .Sprintf (`["%s"]` , targetPod .Name )
261267
@@ -292,46 +298,7 @@ var _ = Describe("Volumesnapshot reconciler", func() {
292298 })
293299
294300 It ("should mark the backup as completed when the snapshots are ready" , func (ctx SpecContext ) {
295- snapshots := volumesnapshotv1.VolumeSnapshotList {
296- Items : []volumesnapshotv1.VolumeSnapshot {
297- {
298- ObjectMeta : metav1.ObjectMeta {
299- Namespace : namespace ,
300- Name : backup .Name ,
301- Labels : map [string ]string {
302- utils .BackupNameLabelName : backup .Name ,
303- },
304- Annotations : map [string ]string {
305- "avoid" : "nil" ,
306- },
307- },
308- Status : & volumesnapshotv1.VolumeSnapshotStatus {
309- BoundVolumeSnapshotContentName : ptr .To (fmt .Sprintf ("%s-content" , backup .Name )),
310- ReadyToUse : ptr .To (true ),
311- Error : nil ,
312- CreationTime : ptr .To (metav1 .Now ()),
313- },
314- },
315- {
316- ObjectMeta : metav1.ObjectMeta {
317- Namespace : namespace ,
318- Name : backup .Name + "-wal" ,
319- Labels : map [string ]string {
320- utils .BackupNameLabelName : backup .Name ,
321- },
322- Annotations : map [string ]string {
323- "avoid" : "nil" ,
324- },
325- },
326- Status : & volumesnapshotv1.VolumeSnapshotStatus {
327- BoundVolumeSnapshotContentName : ptr .To (fmt .Sprintf ("%s-wal-content" , backup .Name )),
328- ReadyToUse : ptr .To (true ),
329- Error : nil ,
330- CreationTime : ptr .To (metav1 .Now ()),
331- },
332- },
333- },
334- }
301+ snapshots := newProvisionedSnapshots (namespace , backup .Name , true )
335302
336303 cluster .Annotations [utils .FencedInstanceAnnotation ] = fmt .Sprintf (`["%s"]` , targetPod .Name )
337304
@@ -361,6 +328,39 @@ var _ = Describe("Volumesnapshot reconciler", func() {
361328 Expect (data .Len ()).To (Equal (0 ))
362329 })
363330
331+ It ("should honor the Backup's spec.online over the cluster default when finalizing" , func (ctx SpecContext ) {
332+ // the cluster has no explicit online setting, which defaults to true (hot backup)
333+ cluster .Spec .Backup .VolumeSnapshot .Online = nil
334+ // but this specific Backup requests a cold (offline) backup
335+ backup .Spec .Online = ptr .To (false )
336+
337+ snapshots := newProvisionedSnapshots (namespace , backup .Name , false )
338+
339+ cluster .Annotations [utils .FencedInstanceAnnotation ] = fmt .Sprintf (`["%s"]` , targetPod .Name )
340+
341+ mockClient := fake .NewClientBuilder ().
342+ WithScheme (scheme .BuildWithAllKnownScheme ()).
343+ WithObjects (cluster , targetPod , backup ).
344+ WithStatusSubresource (backup ).
345+ WithLists (& snapshots ).
346+ Build ()
347+ fakeRecorder := record .NewFakeRecorder (3 )
348+
349+ executor := NewReconcilerBuilder (mockClient , fakeRecorder ).
350+ Build ()
351+
352+ result , err := executor .Reconcile (ctx , cluster , backup , targetPod , pvcs )
353+ Expect (err ).ToNot (HaveOccurred ())
354+ Expect (result ).ToNot (BeNil ())
355+
356+ var latestBackup apiv1.Backup
357+ err = mockClient .Get (ctx , types.NamespacedName {Name : backupName , Namespace : namespace }, & latestBackup )
358+ Expect (err ).ToNot (HaveOccurred ())
359+
360+ Expect (latestBackup .Status .Phase ).To (BeEquivalentTo (apiv1 .BackupPhaseFinalizing ))
361+ Expect (latestBackup .Status .GetOnline ()).To (BeFalse ())
362+ })
363+
364364 It ("should properly enrich the backup with labels" , func (ctx SpecContext ) {
365365 mockClient := fake .NewClientBuilder ().
366366 WithScheme (scheme .BuildWithAllKnownScheme ()).
0 commit comments