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 <jiangd@vmware.com>
pull/4372/head
Daniel Jiang 2021-11-15 20:20:27 +08:00 committed by GitHub
parent 983489073f
commit 130602d723
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 4 deletions

View File

@ -0,0 +1 @@
Return the error if velero failed to detect S3 region for restic repo

View File

@ -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

View File

@ -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-<region>.amazonaws.com URL format is used if region can be determined for AWS BSL",