Skip to content

Commit

Permalink
*: sync map deletion
Browse files Browse the repository at this point in the history
Signed-off-by: BornChanger <[email protected]>
  • Loading branch information
BornChanger committed Jan 3, 2024
1 parent 3f90f63 commit 8b80686
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/backup/util/aws_ebs.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"golang.org/x/sync/errgroup"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/klog/v2"
"k8s.io/klog"
)

// TODO: shall this structure be refactor or reserved for future use?
Expand Down Expand Up @@ -156,6 +156,9 @@ func (e *EC2Session) DeleteSnapshots(snapIDMap map[string]string) error {
_, err := e.EC2.DeleteSnapshot(&ec2.DeleteSnapshotInput{
SnapshotId: &snapID,
})

lock.Lock()
defer lock.Unlock()
if err != nil {
if strings.Contains(err.Error(), "NotFound") {
klog.Warningf("snapshot %s not found, err: %s", snapID, err.Error())
Expand All @@ -166,8 +169,6 @@ func (e *EC2Session) DeleteSnapshots(snapIDMap map[string]string) error {
klog.Errorf("failed to delete snapshot id=%s, error=%s", snapID, err)
// todo: we can only retry for a few times, might fail still, need to handle error from outside.
// we don't return error if it fails to make sure all snapshot got chance to delete.
lock.Lock()
defer lock.Unlock()
errs = multierr.Combine(errs, err)
return nil
} else {
Expand Down

0 comments on commit 8b80686

Please sign in to comment.