Invalidate restores based on missing backups

When creating a restore based on a backup that doesn't exist, the
restore should be marked as invalid and the error clearly communicated
so the user understands why the restore wasn't made.

Previously, the restore was left as in progress with an error attached.

Since restores are CRDs and must be updated via a controller, there's
currently not a way to give the client immediate errors.

Signed-off-by: Nolan Brubaker <nolan@heptio.com>
pull/271/head
Nolan Brubaker 2018-01-04 11:05:09 -05:00
parent 656428d0b9
commit bb7b0a3c33
2 changed files with 4 additions and 2 deletions

View File

@ -294,6 +294,8 @@ func (controller *restoreController) getValidationErrors(itm *api.Restore) []str
if itm.Spec.BackupName == "" {
validationErrors = append(validationErrors, "BackupName must be non-empty and correspond to the name of a backup in object storage.")
} else if _, err := controller.fetchBackup(controller.bucket, itm.Spec.BackupName); err != nil {
validationErrors = append(validationErrors, fmt.Sprintf("Error retrieving backup: %v", err))
}
includedResources := sets.NewString(itm.Spec.IncludedResources...)

View File

@ -182,8 +182,8 @@ func TestProcessRestore(t *testing.T) {
name: "restore with non-existent backup name fails",
restore: arktest.NewTestRestore("foo", "bar", api.RestorePhaseNew).WithBackup("backup-1").WithIncludedNamespace("ns-1").Restore,
expectedErr: false,
expectedPhase: string(api.RestorePhaseInProgress),
expectedRestoreErrors: 1,
expectedPhase: string(api.RestorePhaseFailedValidation),
expectedValidationErrors: []string{"Error retrieving backup: no backup here"},
backupServiceGetBackupError: errors.New("no backup here"),
},
{