Skip to content

Commit

Permalink
ebs br: handle tag limit exceed issue
Browse files Browse the repository at this point in the history
Signed-off-by: BornChanger <dawn_catcher@126.com>
  • Loading branch information
BornChanger committed Feb 3, 2024
1 parent 7c7f198 commit 6846631
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions br/pkg/aws/ebs.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,20 @@ func (e *EC2Session) CreateSnapshots(backupInfo *config.EBSBasedBRMeta) (map[str
resp, err := e.createSnapshotsWithRetry(context.TODO(), &createSnapshotInput)

if err != nil {
return errors.Trace(err)
if aErr, ok := err.(awserr.Error); ok {
if aErr.Code() == "TagLimitExceeded" {
log.Warn("tag number exceeds AWS limitation during snapshots, retry without tagging")
createSnapshotInput.SetTagSpecifications(nil)
resp, err = e.createSnapshotsWithRetry(context.TODO(), &createSnapshotInput)
if err != nil {
return errors.Trace(err)
}
} else {
return errors.Trace(err)
}
} else {
return errors.Trace(err)
}
}
fillResult(resp)
return nil
Expand Down Expand Up @@ -592,10 +605,12 @@ func (e *EC2Session) CreateVolumes(meta *config.EBSBasedBRMeta, volumeType strin
return errors.Errorf("specified snapshot [%s] is not found", oldVol.SnapshotID)
}

// Copy tags from source snapshots
// Copy tags from source snapshots, but avoid recursive tagging
for j := range resp.Snapshots[0].Tags {
tags = append(tags,
ec2Tag("snapshot/"+aws.StringValue(resp.Snapshots[0].Tags[j].Key), aws.StringValue(resp.Snapshots[0].Tags[j].Value)))
if !strings.HasPrefix(aws.StringValue(resp.Snapshots[0].Tags[j].Key), "snapshot/") {
tags = append(tags,
ec2Tag("snapshot/"+aws.StringValue(resp.Snapshots[0].Tags[j].Key), aws.StringValue(resp.Snapshots[0].Tags[j].Value)))
}
}

req.SetTagSpecifications([]*ec2.TagSpecification{
Expand All @@ -607,7 +622,20 @@ func (e *EC2Session) CreateVolumes(meta *config.EBSBasedBRMeta, volumeType strin

newVol, err := e.ec2.CreateVolume(&req)
if err != nil {
return errors.Trace(err)
if aErr, ok := err.(awserr.Error); ok {
if aErr.Code() == "TagLimitExceeded" {
log.Warn("tag number exceeds AWS limitation, retry without tagging", zap.String("from_snapshot", oldVol.SnapshotID))
req.SetTagSpecifications(nil)
newVol, err = e.ec2.CreateVolume(&req)
if err != nil {
return errors.Trace(err)
}
} else {
return errors.Trace(err)
}
} else {
return errors.Trace(err)
}
}
log.Info("new volume creating", zap.Stringer("vol", newVol))
fillResult(newVol, oldVol)
Expand Down

0 comments on commit 6846631

Please sign in to comment.