From 130602d72341bbc0528e0e0e4469fb666cc507b6 Mon Sep 17 00:00:00 2001 From: Daniel Jiang Date: Mon, 15 Nov 2021 20:20:27 +0800 Subject: [PATCH] Return the error if velero failed to detect S3 region for restic repo (#4343) The error should be returned explicitly, because when the default URL is used S3 will return a 301 and the response can't be handled by restic. Fixes #4178 Signed-off-by: Daniel Jiang --- changelogs/unreleased/4343-reasonerjt | 1 + pkg/restic/config.go | 5 ++--- pkg/restic/config_test.go | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 changelogs/unreleased/4343-reasonerjt diff --git a/changelogs/unreleased/4343-reasonerjt b/changelogs/unreleased/4343-reasonerjt new file mode 100644 index 000000000..1a8e548e6 --- /dev/null +++ b/changelogs/unreleased/4343-reasonerjt @@ -0,0 +1 @@ +Return the error if velero failed to detect S3 region for restic repo \ No newline at end of file diff --git a/pkg/restic/config.go b/pkg/restic/config.go index b5471fa37..4cde8336a 100644 --- a/pkg/restic/config.go +++ b/pkg/restic/config.go @@ -74,10 +74,9 @@ func getRepoPrefix(location *velerov1api.BackupStorageLocation) (string, error) region, err = getAWSBucketRegion(bucket) } if err != nil { - url = "s3.amazonaws.com" - } else { - url = fmt.Sprintf("s3-%s.amazonaws.com", region) + return "", errors.Wrapf(err, "failed to detect the region via bucket: %s", bucket) } + url = fmt.Sprintf("s3-%s.amazonaws.com", region) } return fmt.Sprintf("s3:%s/%s", url, path.Join(bucket, prefix)), nil diff --git a/pkg/restic/config_test.go b/pkg/restic/config_test.go index ad2413104..8418d6808 100644 --- a/pkg/restic/config_test.go +++ b/pkg/restic/config_test.go @@ -85,7 +85,8 @@ func TestGetRepoIdentifier(t *testing.T) { getAWSBucketRegion: func(string) (string, error) { return "", errors.New("no region found") }, - expected: "s3:s3.amazonaws.com/bucket/restic/repo-1", + expected: "", + expectedErr: "failed to detect the region via bucket: bucket: no region found", }, { name: "s3.s3-.amazonaws.com URL format is used if region can be determined for AWS BSL",