Improve directions when location CRDs not deployed

Signed-off-by: Carlisia <carlisia@grokkingtech.io>
This commit is contained in:
Carlisia
2018-12-07 10:41:40 -08:00
parent 5464b3dce8
commit 1906c33eb2
3 changed files with 14 additions and 6 deletions
+11 -2
View File
@@ -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
}
+2 -3
View File
@@ -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",