Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set hinting region to use for GetBucketRegion() #210

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelogs/unreleased/210-kaovilai
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix region discovery after aws-sdk-go-v2
27 changes: 13 additions & 14 deletions velero-plugin-for-aws/object_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,33 +137,32 @@ func (o *ObjectStore) Init(config map[string]string) error {
}
}

cfg, err := newConfigBuilder(o.log).WithRegion(region).
WithProfile(credentialProfile).
WithCredentialsFile(credentialsFile).
WithTLSSettings(insecureSkipTLSVerify, caCert).Build()
if err != nil {
return errors.WithStack(err)
}

// AWS (not an alternate S3-compatible API) and region not
// explicitly specified: determine the bucket's region
// GetBucketRegion will attempt to get the region for a bucket using the
// client's configured region to determine which AWS partition to perform the query on.
if s3URL == "" && region == "" {
cfg, err := newConfigBuilder(o.log).WithTLSSettings(insecureSkipTLSVerify, caCert).Build()
regionClient, err := newS3Client(cfg, s3URL, s3ForcePathStyle)
if err != nil {
return errors.WithStack(err)
}
client, err := newS3Client(cfg, s3URL, s3ForcePathStyle)
if err != nil {
return errors.WithStack(err)
}
region, err = manager.GetBucketRegion(context.Background(), client, bucket)
region, err = manager.GetBucketRegion(context.Background(), regionClient, bucket, func(o *s3.Options) { o.Region = "us-east-1" })
if err != nil {
o.log.Errorf("Failed to determine bucket's region bucket: %s, error: %v", bucket, err)
return err
}
if region == "" {
return fmt.Errorf("unable to determine bucket's region, bucket: %s", bucket)
}
}

cfg, err := newConfigBuilder(o.log).WithRegion(region).
WithProfile(credentialProfile).
WithCredentialsFile(credentialsFile).
WithTLSSettings(insecureSkipTLSVerify, caCert).Build()
if err != nil {
return errors.WithStack(err)
cfg.Region = region
}

client, err := newS3Client(cfg, s3URL, s3ForcePathStyle)
Expand Down
Loading