diff --git a/changelogs/unreleased/7031-deefdragon b/changelogs/unreleased/7031-deefdragon deleted file mode 100644 index 430b8c0560..0000000000 --- a/changelogs/unreleased/7031-deefdragon +++ /dev/null @@ -1 +0,0 @@ -Fix #7031. Added check for Owner References when synchronizing backups, removing references that are not found. \ No newline at end of file diff --git a/changelogs/unreleased/7032-deefdragon b/changelogs/unreleased/7032-deefdragon new file mode 100644 index 0000000000..710ed3a110 --- /dev/null +++ b/changelogs/unreleased/7032-deefdragon @@ -0,0 +1 @@ +Fix #6857. Added check for matching Owner References when synchronizing backups, removing references that are not found/have mismatched uid. \ No newline at end of file diff --git a/pkg/controller/backup_sync_controller.go b/pkg/controller/backup_sync_controller.go index 3b2c758ba3..e199390388 100644 --- a/pkg/controller/backup_sync_controller.go +++ b/pkg/controller/backup_sync_controller.go @@ -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") + } default: - foundReferences = append(foundReferences, v) + log.Warnf("Unable to check ownership reference for unknown kind, %s", v.Kind) } + + foundReferences = append(foundReferences, v) } backup.ObjectMeta.OwnerReferences = foundReferences