Skip to content

Commit

Permalink
Check only schedules, and verify UIDs are the same
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffrey Koehler committed Nov 1, 2023
1 parent 929af4f commit c92fc8e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
1 change: 0 additions & 1 deletion changelogs/unreleased/7031-deefdragon

This file was deleted.

1 change: 1 addition & 0 deletions changelogs/unreleased/7032-deefdragon
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix #6857. Added check for matching Owner References when synchronizing backups, removing references that are not found/have mismatched uid.
35 changes: 22 additions & 13 deletions pkg/controller/backup_sync_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,24 +172,33 @@ func (b *backupSyncReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}
backup.Labels[velerov1api.StorageLocationLabel] = label.GetValidName(backup.Spec.StorageLocation)

//check for the backup schedule. If it does not exist, remove it.
//check for the ownership references. If they do not exist, remove them.
listedReferences := backup.ObjectMeta.OwnerReferences
foundReferences := make([]metav1.OwnerReference, 0)
for _, v := range listedReferences {
schedule := new(velerov1api.Schedule)
err := b.client.Get(ctx, types.NamespacedName{
Name: v.Name,
Namespace: backup.Namespace,
}, schedule)
switch {
case err != nil && apierrors.IsNotFound(err):
log.Debug("Removing missing schedule ownership reference from backup")
case err != nil && !apierrors.IsNotFound(err):
log.WithError(errors.WithStack(err)).Error("Error finding ownership reference schedule")
fallthrough
switch v.Kind {
case "Schedule":

schedule := new(velerov1api.Schedule)
err := b.client.Get(ctx, types.NamespacedName{
Name: v.Name,
Namespace: backup.Namespace,
}, schedule)
switch {
case err != nil && apierrors.IsNotFound(err):
log.Warn("Removing missing schedule ownership reference from backup")
continue
case schedule.UID != v.UID:
log.Warnf("Removing schedule ownership reference with mismatched UIDs. Expected %s, got %s", v.UID, schedule.UID)
continue
case err != nil && !apierrors.IsNotFound(err):
log.WithError(errors.WithStack(err)).Error("Error finding schedule ownership reference, keeping schedule on backup")

Check warning on line 195 in pkg/controller/backup_sync_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/backup_sync_controller.go#L179-L195

Added lines #L179 - L195 were not covered by tests
}
default:
foundReferences = append(foundReferences, v)
log.Warnf("Unable to check ownership reference for unknown kind, %s", v.Kind)

Check warning on line 198 in pkg/controller/backup_sync_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/backup_sync_controller.go#L197-L198

Added lines #L197 - L198 were not covered by tests
}

foundReferences = append(foundReferences, v)

Check warning on line 201 in pkg/controller/backup_sync_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/backup_sync_controller.go#L201

Added line #L201 was not covered by tests
}
backup.ObjectMeta.OwnerReferences = foundReferences

Expand Down

0 comments on commit c92fc8e

Please sign in to comment.