Skip to content

Commit f331162

Browse files
committed
volsync: added test without SIDs and Peerclasses
Signed-off-by: rakeshgm <[email protected]>
1 parent ad2155a commit f331162

File tree

1 file changed

+49
-79
lines changed

1 file changed

+49
-79
lines changed

internal/controller/vrg_volsync_test.go

+49-79
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,25 @@ var _ = Describe("VolumeReplicationGroupVolSyncController", func() {
6262
return []ramendrv1alpha1.PeerClass{peerClass(testStorageClassName, sIDs)}
6363
}
6464

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+
6584
BeforeEach(func() {
6685
testCtx, cancel = context.WithCancel(context.TODO())
6786

@@ -86,7 +105,7 @@ var _ = Describe("VolumeReplicationGroupVolSyncController", func() {
86105
testMatchLabels := map[string]string{
87106
"ramentest": "backmeup",
88107
}
89-
108+
90109
var testVsrg *ramendrv1alpha1.VolumeReplicationGroup
91110

92111
Context("When VRG created on primary", func() {
@@ -212,29 +231,9 @@ var _ = Describe("VolumeReplicationGroupVolSyncController", func() {
212231
return len(allRSs.Items)
213232
}, testMaxWait, testInterval).Should(Equal(len(testVsrg.Status.ProtectedPVCs)))
214233

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+
}
238237
})
239238
})
240239
})
@@ -263,7 +262,7 @@ var _ = Describe("VolumeReplicationGroupVolSyncController", func() {
263262
ReplicationState: ramendrv1alpha1.Secondary,
264263
Async: &ramendrv1alpha1.VRGAsyncSpec{
265264
SchedulingInterval: "1h",
266-
PeerClasses: vrgAsyncPeerClasses(),
265+
PeerClasses: vrgAsyncPeerClasses(),
267266
},
268267
PVCSelector: metav1.LabelSelector{
269268
MatchLabels: testMatchLabels,
@@ -292,41 +291,22 @@ var _ = Describe("VolumeReplicationGroupVolSyncController", func() {
292291
Context("When RDSpec entries are added to vrg spec", func() {
293292
storageClassName := testStorageClassName
294293

295-
testCapacity0 := corev1.ResourceList{
296-
corev1.ResourceStorage: resource.MustParse("1Gi"),
297-
}
298-
testCapacity1 := corev1.ResourceList{
299-
corev1.ResourceStorage: resource.MustParse("20Gi"),
300-
}
301-
302294
rd0 := &volsyncv1alpha1.ReplicationDestination{}
303295
rd1 := &volsyncv1alpha1.ReplicationDestination{}
304296

305297
JustBeforeEach(func() {
306298
// Update the vrg spec with some RDSpec entries
307299
Expect(k8sClient.Get(testCtx, client.ObjectKeyFromObject(testVrg), testVrg)).To(Succeed())
300+
308301
testVrg.Spec.VolSync.RDSpec = []ramendrv1alpha1.VolSyncReplicationDestinationSpec{
309302
{
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),
319305
},
306+
320307
{
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),
330310
},
331311
}
332312

@@ -398,14 +378,15 @@ var _ = Describe("VolumeReplicationGroupVolSyncController", func() {
398378
})
399379
})
400380

401-
402381
Describe("Setup without SIDs and PeerClasses", func() {
403382
testMatchLabels := map[string]string{
404383
"ramentest": "backmeup",
405384
}
406-
385+
407386
var testVsrg *ramendrv1alpha1.VolumeReplicationGroup
408387

388+
PVCCount := 3
389+
409390
Context("When VRG created", func() {
410391
JustBeforeEach(func() {
411392
testVsrg = &ramendrv1alpha1.VolumeReplicationGroup{
@@ -459,7 +440,7 @@ var _ = Describe("VolumeReplicationGroupVolSyncController", func() {
459440
boundPvcs = []corev1.PersistentVolumeClaim{}
460441

461442
// Create some PVCs that are bound
462-
for i := 0; i < 3; i++ {
443+
for i := 0; i < PVCCount; i++ {
463444
newPvc := createPVCBoundToRunningPod(testCtx, testNamespace.GetName(), "sc1",
464445
testMatchLabels, pvcAnnotations)
465446
boundPvcs = append(boundPvcs, *newPvc)
@@ -505,41 +486,19 @@ var _ = Describe("VolumeReplicationGroupVolSyncController", func() {
505486
return len(allRSs.Items)
506487
}, testMaxWait, testInterval).Should(Equal(len(testVsrg.Status.ProtectedPVCs)))
507488

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+
}
531492
})
532493
})
533494
})
534495
})
535496
})
536-
537-
538497
})
539498

540499
//nolint:funlen
541500
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,
543502
) *corev1.PersistentVolumeClaim {
544503
capacity := corev1.ResourceList{
545504
corev1.ResourceStorage: resource.MustParse("1Gi"),
@@ -672,3 +631,14 @@ func createVSC(vscName string, vscLabels map[string]string) {
672631
Expect(err).NotTo(HaveOccurred(),
673632
"failed to create/get StorageClass %s", vsc.Name)
674633
}
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

Comments
 (0)