mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-03 11:45:20 +00:00
Merge pull request #1022 from shubheksha/fix/945-restore-controller-remove-checking-backup-storage-directly
Remove code that checks backup storage directly from restore controller
This commit is contained in:
@@ -121,6 +121,27 @@ func shouldSync(location *arkv1api.BackupStorageLocation, now time.Time, backupS
|
||||
return false, ""
|
||||
}
|
||||
|
||||
// orderedBackupLocations returns a new slice with the default backup location first (if it exists),
|
||||
// followed by the rest of the locations in no particular order.
|
||||
func orderedBackupLocations(locations []*arkv1api.BackupStorageLocation, defaultLocationName string) []*arkv1api.BackupStorageLocation {
|
||||
var result []*arkv1api.BackupStorageLocation
|
||||
|
||||
for i := range locations {
|
||||
if locations[i].Name == defaultLocationName {
|
||||
// put the default location first
|
||||
result = append(result, locations[i])
|
||||
// append everything before the default
|
||||
result = append(result, locations[:i]...)
|
||||
// append everything after the default
|
||||
result = append(result, locations[i+1:]...)
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
return locations
|
||||
}
|
||||
|
||||
func (c *backupSyncController) run() {
|
||||
c.logger.Debug("Checking for existing backup storage locations to sync into cluster")
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ import (
|
||||
jsonpatch "github.com/evanphx/json-patch"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
@@ -397,17 +396,11 @@ func mostRecentCompletedBackup(backups []*api.Backup) *api.Backup {
|
||||
}
|
||||
|
||||
// fetchBackupInfo checks the backup lister for a backup that matches the given name. If it doesn't
|
||||
// find it, it tries to retrieve it from one of the backup storage locations.
|
||||
// find it, it returns an error.
|
||||
func (c *restoreController) fetchBackupInfo(backupName string, pluginManager plugin.Manager) (backupInfo, error) {
|
||||
backup, err := c.backupLister.Backups(c.namespace).Get(backupName)
|
||||
if err != nil {
|
||||
if !apierrors.IsNotFound(err) {
|
||||
return backupInfo{}, errors.WithStack(err)
|
||||
}
|
||||
|
||||
log := c.logger.WithField("backupName", backupName)
|
||||
log.Debug("Backup not found in backupLister, checking each backup location directly, starting with default...")
|
||||
return c.fetchFromBackupStorage(backupName, pluginManager)
|
||||
return backupInfo{}, err
|
||||
}
|
||||
|
||||
location, err := c.backupLocationLister.BackupStorageLocations(c.namespace).Get(backup.Spec.StorageLocation)
|
||||
@@ -426,50 +419,6 @@ func (c *restoreController) fetchBackupInfo(backupName string, pluginManager plu
|
||||
}, nil
|
||||
}
|
||||
|
||||
// fetchFromBackupStorage checks each backup storage location, starting with the default,
|
||||
// looking for a backup that matches the given backup name.
|
||||
func (c *restoreController) fetchFromBackupStorage(backupName string, pluginManager plugin.Manager) (backupInfo, error) {
|
||||
locations, err := c.backupLocationLister.BackupStorageLocations(c.namespace).List(labels.Everything())
|
||||
if err != nil {
|
||||
return backupInfo{}, errors.WithStack(err)
|
||||
}
|
||||
|
||||
orderedLocations := orderedBackupLocations(locations, c.defaultBackupLocation)
|
||||
|
||||
log := c.logger.WithField("backupName", backupName)
|
||||
for _, location := range orderedLocations {
|
||||
info, err := c.backupInfoForLocation(location, backupName, pluginManager)
|
||||
if err != nil {
|
||||
log.WithField("locationName", location.Name).WithError(err).Error("Unable to fetch backup from object storage location")
|
||||
continue
|
||||
}
|
||||
return info, nil
|
||||
}
|
||||
|
||||
return backupInfo{}, errors.New("not able to fetch from backup storage")
|
||||
}
|
||||
|
||||
// orderedBackupLocations returns a new slice with the default backup location first (if it exists),
|
||||
// followed by the rest of the locations in no particular order.
|
||||
func orderedBackupLocations(locations []*api.BackupStorageLocation, defaultLocationName string) []*api.BackupStorageLocation {
|
||||
var result []*api.BackupStorageLocation
|
||||
|
||||
for i := range locations {
|
||||
if locations[i].Name == defaultLocationName {
|
||||
// put the default location first
|
||||
result = append(result, locations[i])
|
||||
// append everything before the default
|
||||
result = append(result, locations[:i]...)
|
||||
// append everything after the default
|
||||
result = append(result, locations[i+1:]...)
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
return locations
|
||||
}
|
||||
|
||||
func (c *restoreController) backupInfoForLocation(location *api.BackupStorageLocation, backupName string, pluginManager plugin.Manager) (backupInfo, error) {
|
||||
backupStore, err := persistence.NewObjectBackupStore(location, pluginManager, c.logger)
|
||||
if err != nil {
|
||||
|
||||
@@ -287,7 +287,7 @@ func TestProcessRestore(t *testing.T) {
|
||||
restore: NewRestore("foo", "bar", "backup-1", "ns-1", "*", api.RestorePhaseNew).Restore,
|
||||
expectedErr: false,
|
||||
expectedPhase: string(api.RestorePhaseFailedValidation),
|
||||
expectedValidationErrors: []string{"Error retrieving backup: not able to fetch from backup storage"},
|
||||
expectedValidationErrors: []string{"Error retrieving backup: backup.ark.heptio.com \"backup-1\" not found"},
|
||||
backupStoreGetBackupMetadataErr: errors.New("no backup here"),
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user