@@ -62,6 +62,25 @@ var _ = Describe("VolumeReplicationGroupVolSyncController", func() {
62
62
return []ramendrv1alpha1.PeerClass {peerClass (testStorageClassName , sIDs )}
63
63
}
64
64
65
+ testCapacity := func (capacity string ) corev1.ResourceList {
66
+ return corev1.ResourceList {
67
+ corev1 .ResourceStorage : resource .MustParse (capacity ),
68
+ }
69
+ }
70
+
71
+ protectedPVC := func (storageClassName , testPVCName string , testCapacity corev1.ResourceList ,
72
+ testAccessModes []corev1.PersistentVolumeAccessMode ,
73
+ ) ramendrv1alpha1.ProtectedPVC {
74
+ return ramendrv1alpha1.ProtectedPVC {
75
+ Name : testPVCName ,
76
+ Namespace : testNamespace .GetName (),
77
+ ProtectedByVolSync : true ,
78
+ StorageClassName : & storageClassName ,
79
+ AccessModes : testAccessModes ,
80
+ Resources : corev1.VolumeResourceRequirements {Requests : testCapacity },
81
+ }
82
+ }
83
+
65
84
BeforeEach (func () {
66
85
testCtx , cancel = context .WithCancel (context .TODO ())
67
86
@@ -86,7 +105,7 @@ var _ = Describe("VolumeReplicationGroupVolSyncController", func() {
86
105
testMatchLabels := map [string ]string {
87
106
"ramentest" : "backmeup" ,
88
107
}
89
-
108
+
90
109
var testVsrg * ramendrv1alpha1.VolumeReplicationGroup
91
110
92
111
Context ("When VRG created on primary" , func () {
@@ -212,29 +231,9 @@ var _ = Describe("VolumeReplicationGroupVolSyncController", func() {
212
231
return len (allRSs .Items )
213
232
}, testMaxWait , testInterval ).Should (Equal (len (testVsrg .Status .ProtectedPVCs )))
214
233
215
- rs0 := & volsyncv1alpha1.ReplicationSource {}
216
- Expect (k8sClient .Get (testCtx , types.NamespacedName {
217
- Name : boundPvcs [0 ].GetName (), Namespace : testNamespace .GetName (),
218
- }, rs0 )).To (Succeed ())
219
- Expect (rs0 .Spec .SourcePVC ).To (Equal (boundPvcs [0 ].GetName ()))
220
- Expect (rs0 .Spec .Trigger ).NotTo (BeNil ())
221
- Expect (* rs0 .Spec .Trigger .Schedule ).To (Equal ("0 */1 * * *" )) // scheduling interval was set to 1h
222
-
223
- rs1 := & volsyncv1alpha1.ReplicationSource {}
224
- Expect (k8sClient .Get (testCtx , types.NamespacedName {
225
- Name : boundPvcs [1 ].GetName (), Namespace : testNamespace .GetName (),
226
- }, rs1 )).To (Succeed ())
227
- Expect (rs1 .Spec .SourcePVC ).To (Equal (boundPvcs [1 ].GetName ()))
228
- Expect (rs1 .Spec .Trigger ).NotTo (BeNil ())
229
- Expect (* rs1 .Spec .Trigger .Schedule ).To (Equal ("0 */1 * * *" )) // scheduling interval was set to 1h
230
-
231
- rs2 := & volsyncv1alpha1.ReplicationSource {}
232
- Expect (k8sClient .Get (testCtx , types.NamespacedName {
233
- Name : boundPvcs [2 ].GetName (), Namespace : testNamespace .GetName (),
234
- }, rs2 )).To (Succeed ())
235
- Expect (rs2 .Spec .SourcePVC ).To (Equal (boundPvcs [2 ].GetName ()))
236
- Expect (rs2 .Spec .Trigger ).NotTo (BeNil ())
237
- Expect (* rs2 .Spec .Trigger .Schedule ).To (Equal ("0 */1 * * *" )) // scheduling interval was set to 1h
234
+ for _ , boundPVC := range boundPvcs {
235
+ verifyReplicationSourceCreated (testCtx , & volsyncv1alpha1.ReplicationSource {}, boundPVC , testNamespace )
236
+ }
238
237
})
239
238
})
240
239
})
@@ -263,7 +262,7 @@ var _ = Describe("VolumeReplicationGroupVolSyncController", func() {
263
262
ReplicationState : ramendrv1alpha1 .Secondary ,
264
263
Async : & ramendrv1alpha1.VRGAsyncSpec {
265
264
SchedulingInterval : "1h" ,
266
- PeerClasses : vrgAsyncPeerClasses (),
265
+ PeerClasses : vrgAsyncPeerClasses (),
267
266
},
268
267
PVCSelector : metav1.LabelSelector {
269
268
MatchLabels : testMatchLabels ,
@@ -292,41 +291,22 @@ var _ = Describe("VolumeReplicationGroupVolSyncController", func() {
292
291
Context ("When RDSpec entries are added to vrg spec" , func () {
293
292
storageClassName := testStorageClassName
294
293
295
- testCapacity0 := corev1.ResourceList {
296
- corev1 .ResourceStorage : resource .MustParse ("1Gi" ),
297
- }
298
- testCapacity1 := corev1.ResourceList {
299
- corev1 .ResourceStorage : resource .MustParse ("20Gi" ),
300
- }
301
-
302
294
rd0 := & volsyncv1alpha1.ReplicationDestination {}
303
295
rd1 := & volsyncv1alpha1.ReplicationDestination {}
304
296
305
297
JustBeforeEach (func () {
306
298
// Update the vrg spec with some RDSpec entries
307
299
Expect (k8sClient .Get (testCtx , client .ObjectKeyFromObject (testVrg ), testVrg )).To (Succeed ())
300
+
308
301
testVrg .Spec .VolSync .RDSpec = []ramendrv1alpha1.VolSyncReplicationDestinationSpec {
309
302
{
310
- ProtectedPVC : ramendrv1alpha1.ProtectedPVC {
311
- Name : "testingpvc-a" ,
312
- Namespace : testNamespace .GetName (),
313
- ProtectedByVolSync : true ,
314
- StorageClassName : & storageClassName ,
315
- AccessModes : testAccessModes ,
316
-
317
- Resources : corev1.VolumeResourceRequirements {Requests : testCapacity0 },
318
- },
303
+ ProtectedPVC : protectedPVC (storageClassName ,
304
+ "testingpvc-a" , testCapacity ("1Gi" ), testAccessModes ),
319
305
},
306
+
320
307
{
321
- ProtectedPVC : ramendrv1alpha1.ProtectedPVC {
322
- Name : "testingpvc-b" ,
323
- Namespace : testNamespace .GetName (),
324
- ProtectedByVolSync : true ,
325
- StorageClassName : & storageClassName ,
326
- AccessModes : testAccessModes ,
327
-
328
- Resources : corev1.VolumeResourceRequirements {Requests : testCapacity1 },
329
- },
308
+ ProtectedPVC : protectedPVC (storageClassName ,
309
+ "testingpvc-b" , testCapacity ("20Gi" ), testAccessModes ),
330
310
},
331
311
}
332
312
@@ -398,14 +378,15 @@ var _ = Describe("VolumeReplicationGroupVolSyncController", func() {
398
378
})
399
379
})
400
380
401
-
402
381
Describe ("Setup without SIDs and PeerClasses" , func () {
403
382
testMatchLabels := map [string ]string {
404
383
"ramentest" : "backmeup" ,
405
384
}
406
-
385
+
407
386
var testVsrg * ramendrv1alpha1.VolumeReplicationGroup
408
387
388
+ PVCCount := 3
389
+
409
390
Context ("When VRG created" , func () {
410
391
JustBeforeEach (func () {
411
392
testVsrg = & ramendrv1alpha1.VolumeReplicationGroup {
@@ -459,7 +440,7 @@ var _ = Describe("VolumeReplicationGroupVolSyncController", func() {
459
440
boundPvcs = []corev1.PersistentVolumeClaim {}
460
441
461
442
// Create some PVCs that are bound
462
- for i := 0 ; i < 3 ; i ++ {
443
+ for i := 0 ; i < PVCCount ; i ++ {
463
444
newPvc := createPVCBoundToRunningPod (testCtx , testNamespace .GetName (), "sc1" ,
464
445
testMatchLabels , pvcAnnotations )
465
446
boundPvcs = append (boundPvcs , * newPvc )
@@ -505,41 +486,19 @@ var _ = Describe("VolumeReplicationGroupVolSyncController", func() {
505
486
return len (allRSs .Items )
506
487
}, testMaxWait , testInterval ).Should (Equal (len (testVsrg .Status .ProtectedPVCs )))
507
488
508
- rs0 := & volsyncv1alpha1.ReplicationSource {}
509
- Expect (k8sClient .Get (testCtx , types.NamespacedName {
510
- Name : boundPvcs [0 ].GetName (), Namespace : testNamespace .GetName (),
511
- }, rs0 )).To (Succeed ())
512
- Expect (rs0 .Spec .SourcePVC ).To (Equal (boundPvcs [0 ].GetName ()))
513
- Expect (rs0 .Spec .Trigger ).NotTo (BeNil ())
514
- Expect (* rs0 .Spec .Trigger .Schedule ).To (Equal ("0 */1 * * *" )) // scheduling interval was set to 1h
515
-
516
- rs1 := & volsyncv1alpha1.ReplicationSource {}
517
- Expect (k8sClient .Get (testCtx , types.NamespacedName {
518
- Name : boundPvcs [1 ].GetName (), Namespace : testNamespace .GetName (),
519
- }, rs1 )).To (Succeed ())
520
- Expect (rs1 .Spec .SourcePVC ).To (Equal (boundPvcs [1 ].GetName ()))
521
- Expect (rs1 .Spec .Trigger ).NotTo (BeNil ())
522
- Expect (* rs1 .Spec .Trigger .Schedule ).To (Equal ("0 */1 * * *" )) // scheduling interval was set to 1h
523
-
524
- rs2 := & volsyncv1alpha1.ReplicationSource {}
525
- Expect (k8sClient .Get (testCtx , types.NamespacedName {
526
- Name : boundPvcs [2 ].GetName (), Namespace : testNamespace .GetName (),
527
- }, rs2 )).To (Succeed ())
528
- Expect (rs2 .Spec .SourcePVC ).To (Equal (boundPvcs [2 ].GetName ()))
529
- Expect (rs2 .Spec .Trigger ).NotTo (BeNil ())
530
- Expect (* rs2 .Spec .Trigger .Schedule ).To (Equal ("0 */1 * * *" )) // scheduling interval was set to 1h
489
+ for _ , boundPVC := range boundPvcs {
490
+ verifyReplicationSourceCreated (testCtx , & volsyncv1alpha1.ReplicationSource {}, boundPVC , testNamespace )
491
+ }
531
492
})
532
493
})
533
494
})
534
495
})
535
496
})
536
-
537
-
538
497
})
539
498
540
499
//nolint:funlen
541
500
func createPVCBoundToRunningPod (ctx context.Context , namespace , scName string ,
542
- labels map [string ]string , annotations map [string ]string ,
501
+ labels map [string ]string , annotations map [string ]string ,
543
502
) * corev1.PersistentVolumeClaim {
544
503
capacity := corev1.ResourceList {
545
504
corev1 .ResourceStorage : resource .MustParse ("1Gi" ),
@@ -672,3 +631,14 @@ func createVSC(vscName string, vscLabels map[string]string) {
672
631
Expect (err ).NotTo (HaveOccurred (),
673
632
"failed to create/get StorageClass %s" , vsc .Name )
674
633
}
634
+
635
+ func verifyReplicationSourceCreated (testCtx context.Context , rs * volsyncv1alpha1.ReplicationSource ,
636
+ boundPVC corev1.PersistentVolumeClaim , ns * corev1.Namespace ,
637
+ ) {
638
+ Expect (k8sClient .Get (testCtx , types.NamespacedName {
639
+ Name : boundPVC .GetName (), Namespace : ns .GetName (),
640
+ }, rs )).To (Succeed ())
641
+ Expect (rs .Spec .SourcePVC ).To (Equal (boundPVC .GetName ()))
642
+ Expect (rs .Spec .Trigger ).NotTo (BeNil ())
643
+ Expect (* rs .Spec .Trigger .Schedule ).To (Equal ("0 */1 * * *" )) // scheduling interval was set to 1h
644
+ }
0 commit comments