diff --git a/pkg/cmd/server/server.go b/pkg/cmd/server/server.go index 107ccf199..d8ac6c313 100644 --- a/pkg/cmd/server/server.go +++ b/pkg/cmd/server/server.go @@ -299,7 +299,7 @@ func (s *server) run() error { if _, err := s.arkClient.ArkV1().BackupStorageLocations(s.namespace).Get(s.config.defaultBackupLocation, metav1.GetOptions{}); err != nil { s.logger.WithError(errors.WithStack(err)). - Warnf("Default backup storage location %q not found; backups must explicitly specify a location", s.config.defaultBackupLocation) + Warnf("A backup storage location named %s has been specified for the server to use by default, but no corresponding backup storage location exists. Backups with a location not matching the default will need to explicitly specify an existing location", s.config.defaultBackupLocation) } if err := s.initRestic(); err != nil { diff --git a/pkg/controller/backup_controller.go b/pkg/controller/backup_controller.go index 8a886db3b..c98313050 100644 --- a/pkg/controller/backup_controller.go +++ b/pkg/controller/backup_controller.go @@ -29,6 +29,7 @@ import ( jsonpatch "github.com/evanphx/json-patch" "github.com/pkg/errors" "github.com/sirupsen/logrus" + apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/types" @@ -274,7 +275,11 @@ func (c *backupController) prepareBackupRequest(backup *api.Backup) *pkgbackup.R // validate the storage location, and store the BackupStorageLocation API obj on the request if storageLocation, err := c.backupLocationLister.BackupStorageLocations(request.Namespace).Get(request.Spec.StorageLocation); err != nil { - request.Status.ValidationErrors = append(request.Status.ValidationErrors, fmt.Sprintf("Error getting backup storage location: %v", err)) + if apierrors.IsNotFound(err) { + request.Status.ValidationErrors = append(request.Status.ValidationErrors, fmt.Sprintf("a BackupStorageLocation CRD with the name specified in the backup spec needs to be created before this backup can be executed. Error: %v", err)) + } else { + request.Status.ValidationErrors = append(request.Status.ValidationErrors, fmt.Sprintf("error getting backup storage location: %v", err)) + } } else { request.StorageLocation = storageLocation } @@ -309,7 +314,11 @@ func (c *backupController) validateAndGetSnapshotLocations(backup *api.Backup) ( // validate each locationName exists as a VolumeSnapshotLocation location, err := c.snapshotLocationLister.VolumeSnapshotLocations(backup.Namespace).Get(locationName) if err != nil { - errors = append(errors, fmt.Sprintf("error getting volume snapshot location named %s: %v", locationName, err)) + if apierrors.IsNotFound(err) { + errors = append(errors, fmt.Sprintf("a VolumeSnapshotLocation CRD for the location %s with the name specified in the backup spec needs to be created before this snapshot can be executed. Error: %v", locationName, err)) + } else { + errors = append(errors, fmt.Sprintf("error getting volume snapshot location named %s: %v", locationName, err)) + } continue } diff --git a/pkg/controller/backup_controller_test.go b/pkg/controller/backup_controller_test.go index 4d9c20c36..41dfb4f2b 100644 --- a/pkg/controller/backup_controller_test.go +++ b/pkg/controller/backup_controller_test.go @@ -150,7 +150,7 @@ func TestProcessBackupValidationFailures(t *testing.T) { { name: "non-existent backup location fails validation", backup: arktest.NewTestBackup().WithName("backup-1").WithStorageLocation("nonexistent").Backup, - expectedErrs: []string{"Error getting backup storage location: backupstoragelocation.ark.heptio.com \"nonexistent\" not found"}, + expectedErrs: []string{"a BackupStorageLocation CRD with the name specified in the backup spec needs to be created before this backup can be executed. Error: backupstoragelocation.ark.heptio.com \"nonexistent\" not found"}, }, } @@ -370,8 +370,7 @@ func TestValidateAndGetSnapshotLocations(t *testing.T) { arktest.NewTestVolumeSnapshotLocation().WithProvider("aws").WithName("aws-us-west-1"), arktest.NewTestVolumeSnapshotLocation().WithProvider("fake-provider").WithName("some-name"), }, - expectedErrors: "error getting volume snapshot location named random-name: volumesnapshotlocation.ark.heptio.com \"random-name\" not found", - expectedSuccess: false, + expectedErrors: "a VolumeSnapshotLocation CRD for the location random-name with the name specified in the backup spec needs to be created before this snapshot can be executed. Error: volumesnapshotlocation.ark.heptio.com \"random-name\" not found", expectedSuccess: false, }, { name: "duplicate locationName per provider: should filter out dups",