feat: support configure BSL CR to indicate which one is the default (#3092)

* Add default field to BSL CRD

Signed-off-by: JenTing Hsiao <jenting.hsiao@suse.com>

* Add a new flag `--default` under `velero backup-location create`

add a new flag `--default` under `velero backup-location create`
to specify this new location to be the new default BSL.

Signed-off-by: JenTing Hsiao <jenting.hsiao@suse.com>

* Add a new default field under `velero backup-location get`

add a new default field under `velero backup-location get` to indicate
which BSL is the default one.

Signed-off-by: JenTing Hsiao <jenting.hsiao@suse.com>

* Add a new sub-command and flag under `velero backup-location`

Add a new sub-command called `velero backup-location set` sub-command
and a new flag `velero backup-cation set --default` to configure which
BSL is the default one.

Signed-off-by: JenTing Hsiao <jenting.hsiao@suse.com>

* Add new flag to get the default backup-location

Add a new flag `--default` under `velero backup-location get`
to displays the current default BSL.

Signed-off-by: JenTing Hsiao <jenting.hsiao@suse.com>

* Configures default BSL in BSL controller

When upgrade the BSL CRDs, none of the BSL has been labeled as default.
Sets the BSL default field to true if the BSL name matches to the default BSL setting.

Signed-off-by: JenTing Hsiao <jenting.hsiao@suse.com>

* Configures the default BSL in BSL controller for velero upgrade

When upgrade the BSL CRDs, none of the BSL be marked as the default.
Sets the BSL `.spec.default: true` if the BSL name matches against the
`velero server --default-backup-storage-location`.

Signed-off-by: JenTing Hsiao <jenting.hsiao@suse.com>

* Add unit test to test default BSL behavior

Signed-off-by: JenTing Hsiao <jenting.hsiao@suse.com>

* Update check which one is the default BSL in backup/backup_sync/restore controller

Signed-off-by: JenTing Hsiao <jenting.hsiao@suse.com>

* Add changelog

Signed-off-by: JenTing Hsiao <jenting.hsiao@suse.com>

* Update docs locations.md and upgrade-to-1.6.md

Signed-off-by: JenTing Hsiao <jenting.hsiao@suse.com>
This commit is contained in:
JenTing Hsiao
2020-12-08 16:38:29 -05:00
committed by GitHub
parent 5eb64eb84b
commit 9dd158d13d
21 changed files with 440 additions and 64 deletions
@@ -67,13 +67,25 @@ func (r *BackupStorageLocationReconciler) Reconcile(req ctrl.Request) (ctrl.Resu
defer pluginManager.CleanupClients()
var defaultFound bool
for _, location := range locationList.Items {
if location.Spec.Default {
defaultFound = true
break
}
}
var unavailableErrors []string
var anyVerified bool
for i := range locationList.Items {
location := &locationList.Items[i]
isDefault := location.Spec.Default
log := r.Log.WithField("controller", BackupStorageLocation).WithField(BackupStorageLocation, location.Name)
if location.Name == r.DefaultBackupLocationInfo.StorageLocation {
if !defaultFound && location.Name == r.DefaultBackupLocationInfo.StorageLocation {
// For backward-compatible, to configure the backup storage location as the default if
// none of the BSLs be marked as the default and the BSL name matches against the
// "velero server --default-backup-storage-location".
isDefault = true
defaultFound = true
}
@@ -95,29 +107,28 @@ func (r *BackupStorageLocationReconciler) Reconcile(req ctrl.Request) (ctrl.Resu
continue
}
// updates the default backup location
location.Spec.Default = isDefault
log.Info("Validating backup storage location")
anyVerified = true
if err := backupStore.IsValid(); err != nil {
log.Info("Backup location is invalid, marking as unavailable")
unavailableErrors = append(unavailableErrors, errors.Wrapf(err, "Backup location %q is unavailable", location.Name).Error())
if location.Name == r.DefaultBackupLocationInfo.StorageLocation {
log.Warnf("The specified default backup location named %q is unavailable; for convenience, be sure to configure it properly or make another backup location that is available the default", r.DefaultBackupLocationInfo.StorageLocation)
}
log.Info("Backup storage location is invalid, marking as unavailable")
unavailableErrors = append(unavailableErrors, errors.Wrapf(err, "Backup storage location %q is unavailable", location.Name).Error())
location.Status.Phase = velerov1api.BackupStorageLocationPhaseUnavailable
} else {
log.Info("Backup location valid, marking as available")
log.Info("Backup storage location valid, marking as available")
location.Status.Phase = velerov1api.BackupStorageLocationPhaseAvailable
}
location.Status.LastValidationTime = &metav1.Time{Time: time.Now().UTC()}
if err := patchHelper.Patch(r.Ctx, location); err != nil {
log.WithError(err).Error("Error updating backup location phase")
log.WithError(err).Error("Error updating backup storage location phase")
}
}
if !anyVerified {
log.Debug("No backup locations needed to be validated")
log.Debug("No backup storage locations needed to be validated")
}
r.logReconciledPhase(defaultFound, locationList, unavailableErrors)
@@ -154,11 +165,11 @@ func (r *BackupStorageLocationReconciler) logReconciledPhase(defaultFound bool,
log.Errorf("Current backup storage locations available/unavailable/unknown: %v/%v/%v)", numAvailable, numUnavailable, numUnknown)
}
} else if numUnavailable > 0 { // some but not all BSL unavailable
log.Warnf("Invalid backup locations detected: available/unavailable/unknown: %v/%v/%v, %s)", numAvailable, numUnavailable, numUnknown, strings.Join(errs, "; "))
log.Warnf("Invalid backup storage locations detected: available/unavailable/unknown: %v/%v/%v, %s)", numAvailable, numUnavailable, numUnknown, strings.Join(errs, "; "))
}
if !defaultFound {
log.Warnf("The specified default backup location named %q was not found; for convenience, be sure to create one or make another backup location that is available the default", r.DefaultBackupLocationInfo.StorageLocation)
log.Warn("The default backup storage location was not found; for convenience, be sure to create one or make another backup location that is designated as the default")
}
}