Skip to content

Commit

Permalink
Fix to wait for delete_mount_targets to complete (#1140)
Browse files Browse the repository at this point in the history
* fix to wait for delete mount targets to complete

* create efs volume with mount targets
  • Loading branch information
bathina2 committed Nov 16, 2021
1 parent 9ad3a9f commit 1e2a881
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
15 changes: 13 additions & 2 deletions pkg/blockstorage/awsefs/awsefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ func (e *efs) VolumeCreate(ctx context.Context, volume blockstorage.Volume) (*bl
if err != nil {
return nil, errors.Wrap(err, "Failed to get recently create EFS instance")
}
_, mountTargets, err := filterAndGetMountTargetsFromTags(blockstorage.KeyValueToMap(volume.Tags))
if err != nil {
return nil, errors.Wrap(err, "Failed to get filtered tags and mount targets")
}
if err = e.createMountTargets(ctx, vol.ID, mountTargets); err != nil {
return nil, errors.Wrap(err, "Failed to create mount targets")
}
return vol, nil
}

Expand Down Expand Up @@ -254,12 +261,12 @@ func parseMountTargetValue(value string) (*mountTarget, error) {
// Example value:
// subnet-123+securityGroup-1+securityGroup-2
tokens := strings.Split(value, securityGroupSeperator)
if len(tokens) <= 1 {
if len(tokens) < 1 {
return nil, errors.New("Malformed string for mount target values")
}
subnetID := tokens[0]
sgs := make([]string, 0)
if len(tokens[1]) != 0 {
if len(tokens) > 1 {
sgs = append(sgs, tokens[1:]...)
}
return &mountTarget{
Expand Down Expand Up @@ -349,6 +356,10 @@ func (e *efs) deleteMountTargets(ctx context.Context, mts []*awsefs.MountTargetD
if err != nil {
return err
}
err = e.waitUntilMountTargetIsDeleted(ctx, *mt.MountTargetId)
if err != nil {
return err
}
}
return nil
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/blockstorage/awsefs/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,22 @@ func (e *efs) waitUntilMountTargetReady(ctx context.Context, mountTargetID strin
})
}

func (e *efs) waitUntilMountTargetIsDeleted(ctx context.Context, mountTargetID string) error {
return poll.Wait(ctx, func(ctx context.Context) (bool, error) {
req := &awsefs.DescribeMountTargetsInput{}
req.SetMountTargetId(mountTargetID)

_, err := e.DescribeMountTargetsWithContext(ctx, req)
if isMountTargetNotFound(err) {
return true, nil
}
if err != nil {
return false, err
}
return false, nil
})
}

func (e *efs) waitUntilRestoreComplete(ctx context.Context, restoreJobID string) error {
return poll.Wait(ctx, func(ctx context.Context) (bool, error) {
req := &backup.DescribeRestoreJobInput{}
Expand Down

0 comments on commit 1e2a881

Please sign in to comment.