Skip to content

Commit fa896bc

Browse files
authored
fix: restore ops is always Creating when the Point of time incorrect (#10112)
1 parent 4857828 commit fa896bc

3 files changed

Lines changed: 72 additions & 10 deletions

File tree

pkg/dataprotection/restore/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func (r *RestoreManager) BuildContinuousRestoreManager(reqCtx intctrlutil.Reques
158158
if startTime.IsZero() || stopTime.IsZero() {
159159
return intctrlutil.NewFatalError(fmt.Sprintf(`startTimeStamp or completeTimeStamp of backup "%s" is empty`, continuousBackup.Name))
160160
}
161-
if restoreTime.Before(startTime.Time) || restoreTime.After(stopTime.Time) {
161+
if !isTimeInRange(restoreTime, startTime.Time, stopTime.Time) {
162162
return intctrlutil.NewFatalError(fmt.Sprintf(`restore time out of the range for backup "%s"`, continuousBackup.Name))
163163
}
164164
return nil

pkg/dataprotection/restore/manager_test.go

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -417,27 +417,35 @@ var _ = Describe("RestoreManager Test", func() {
417417
})
418418

419419
Context("BuildContinuousRestoreManager", func() {
420-
It("respects UnifyFullAndContinuousRestore annotation", func() {
421-
By("create a continuous backup")
420+
const (
421+
continuousBackupStartTime = "2023-01-01T09:00:00Z"
422+
continuousBackupEndTime = "2023-01-01T12:00:00Z"
423+
)
424+
425+
createContinuousBackupAndRestore := func(restoreTime string) (*dpv1alpha1.Backup, *dpv1alpha1.Restore) {
422426
continuousBackup := mockBackupForRestore(
423427
&testCtx, actionSet.Name, testdp.BackupPVCName, true, false, dpv1alpha1.BackupTypeContinuous,
424-
"2023-01-01T09:00:00Z", "2023-01-01T12:00:00Z", "test-backup-continuous",
428+
continuousBackupStartTime, continuousBackupEndTime, "test-backup-continuous",
425429
)
426430

427-
By("create a completed backup")
428-
_ = mockBackupForRestore(&testCtx, actionSet.Name, testdp.BackupPVCName, true, false, dpv1alpha1.BackupTypeFull, "", "2023-01-01T10:00:00Z", "")
429-
430431
schedulingSpec := dpv1alpha1.SchedulingSpec{
431432
NodeName: nodeName,
432433
}
433434

434-
By("create restore")
435435
restore := testdp.NewRestoreFactory(testCtx.DefaultNamespace, testdp.RestoreName).
436436
SetBackup(continuousBackup.Name, testCtx.DefaultNamespace).
437437
SetSchedulingSpec(schedulingSpec).
438438
Create(&testCtx).
439-
SetRestoreTime("2023-01-01T11:30:00Z").
439+
SetRestoreTime(restoreTime).
440440
Get()
441+
return continuousBackup, restore
442+
}
443+
444+
It("respects UnifyFullAndContinuousRestore annotation", func() {
445+
By("create a completed backup")
446+
_ = mockBackupForRestore(&testCtx, actionSet.Name, testdp.BackupPVCName, true, false, dpv1alpha1.BackupTypeFull, "", "2023-01-01T10:00:00Z", "")
447+
448+
continuousBackup, restore := createContinuousBackupAndRestore("2023-01-01T11:30:00Z")
441449

442450
By("create restore manager")
443451
reqCtx := getReqCtx()
@@ -465,6 +473,60 @@ var _ = Describe("RestoreManager Test", func() {
465473
Expect(restoreMGR.PostReadyBackupSets).Should(HaveLen(1))
466474

467475
})
476+
477+
When("restoreTime is at boundary values", func() {
478+
It("should fail when restoreTime equals backup start time", func() {
479+
_ = mockBackupForRestore(&testCtx, actionSet.Name, testdp.BackupPVCName, true, false, dpv1alpha1.BackupTypeFull, "", "2023-01-01T09:00:00Z", "")
480+
continuousBackup, restore := createContinuousBackupAndRestore(continuousBackupStartTime)
481+
482+
reqCtx := getReqCtx()
483+
restoreMGR := NewRestoreManager(restore, recorder, k8sClient.Scheme(), k8sClient)
484+
backupSet, err := restoreMGR.GetBackupActionSetByNamespaced(reqCtx, k8sClient, continuousBackup.Name, testCtx.DefaultNamespace)
485+
Expect(err).ShouldNot(HaveOccurred())
486+
487+
_ = restoreMGR.BuildContinuousRestoreManager(reqCtx, k8sClient, *backupSet)
488+
Expect(restoreMGR.PostReadyBackupSets).Should(HaveLen(2))
489+
})
490+
491+
It("should fail when restoreTime equals backup end time", func() {
492+
_ = mockBackupForRestore(&testCtx, actionSet.Name, testdp.BackupPVCName, true, false, dpv1alpha1.BackupTypeFull, "", "2023-01-01T10:00:00Z", "")
493+
continuousBackup, restore := createContinuousBackupAndRestore(continuousBackupEndTime)
494+
495+
reqCtx := getReqCtx()
496+
restoreMGR := NewRestoreManager(restore, recorder, k8sClient.Scheme(), k8sClient)
497+
backupSet, err := restoreMGR.GetBackupActionSetByNamespaced(reqCtx, k8sClient, continuousBackup.Name, testCtx.DefaultNamespace)
498+
Expect(err).ShouldNot(HaveOccurred())
499+
500+
_ = restoreMGR.BuildContinuousRestoreManager(reqCtx, k8sClient, *backupSet)
501+
Expect(restoreMGR.PostReadyBackupSets).Should(HaveLen(2))
502+
})
503+
504+
It("should failed when restoreTime is before backup start time", func() {
505+
_ = mockBackupForRestore(&testCtx, actionSet.Name, testdp.BackupPVCName, true, false, dpv1alpha1.BackupTypeFull, "", "2023-01-01T10:00:00Z", "")
506+
continuousBackup, restore := createContinuousBackupAndRestore("2023-01-01T08:00:00Z")
507+
508+
reqCtx := getReqCtx()
509+
restoreMGR := NewRestoreManager(restore, recorder, k8sClient.Scheme(), k8sClient)
510+
backupSet, err := restoreMGR.GetBackupActionSetByNamespaced(reqCtx, k8sClient, continuousBackup.Name, testCtx.DefaultNamespace)
511+
Expect(err).ShouldNot(HaveOccurred())
512+
513+
err = restoreMGR.BuildContinuousRestoreManager(reqCtx, k8sClient, *backupSet)
514+
Expect(err).Should(HaveOccurred())
515+
})
516+
517+
It("should failed when restoreTime is after backup end time", func() {
518+
_ = mockBackupForRestore(&testCtx, actionSet.Name, testdp.BackupPVCName, true, false, dpv1alpha1.BackupTypeFull, "", "2023-01-01T10:00:00Z", "")
519+
continuousBackup, restore := createContinuousBackupAndRestore("2023-01-01T13:00:00Z")
520+
521+
reqCtx := getReqCtx()
522+
restoreMGR := NewRestoreManager(restore, recorder, k8sClient.Scheme(), k8sClient)
523+
backupSet, err := restoreMGR.GetBackupActionSetByNamespaced(reqCtx, k8sClient, continuousBackup.Name, testCtx.DefaultNamespace)
524+
Expect(err).ShouldNot(HaveOccurred())
525+
526+
err = restoreMGR.BuildContinuousRestoreManager(reqCtx, k8sClient, *backupSet)
527+
Expect(err).Should(HaveOccurred())
528+
})
529+
})
468530
})
469531
})
470532

pkg/operations/restore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func (r RestoreOpsHandler) restoreClusterFromBackup(reqCtx intctrlutil.RequestCt
168168
if backupType == string(dpv1alpha1.BackupTypeContinuous) {
169169
restoreTimeStr, err := restore.FormatRestoreTimeAndValidate(restoreSpec.RestorePointInTime, backup)
170170
if err != nil {
171-
return nil, err
171+
return nil, intctrlutil.NewFatalError(err.Error())
172172
}
173173
opsRequest.Spec.GetRestore().RestorePointInTime = restoreTimeStr
174174
}

0 commit comments

Comments
 (0)