@@ -257,29 +257,72 @@ var _ = Describe("RestoreManager Test", func() {
257257
258258 It ("test with RestorePVCFromSnapshot function" , func () {
259259 reqCtx := getReqCtx ()
260- startingIndex := 0
260+ startingIndex := 3
261+ templateName := "az-a"
262+ cmpName := "mysql"
261263 useVolumeSnapshot := true
262264 restoreMGR , backupSet := initResources (reqCtx , startingIndex , useVolumeSnapshot , func (f * testdp.MockRestoreFactory ) {
263265 f .SetVolumeClaimsTemplate (testdp .MysqlTemplateName , testdp .DataVolumeName ,
264- testdp .DataVolumeMountPath , "" , int32 (replicas ), int32 (startingIndex ), nil )
266+ testdp .DataVolumeMountPath , "" , int32 (replicas ), int32 (startingIndex ), map [string ]string {
267+ constant .AppInstanceLabelKey : instanceName ,
268+ constant .KBAppComponentLabelKey : cmpName ,
269+ constant .KBAppInstanceTemplateLabelKey : templateName ,
270+ }).
271+ SetPrepareDataRequiredPolicy (dpv1alpha1 .OneToOneRestorePolicy , "" )
265272 })
273+ backupSet .Backup .Status .Target .PodSelector .Strategy = dpv1alpha1 .PodSelectionStrategyAll
274+ backupSet .Backup .Status .Target .PodSelector .MatchLabels [constant .AppInstanceLabelKey ] = "source"
275+ backupSet .Backup .Status .Target .PodSelector .MatchLabels [constant .KBAppComponentLabelKey ] = cmpName
276+ backupSet .Backup .Status .Target .SelectedTargetPods = []string {"source-mysql-az-a-4" , "source-mysql-az-a-3" }
277+ backupSet .Backup .Status .Actions = []dpv1alpha1.ActionStatus {
278+ {
279+ TargetPodName : "source-mysql-az-a-4" ,
280+ VolumeSnapshots : []dpv1alpha1.VolumeSnapshotStatus {{
281+ Name : "snapshot-4" ,
282+ VolumeName : testdp .DataVolumeName ,
283+ }},
284+ },
285+ {
286+ TargetPodName : "source-mysql-az-a-3" ,
287+ VolumeSnapshots : []dpv1alpha1.VolumeSnapshotStatus {{
288+ Name : "snapshot-3" ,
289+ VolumeName : testdp .DataVolumeName ,
290+ }},
291+ },
292+ }
266293
267294 By ("test RestorePVCFromSnapshot function" )
268295 target := utils .GetBackupStatusTarget (backupSet .Backup , restoreMGR .Restore .Spec .Backup .SourceTargetName )
269296 Expect (restoreMGR .RestorePVCFromSnapshot (reqCtx , k8sClient , * backupSet , target )).Should (Succeed ())
270297
271- checkPVC (startingIndex , useVolumeSnapshot , "restore" )
298+ checkPVC (startingIndex , useVolumeSnapshot , constant .AppName )
299+ for i := 0 ; i < replicas ; i ++ {
300+ pvc := & corev1.PersistentVolumeClaim {}
301+ Expect (k8sClient .Get (ctx , client.ObjectKey {
302+ Namespace : testCtx .DefaultNamespace ,
303+ Name : fmt .Sprintf ("%s-%d" , testdp .MysqlTemplateName , startingIndex + i ),
304+ }, pvc )).Should (Succeed ())
305+ Expect (pvc .Spec .DataSource ).ShouldNot (BeNil ())
306+ Expect (pvc .Spec .DataSource .Name ).Should (Equal (fmt .Sprintf ("snapshot-%d" , startingIndex + i )))
307+ }
272308 })
273309
274310 It ("test with BuildPrepareDataJobs function and Parallel volumeRestorePolicy" , func () {
275311 reqCtx := getReqCtx ()
276- startingIndex := 1
312+ startingIndex := 3
313+ cmpName := "mysql"
277314 restoreMGR , backupSet := initResources (reqCtx , startingIndex , false , func (f * testdp.MockRestoreFactory ) {
278315 f .SetVolumeClaimsTemplate (testdp .MysqlTemplateName , testdp .DataVolumeName ,
279316 testdp .DataVolumeMountPath , "" , int32 (replicas ), int32 (startingIndex ), map [string ]string {
280- constant .AppInstanceLabelKey : instanceName ,
281- })
317+ constant .AppInstanceLabelKey : instanceName ,
318+ constant .KBAppComponentLabelKey : cmpName ,
319+ }).SetPrepareDataRequiredPolicy (dpv1alpha1 .OneToOneRestorePolicy , "" )
282320 })
321+ backupSet .Backup .Status .Path = "/repo/test/backup"
322+ backupSet .Backup .Status .Target .PodSelector .Strategy = dpv1alpha1 .PodSelectionStrategyAll
323+ backupSet .Backup .Status .Target .PodSelector .MatchLabels [constant .AppInstanceLabelKey ] = "source"
324+ backupSet .Backup .Status .Target .PodSelector .MatchLabels [constant .KBAppComponentLabelKey ] = cmpName
325+ backupSet .Backup .Status .Target .SelectedTargetPods = []string {"source-mysql-4" , "source-mysql-3" }
283326
284327 By (fmt .Sprintf ("test BuildPrepareDataJobs function, expect for %d jobs" , replicas ))
285328 actionSetName := "preparedata-0"
@@ -291,8 +334,12 @@ var _ = Describe("RestoreManager Test", func() {
291334 Expect (len (jobs )).Should (Equal (replicas ))
292335 // image should be expanded by env
293336 Expect (jobs [0 ].Spec .Template .Spec .Containers [0 ].Image ).Should (ContainSubstring (testdp .ImageTag ))
337+ for i := 0 ; i < replicas ; i ++ {
338+ env := utils .CovertEnvToMap (jobs [i ].Spec .Template .Spec .Containers [0 ].Env )
339+ Expect (env [dptypes .DPTargetRelativePath ]).Should (Equal (fmt .Sprintf ("source-mysql-%d" , startingIndex + i )))
340+ }
294341
295- checkPVC (startingIndex , false , "restore" )
342+ checkPVC (startingIndex , false , constant . AppName )
296343 })
297344
298345 It ("test with BuildPrepareDataJobs function with InstanceTemplates claims" , func () {
@@ -306,8 +353,18 @@ var _ = Describe("RestoreManager Test", func() {
306353 constant .AppInstanceLabelKey : instanceName ,
307354 constant .KBAppComponentLabelKey : cmpName ,
308355 constant .KBAppInstanceTemplateLabelKey : templateName ,
309- })
356+ }). SetPrepareDataRequiredPolicy ( dpv1alpha1 . OneToOneRestorePolicy , "" )
310357 })
358+ backupSet .Backup .Status .Path = "/repo/test/backup"
359+ backupSet .Backup .Status .Target .PodSelector .Strategy = dpv1alpha1 .PodSelectionStrategyAll
360+ backupSet .Backup .Status .Target .PodSelector .MatchLabels [constant .AppInstanceLabelKey ] = "source"
361+ backupSet .Backup .Status .Target .PodSelector .MatchLabels [constant .KBAppComponentLabelKey ] = cmpName
362+ backupSet .Backup .Status .Target .SelectedTargetPods = []string {
363+ "source-mysql-other-301" ,
364+ "source-mysql-abc-301" ,
365+ "source-mysql-other-300" ,
366+ "source-mysql-abc-300" ,
367+ }
311368 By (fmt .Sprintf ("test BuildPrepareDataJobs function, expect job label pod name contains template '%s' and ordinal correct" , templateName ))
312369 actionSetName := "preparedata-0"
313370 target := utils .GetBackupStatusTarget (backupSet .Backup , restoreMGR .Restore .Spec .Backup .SourceTargetName )
@@ -317,6 +374,8 @@ var _ = Describe("RestoreManager Test", func() {
317374 // job label contains pod name and ordinal match
318375 for i := 0 ; i < replicas ; i ++ {
319376 Expect (jobs [i ].Spec .Template .Labels [constant .KBAppPodNameLabelKey ]).Should (Equal (fmt .Sprintf ("%s-%s-%s-%d" , instanceName , cmpName , templateName , startingIndex + i )))
377+ env := utils .CovertEnvToMap (jobs [i ].Spec .Template .Spec .Containers [0 ].Env )
378+ Expect (env [dptypes .DPTargetRelativePath ]).Should (Equal (fmt .Sprintf ("source-mysql-%s-%d" , templateName , startingIndex + i )))
320379 }
321380
322381 checkPVC (startingIndex , false , constant .AppName )
0 commit comments