Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/operations/rebuild_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,9 @@ func (r rebuildInstanceOpsHandler) prepareInplaceRebuildHelper(reqCtx intctrluti
// prepare backup infos
backup = &dpv1alpha1.Backup{}
if err = cli.Get(reqCtx.Ctx, client.ObjectKey{Name: rebuildInstance.BackupName, Namespace: opsRes.Cluster.Namespace}, backup); err != nil {
if apierrors.IsNotFound(err) {
return nil, intctrlutil.NewFatalError(fmt.Sprintf(`the backup "%s" is not found`, rebuildInstance.BackupName))
}
return nil, err
}
if !slices.Contains([]string{string(dpv1alpha1.BackupTypeFull), string(dpv1alpha1.BackupTypeIncremental)}, backup.Labels[dptypes.BackupTypeLabelKey]) {
Expand All @@ -609,6 +612,9 @@ func (r rebuildInstanceOpsHandler) prepareInplaceRebuildHelper(reqCtx intctrluti
}
actionSet, err = dputils.GetActionSetByName(reqCtx, cli, backup.Status.BackupMethod.ActionSetName)
Comment thread
leon-ape marked this conversation as resolved.
if err != nil {
if apierrors.IsNotFound(err) {
Comment thread
leon-ape marked this conversation as resolved.
Outdated
return nil, intctrlutil.NewFatalError(fmt.Sprintf(`the actionSet "%s" of the backup "%s" is not found`, backup.Status.BackupMethod.ActionSetName, rebuildInstance.BackupName))
}
return nil, err
}
}
Expand Down
60 changes: 60 additions & 0 deletions pkg/operations/rebuild_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,66 @@ var _ = Describe("OpsUtil functions", func() {
testRebuildInstanceWithBackup(true)
})

It("test rebuild instance in place when the backup does not exist", func() {
By("init operations resources with a nonexistent backup")
opsRes := prepareOpsRes("backup-not-exist-"+randomStr, true)
_ = testapps.MockInstanceSetComponent(&testCtx, clusterName, defaultCompName)
opsRes.OpsRequest.Status.Phase = opsv1alpha1.OpsRunningPhase
reqCtx := intctrlutil.RequestCtx{Ctx: testCtx.Ctx}
handler := rebuildInstanceOpsHandler{}

By("expect the missing backup to fail the instances instead of returning a retryable error")
_, _, err := handler.ReconcileAction(reqCtx, k8sClient, opsRes)
Expect(err).ShouldNot(HaveOccurred())
progressDetails := opsRes.OpsRequest.Status.Components[defaultCompName].ProgressDetails
Expect(progressDetails).Should(HaveLen(rebuildInstanceCount))
for _, detail := range progressDetails {
Expect(detail.Status).Should(Equal(opsv1alpha1.FailedProgressStatus))
Expect(detail.Message).Should(ContainSubstring("not found"))
}

By("expect the opsRequest to fail on the next reconciliation")
opsPhase, _, err := handler.ReconcileAction(reqCtx, k8sClient, opsRes)
Expect(err).ShouldNot(HaveOccurred())
Expect(opsPhase).Should(Equal(opsv1alpha1.OpsFailedPhase))
})

It("test rebuild instance in place when the actionSet of the backup does not exist", func() {
By("init operations resources with a backup that references a nonexistent actionSet")
backup := testdp.NewBackupFactory(testCtx.DefaultNamespace, testdp.BackupName).
SetBackupPolicyName(testdp.BackupPolicyName).
SetBackupMethod(testdp.BackupMethodName).
AddLabels(dptypes.BackupTypeLabelKey, string(dpv1alpha1.BackupTypeFull)).
Create(&testCtx).GetObject()
Expect(testapps.ChangeObjStatus(&testCtx, backup, func() {
backup.Status.Phase = dpv1alpha1.BackupPhaseCompleted
backup.Status.BackupMethod = &dpv1alpha1.BackupMethod{
Name: backup.Spec.BackupMethod,
ActionSetName: "actionset-not-exist-" + randomStr,
}
})).Should(Succeed())
opsRes := prepareOpsRes(backup.Name, true)
_ = testapps.MockInstanceSetComponent(&testCtx, clusterName, defaultCompName)
opsRes.OpsRequest.Status.Phase = opsv1alpha1.OpsRunningPhase
reqCtx := intctrlutil.RequestCtx{Ctx: testCtx.Ctx}
handler := rebuildInstanceOpsHandler{}

By("expect the missing actionSet to fail the instances instead of returning a retryable error")
_, _, err := handler.ReconcileAction(reqCtx, k8sClient, opsRes)
Expect(err).ShouldNot(HaveOccurred())
progressDetails := opsRes.OpsRequest.Status.Components[defaultCompName].ProgressDetails
Expect(progressDetails).Should(HaveLen(rebuildInstanceCount))
for _, detail := range progressDetails {
Expect(detail.Status).Should(Equal(opsv1alpha1.FailedProgressStatus))
Expect(detail.Message).Should(ContainSubstring("not found"))
}

By("expect the opsRequest to fail on the next reconciliation")
opsPhase, _, err := handler.ReconcileAction(reqCtx, k8sClient, opsRes)
Expect(err).ShouldNot(HaveOccurred())
Expect(opsPhase).Should(Equal(opsv1alpha1.OpsFailedPhase))
})

It("rebuild instance with horizontal scaling", func() {
By("init operations resources ")
opsRes, _, _ := initOperationsResources(compDefName, clusterName)
Expand Down
Loading