Skip to content

Commit

Permalink
*: pass region name for aws EBS volume operation
Browse files Browse the repository at this point in the history
Signed-off-by: BornChanger <[email protected]>
  • Loading branch information
BornChanger committed Jul 21, 2023
1 parent 8b1aa3b commit 02fff6e
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/backup-manager/app/clean/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (bo *Options) deleteVolumeSnapshots(meta *bkutil.EBSBasedBRMeta) error {
}
}

ec2Session, err := bkutil.NewEC2Session(CloudAPIConcurrency)
ec2Session, err := bkutil.NewEC2Session(CloudAPIConcurrency, meta.Region)
if err != nil {
klog.Errorf("new a ec2 session failure.")
return err
Expand Down
4 changes: 3 additions & 1 deletion pkg/backup/restore/restore_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ func (rm *restoreManager) syncRestoreJob(restore *v1alpha1.Restore) error {
return err
}

err = s.AddVolumeTags(pvs)
if restore.Spec.S3 != nil {
err = s.AddVolumeTags(pvs, restore.Spec.S3.Region)
}
if err != nil {
rm.statusUpdater.Update(restore, &v1alpha1.RestoreCondition{
Type: v1alpha1.RestoreRetryFailed,
Expand Down
2 changes: 1 addition & 1 deletion pkg/backup/snapshotter/snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type Snapshotter interface {
ResetPvAvailableZone(r *v1alpha1.Restore, pv *corev1.PersistentVolume)

// AddVolumeTags add operator related tags to volumes
AddVolumeTags(pvs []*corev1.PersistentVolume) error
AddVolumeTags(pvs []*corev1.PersistentVolume, regionName string) error
}

type BaseSnapshotter struct {
Expand Down
4 changes: 2 additions & 2 deletions pkg/backup/snapshotter/snapshotter_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (s *AWSSnapshotter) PrepareRestoreMetadata(r *v1alpha1.Restore, csb *CloudS
return s.BaseSnapshotter.prepareRestoreMetadata(r, csb, s)
}

func (s *AWSSnapshotter) AddVolumeTags(pvs []*corev1.PersistentVolume) error {
func (s *AWSSnapshotter) AddVolumeTags(pvs []*corev1.PersistentVolume, regionName string) error {
resourcesTags := make(map[string]util.TagMap)

for _, pv := range pvs {
Expand All @@ -112,7 +112,7 @@ func (s *AWSSnapshotter) AddVolumeTags(pvs []*corev1.PersistentVolume) error {

resourcesTags[volId] = tags
}
ec2Session, err := util.NewEC2Session(CloudAPIConcurrency)
ec2Session, err := util.NewEC2Session(CloudAPIConcurrency, regionName)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/backup/snapshotter/snapshotter_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (s *GCPSnapshotter) ResetPvAvailableZone(r *v1alpha1.Restore, pv *corev1.Pe
// TODO implement it if support to restore snapshots to another az on GCP
}

func (s *GCPSnapshotter) AddVolumeTags(pvs []*corev1.PersistentVolume) error {
func (s *GCPSnapshotter) AddVolumeTags(pvs []*corev1.PersistentVolume, regionName string) error {
// TODO implement it if support to restore snapshots to another az on GCP
return nil
}
2 changes: 1 addition & 1 deletion pkg/backup/snapshotter/snapshotter_none.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (s *NoneSnapshotter) PrepareRestoreMetadata(r *v1alpha1.Restore, csb *Cloud

func (s *NoneSnapshotter) ResetPvAvailableZone(r *v1alpha1.Restore, pv *corev1.PersistentVolume) {}

func (s *NoneSnapshotter) AddVolumeTags(pvs []*corev1.PersistentVolume) error {
func (s *NoneSnapshotter) AddVolumeTags(pvs []*corev1.PersistentVolume, regionName string) error {
// TODO implement it if support to restore snapshots to another az on GCP
return nil
}
4 changes: 2 additions & 2 deletions pkg/backup/util/aws_ebs.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ type EC2Session struct {

type TagMap map[string]string

func NewEC2Session(concurrency uint) (*EC2Session, error) {
func NewEC2Session(concurrency uint, region string) (*EC2Session, error) {
// aws-sdk has builtin exponential backoff retry mechanism, see:
// https://github.com/aws/aws-sdk-go/blob/db4388e8b9b19d34dcde76c492b17607cd5651e2/aws/client/default_retryer.go#L12-L16
// with default retryer & max-retry=9, we will wait for at least 30s in total
awsConfig := aws.NewConfig().WithMaxRetries(9)
awsConfig := aws.NewConfig().WithMaxRetries(9).WithRegion(region)
// TiDB Operator need make sure we have the correct permission to call aws api(through aws env variables)
// we may change this behaviour in the future.
sessionOptions := session.Options{Config: *awsConfig}
Expand Down

0 comments on commit 02fff6e

Please sign in to comment.