Skip to content

Commit

Permalink
tools shoud create secret
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyelei committed Oct 17, 2023
1 parent cf35873 commit 4d873e3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
15 changes: 10 additions & 5 deletions internal/dataprotection/restore/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,18 @@ func ValidateAndInitRestoreMGR(reqCtx intctrlutil.RequestCtx,
restoreMgr *RestoreManager) error {
backupName := restoreMgr.Restore.Spec.Backup.Name
backupNamespace := restoreMgr.Restore.Spec.Backup.Namespace
// get backupActionSet based on the specified backup name.
backupSet, err := restoreMgr.GetBackupActionSetByNamespaced(reqCtx, cli, backupName, backupNamespace)
if err != nil {
return err
}

restoreNamespace := restoreMgr.Restore.Namespace
if restoreNamespace != backupNamespace {
if backupSet.Backup.Status.PersistentVolumeClaimName != "" {
return intctrlutil.NewFatalError(fmt.Sprintf(`restore %s/%s isn't supported when the accessMethod of backupRepo "%s" is %s`,
backupNamespace, backupName, backupSet.Backup.Status.BackupRepoName, dpv1alpha1.AccessMethodMount))
}
// check if there is permission for cross namespace recovery.
isGrant, err := isGrantedForCrossNamespace(reqCtx, cli, restoreNamespace, backupName, backupNamespace)
if err != nil {
Expand All @@ -238,11 +248,6 @@ func ValidateAndInitRestoreMGR(reqCtx intctrlutil.RequestCtx,
return intctrlutil.NewFatalError(fmt.Sprintf("accessing %s/%s isn't allowed", backupNamespace, backupName))
}
}
// get backupActionSet based on the specified backup name.
backupSet, err := restoreMgr.GetBackupActionSetByNamespaced(reqCtx, cli, backupName, backupNamespace)
if err != nil {
return err
}

// check if the backup is completed exclude continuous backup.
var backupType dpv1alpha1.BackupType
Expand Down
18 changes: 13 additions & 5 deletions internal/dataprotection/restore/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ var _ = Describe("Restore Utils Test", func() {
return namespace
}

mockRestoreMGR := func(restoreNamespace string) *RestoreManager {
backup := mockBackupForRestore(&testCtx, actionSet.Name, testdp.BackupPVCName, true, true)
mockRestoreMGR := func(restoreNamespace string, backupPvcName string) *RestoreManager {
backup := mockBackupForRestore(&testCtx, actionSet.Name, backupPvcName, true, true)
restore := testdp.NewRestoreactory(restoreNamespace, testdp.RestoreName).
SetBackup(backup.Name, testCtx.DefaultNamespace).
SetVolumeClaimsTemplate(testdp.MysqlTemplateName, testdp.DataVolumeName,
Expand All @@ -118,24 +118,32 @@ var _ = Describe("Restore Utils Test", func() {
}

It("test ValidateAndInitRestoreMGR function, reference the backup with same namespace", func() {
restoreMGR := mockRestoreMGR(testCtx.DefaultNamespace)
restoreMGR := mockRestoreMGR(testCtx.DefaultNamespace, testdp.BackupPVCName)
reqCtx := getReqCtx()
Expect(ValidateAndInitRestoreMGR(reqCtx, k8sClient, recorder, restoreMGR)).Should(Succeed())
})

It("test ValidateAndInitRestoreMGR function, reference the backup with different namespace and no referenceGrant", func() {
mockMyNamespace()
restoreMGR := mockRestoreMGR(myNamespace)
restoreMGR := mockRestoreMGR(myNamespace, "")
reqCtx := getReqCtx()
err := ValidateAndInitRestoreMGR(reqCtx, k8sClient, recorder, restoreMGR)
Expect(err).Should(HaveOccurred())
Expect(err.Error()).Should(ContainSubstring("isn't allowed"))
testapps.ClearResourcesWithRemoveFinalizerOption(&testCtx, generics.RestoreSignature, true, client.InNamespace(myNamespace))
})

It("test ValidateAndInitRestoreMGR function, reference the backup with different namespace and backup with pvc", func() {
restoreMGR := mockRestoreMGR(myNamespace, testdp.BackupPVCName)
reqCtx := getReqCtx()
err := ValidateAndInitRestoreMGR(reqCtx, k8sClient, recorder, restoreMGR)
Expect(err).Should(HaveOccurred())
Expect(err.Error()).Should(ContainSubstring("isn't supported when the accessMethod of backupRepo"))
})

It("test ValidateAndInitRestoreMGR function, reference the backup with different namespace and referenceGrant", func() {
mockMyNamespace()
restoreMGR := mockRestoreMGR(myNamespace)
restoreMGR := mockRestoreMGR(myNamespace, "")
reqCtx := getReqCtx()
referenceGrant := &gatewayv1beta1.ReferenceGrant{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit 4d873e3

Please sign in to comment.