mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-08-15 11:46:06 +00:00
Enhance checkpoint of bsl deletion
Signed-off-by: danfengl <danfengl@vmware.com>
This commit is contained in:
@@ -161,5 +161,5 @@ func BackupsSyncTest() {
|
||||
}
|
||||
|
||||
func (b *SyncBackups) IsBackupsSynced() error {
|
||||
return WaitForBackupCreated(b.ctx, VeleroCfg.VeleroCLI, b.backupName, 10*time.Minute)
|
||||
return WaitForBackupToBeCreated(b.ctx, VeleroCfg.VeleroCLI, b.backupName, 10*time.Minute)
|
||||
}
|
||||
|
||||
@@ -252,12 +252,12 @@ func BslDeletionTest(useVolumeSnapshots bool) {
|
||||
}
|
||||
|
||||
By(fmt.Sprintf("Backup 1 %s should be created.", backupName_1), func() {
|
||||
Expect(WaitForBackupCreated(context.Background(), VeleroCfg.VeleroCLI,
|
||||
Expect(WaitForBackupToBeCreated(context.Background(), VeleroCfg.VeleroCLI,
|
||||
backupName_1, 10*time.Minute)).To(Succeed())
|
||||
})
|
||||
|
||||
By(fmt.Sprintf("Backup 2 %s should be created.", backupName_2), func() {
|
||||
Expect(WaitForBackupCreated(context.Background(), VeleroCfg.VeleroCLI,
|
||||
Expect(WaitForBackupToBeCreated(context.Background(), VeleroCfg.VeleroCLI,
|
||||
backupName_2, 10*time.Minute)).To(Succeed())
|
||||
})
|
||||
|
||||
@@ -280,6 +280,7 @@ func BslDeletionTest(useVolumeSnapshots bool) {
|
||||
|
||||
By(fmt.Sprintf("Delete one of backup locations - %s", backupLocation_1), func() {
|
||||
Expect(DeleteBslResource(context.Background(), VeleroCfg.VeleroCLI, backupLocation_1)).To(Succeed())
|
||||
Expect(WaitForBackupsToBeDeleted(context.Background(), VeleroCfg.VeleroCLI, backupsInBSL1, 10*time.Minute)).To(Succeed())
|
||||
})
|
||||
|
||||
By("Get all backups from 2 BSLs after deleting one of them", func() {
|
||||
|
||||
@@ -705,6 +705,7 @@ func getVeleroCliTarball(cliTarballUrl string) (*os.File, error) {
|
||||
|
||||
return tmpfile, nil
|
||||
}
|
||||
|
||||
func DeleteBackupResource(ctx context.Context, veleroCLI string, backupName string) error {
|
||||
args := []string{"backup", "delete", backupName, "--confirm"}
|
||||
|
||||
@@ -771,19 +772,48 @@ func WaitBackupDeleted(ctx context.Context, veleroCLI string, backupName string,
|
||||
})
|
||||
}
|
||||
|
||||
func WaitForBackupCreated(ctx context.Context, veleroCLI string, backupName string, timeout time.Duration) error {
|
||||
func WaitForExpectedStateOfBackup(ctx context.Context, veleroCLI string, backupName string,
|
||||
timeout time.Duration, existing bool) error {
|
||||
return wait.PollImmediate(10*time.Second, timeout, func() (bool, error) {
|
||||
if exist, err := IsBackupExist(ctx, veleroCLI, backupName); err != nil {
|
||||
return false, err
|
||||
} else {
|
||||
if exist {
|
||||
msg := "does not exist"
|
||||
if existing {
|
||||
msg = "was found"
|
||||
}
|
||||
if exist == existing {
|
||||
fmt.Println("Backup <" + backupName + "> " + msg)
|
||||
return true, nil
|
||||
} else {
|
||||
fmt.Println("Backup <" + backupName + "> " + msg)
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func WaitForBackupToBeCreated(ctx context.Context, veleroCLI string, backupName string, timeout time.Duration) error {
|
||||
return WaitForExpectedStateOfBackup(ctx, veleroCLI, backupName, timeout, true)
|
||||
}
|
||||
|
||||
func WaitForBackupToBeDeleted(ctx context.Context, veleroCLI string, backupName string, timeout time.Duration) error {
|
||||
return WaitForExpectedStateOfBackup(ctx, veleroCLI, backupName, timeout, false)
|
||||
}
|
||||
|
||||
func WaitForBackupsToBeDeleted(ctx context.Context, veleroCLI string, backups []string, timeout time.Duration) error {
|
||||
var err error
|
||||
for _, backupName := range backups {
|
||||
fmt.Println("Waiting for deletion of backup <" + backupName + ">")
|
||||
err = WaitForExpectedStateOfBackup(ctx, veleroCLI, backupName, timeout, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
fmt.Println("All backups were deleted.")
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetBackupsFromBsl(ctx context.Context, veleroCLI, bslName string) ([]string, error) {
|
||||
args1 := []string{"get", "backups"}
|
||||
if strings.TrimSpace(bslName) != "" {
|
||||
|
||||
Reference in New Issue
Block a user