Skip to content

Commit

Permalink
Deal with PartiallyFailed orphaned backups as well as Completed ones
Browse files Browse the repository at this point in the history
Fixes vmware-tanzu#6648

Signed-off-by: Scott Seago <sseago@redhat.com>
  • Loading branch information
sseago committed Aug 14, 2023
1 parent 713792d commit 441a32a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/6649-sseago
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deal with PartiallyFailed orphaned backups as well as Completed ones
2 changes: 1 addition & 1 deletion pkg/controller/backup_sync_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func (b *backupSyncReconciler) deleteOrphanedBackups(ctx context.Context, locati

for i, backup := range backupList.Items {
log = log.WithField("backup", backup.Name)
if backup.Status.Phase != velerov1api.BackupPhaseCompleted || backupStoreBackups.Has(backup.Name) {
if !(backup.Status.Phase == velerov1api.BackupPhaseCompleted || backup.Status.Phase == velerov1api.BackupPhasePartiallyFailed) || backupStoreBackups.Has(backup.Name) {
continue
}

Expand Down
25 changes: 17 additions & 8 deletions pkg/controller/backup_sync_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ var _ = Describe("Backup Sync Reconciler", func() {
k8sBackups: []*velerov1api.Backup{
baseBuilder("backupA").Phase(velerov1api.BackupPhaseCompleted).Result(),
baseBuilder("backupB").Phase(velerov1api.BackupPhaseCompleted).Result(),
baseBuilder("backupC").Phase(velerov1api.BackupPhaseCompleted).Result(),
baseBuilder("backupC").Phase(velerov1api.BackupPhasePartiallyFailed).Result(),
},
expectedDeletes: sets.NewString("backupA", "backupB", "backupC"),
},
Expand All @@ -568,9 +568,10 @@ var _ = Describe("Backup Sync Reconciler", func() {
k8sBackups: []*velerov1api.Backup{
baseBuilder("backup-1").Phase(velerov1api.BackupPhaseCompleted).Result(),
baseBuilder("backup-2").Phase(velerov1api.BackupPhaseCompleted).Result(),
baseBuilder("backup-C").Phase(velerov1api.BackupPhaseCompleted).Result(),
baseBuilder("backup-B").Phase(velerov1api.BackupPhaseCompleted).Result(),
baseBuilder("backup-C").Phase(velerov1api.BackupPhasePartiallyFailed).Result(),
},
expectedDeletes: sets.NewString("backup-C"),
expectedDeletes: sets.NewString("backup-B", "backup-C"),
},
{
name: "all overlapping backups",
Expand All @@ -579,7 +580,7 @@ var _ = Describe("Backup Sync Reconciler", func() {
k8sBackups: []*velerov1api.Backup{
baseBuilder("backup-1").Phase(velerov1api.BackupPhaseCompleted).Result(),
baseBuilder("backup-2").Phase(velerov1api.BackupPhaseCompleted).Result(),
baseBuilder("backup-3").Phase(velerov1api.BackupPhaseCompleted).Result(),
baseBuilder("backup-3").Phase(velerov1api.BackupPhasePartiallyFailed).Result(),
},
expectedDeletes: sets.NewString(),
},
Expand All @@ -589,13 +590,14 @@ var _ = Describe("Backup Sync Reconciler", func() {
cloudBackups: sets.NewString("backup-1", "backup-2", "backup-3"),
k8sBackups: []*velerov1api.Backup{
baseBuilder("backupA").Phase(velerov1api.BackupPhaseCompleted).Result(),
baseBuilder("backupB").Phase(velerov1api.BackupPhasePartiallyFailed).Result(),
baseBuilder("Deleting").Phase(velerov1api.BackupPhaseDeleting).Result(),
baseBuilder("Failed").Phase(velerov1api.BackupPhaseFailed).Result(),
baseBuilder("FailedValidation").Phase(velerov1api.BackupPhaseFailedValidation).Result(),
baseBuilder("InProgress").Phase(velerov1api.BackupPhaseInProgress).Result(),
baseBuilder("New").Phase(velerov1api.BackupPhaseNew).Result(),
},
expectedDeletes: sets.NewString("backupA"),
expectedDeletes: sets.NewString("backupA", "backupB"),
},
{
name: "all overlapping backups and all backups that are not complete",
Expand All @@ -616,12 +618,13 @@ var _ = Describe("Backup Sync Reconciler", func() {
baseBuilder("backup-1").Phase(velerov1api.BackupPhaseCompleted).Result(),
baseBuilder("backup-2").Phase(velerov1api.BackupPhaseCompleted).Result(),
baseBuilder("backup-C").Phase(velerov1api.BackupPhaseCompleted).Result(),
baseBuilder("backup-D").Phase(velerov1api.BackupPhasePartiallyFailed).Result(),

baseBuilder("backup-4").ObjectMeta(builder.WithLabels(velerov1api.StorageLocationLabel, "alternate")).Phase(velerov1api.BackupPhaseCompleted).Result(),
baseBuilder("backup-5").ObjectMeta(builder.WithLabels(velerov1api.StorageLocationLabel, "alternate")).Phase(velerov1api.BackupPhaseCompleted).Result(),
baseBuilder("backup-6").ObjectMeta(builder.WithLabels(velerov1api.StorageLocationLabel, "alternate")).Phase(velerov1api.BackupPhaseCompleted).Result(),
baseBuilder("backup-6").ObjectMeta(builder.WithLabels(velerov1api.StorageLocationLabel, "alternate")).Phase(velerov1api.BackupPhasePartiallyFailed).Result(),
},
expectedDeletes: sets.NewString("backup-C"),
expectedDeletes: sets.NewString("backup-C", "backup-D"),
},
{
name: "some overlapping backups",
Expand All @@ -646,8 +649,14 @@ var _ = Describe("Backup Sync Reconciler", func() {
).
Phase(velerov1api.BackupPhaseCompleted).
Result(),
builder.ForBackup("ns-1", "backup-D").
ObjectMeta(
builder.WithLabels(velerov1api.StorageLocationLabel, "the-really-long-location-name-that-is-much-more-than-63-c69e779"),
).
Phase(velerov1api.BackupPhasePartiallyFailed).
Result(),
},
expectedDeletes: sets.NewString("backup-C"),
expectedDeletes: sets.NewString("backup-C", "backup-D"),
useLongBSLName: true,
},
}
Expand Down

0 comments on commit 441a32a

Please sign in to comment.