Skip to content

Commit

Permalink
br: add aws region to aws config
Browse files Browse the repository at this point in the history
Signed-off-by: WangLe1321 <[email protected]>
  • Loading branch information
WangLe1321 committed Jul 24, 2023
1 parent 2c38d92 commit d44469d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
4 changes: 0 additions & 4 deletions cmd/backup-manager/app/util/backup_size.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ func CalcVolSnapBackupSize(ctx context.Context, provider v1alpha1.StorageProvide
return 0, 0, err
}

if err != nil {
return 0, 0, err
}

fullBackupSize, incrementalBackupSize, err = calcBackupSize(ctx, volSnapshots)

if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/backup/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ const (
// S3SecretKey represents the S3 compatible secret access key in related secret
S3SecretKey = "secret_key"

// AWSRegionEnv is the aws region environment variable
AWSRegionEnv = "AWS_REGION"

// GcsCredentialsKey represents the gcs service account credentials json key in related secret
GcsCredentialsKey = "credentials"

Expand Down
28 changes: 26 additions & 2 deletions pkg/backup/util/aws_ebs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@
package util

import (
"os"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/ec2metadata"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ebs"
"github.com/aws/aws-sdk-go/service/ebs/ebsiface"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/ec2/ec2iface"
"github.com/pingcap/errors"
"github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1"
"github.com/pingcap/tidb-operator/pkg/backup/constants"
"go.uber.org/atomic"
"golang.org/x/sync/errgroup"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -119,7 +123,17 @@ func NewEC2Session(concurrency uint) (*EC2Session, error) {
if err != nil {
return nil, errors.Trace(err)
}
ec2Session := ec2.New(sess)

region := os.Getenv(constants.AWSRegionEnv)
if region == "" {
ec2Metadata := ec2metadata.New(sess)
region, err = ec2Metadata.Region()
if err != nil {
return nil, errors.Annotate(err, "get ec2 region")
}
}

ec2Session := ec2.New(sess, aws.NewConfig().WithRegion(region))
return &EC2Session{EC2: ec2Session, concurrency: concurrency}, nil
}

Expand Down Expand Up @@ -201,6 +215,16 @@ func NewEBSSession(concurrency uint) (*EBSSession, error) {
if err != nil {
return nil, errors.Trace(err)
}
ebsSession := ebs.New(sess)

region := os.Getenv(constants.AWSRegionEnv)
if region == "" {
ec2Metadata := ec2metadata.New(sess)
region, err = ec2Metadata.Region()
if err != nil {
return nil, errors.Annotate(err, "get ec2 region")
}
}

ebsSession := ebs.New(sess, aws.NewConfig().WithRegion(region))
return &EBSSession{EBS: ebsSession, concurrency: concurrency}, nil
}

0 comments on commit d44469d

Please sign in to comment.