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
Signed-off-by: Jeffrey Koehler <[email protected]>
  • Loading branch information
Jeffrey Koehler committed Nov 16, 2023
1 parent 929af4f commit 8eec686
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")
}
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

Expand Down

0 comments on commit 8eec686

Please sign in to comment.