diff --git a/controller/volume_controller.go b/controller/volume_controller.go index ed24927d50..67953f1c93 100644 --- a/controller/volume_controller.go +++ b/controller/volume_controller.go @@ -3116,18 +3116,24 @@ func (c *VolumeController) checkAndFinishVolumeRestore(v *longhorn.Volume, e *lo return errors.Wrapf(err, "failed to get backup name from volume %s backup URL %v", v.Name, v.Spec.FromBackup) } bv, err := c.ds.GetBackupVolumeRO(bvName) - if err != nil { + if err != nil && !apierrors.IsNotFound(err) { return err } - if !bv.Status.LastSyncedAt.IsZero() && - bv.Spec.SyncRequestedAt.After(bv.Status.LastSyncedAt.Time) { - log.Infof("Restore/DR volume needs to wait for backup volume %s update", bvName) - return nil - } - if e.Status.LastRestoredBackup != bv.Status.LastBackupName { - log.Infof("Restore/DR volume needs to restore the latest backup %s, and the current restored backup is %s", bv.Status.LastBackupName, e.Status.LastRestoredBackup) - c.enqueueVolume(v) - return nil + if bv != nil { + if bv.Status.LastBackupName != "" { + // If the backup CR does not exist, the Longhorn system may be still syncing up the info with the remote backup target. + // If the backup is removed already, the backup volume should receive the notification and update bv.Status.LastBackupName. + // Hence we cannot continue the activation when the backup get call returns error IsNotFound. + b, err := c.ds.GetBackup(bv.Status.LastBackupName) + if err != nil { + return err + } + if b.Name != e.Status.LastRestoredBackup { + log.Infof("Restore/DR volume needs to restore the latest backup %s, and the current restored backup is %s", b.Name, e.Status.LastRestoredBackup) + c.enqueueVolume(v) + return nil + } + } } } diff --git a/manager/volume.go b/manager/volume.go index 250228523d..c317c11123 100644 --- a/manager/volume.go +++ b/manager/volume.go @@ -11,6 +11,7 @@ import ( "k8s.io/apimachinery/pkg/api/resource" corev1 "k8s.io/api/core/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/longhorn/longhorn-manager/datastore" @@ -447,6 +448,12 @@ func (m *VolumeManager) triggerBackupVolumeToSync(volume *longhorn.Volume) error backupVolume, err := m.ds.GetBackupVolume(backupVolumeName) if err != nil { + // The backup volume may be deleted already. + // hence it's better not to block the caller to continue the handlings like DR volume activation. + if apierrors.IsNotFound(err) { + logrus.Infof("Cannot find backup volume %v to trigger the sync-up, will skip it", backupVolumeName) + return nil + } return errors.Wrapf(err, "failed to get backup volume: %v", backupVolumeName) } requestSyncTime := metav1.Time{Time: time.Now().UTC()}