Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
fix: resolve aws volume attachment check (#450)
Browse files Browse the repository at this point in the history
Signed-off-by: Ramiz Polic <[email protected]>
  • Loading branch information
ramizpolic authored Jul 6, 2023
1 parent 9b88720 commit 5205727
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions runtime_scan/pkg/provider/aws/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,27 +166,27 @@ func (v *Volume) IsReady(ctx context.Context) (bool, error) {
}

func (v *Volume) IsAttached(ctx context.Context) (bool, error) {
var attached bool

out, err := v.ec2Client.DescribeVolumes(ctx, &ec2.DescribeVolumesInput{
VolumeIds: []string{v.ID},
}, func(options *ec2.Options) {
options.Region = v.Region
})
if err != nil {
return attached, fmt.Errorf("failed to describe volumes. VolumeID=%s: %w", v.ID, err)
return false, fmt.Errorf("failed to describe volumes. VolumeID=%s: %w", v.ID, err)
}

if len(out.Volumes) != 1 {
return attached, fmt.Errorf("got unexcpected number of volumes (%d). Excpecting 1. VolumeID=%s",
return false, fmt.Errorf("got unexcpected number of volumes (%d). Excpecting 1. VolumeID=%s",
len(out.Volumes), v.ID)
}

if out.Volumes[0].Attachments[0].State == ec2types.VolumeAttachmentStateAttached {
attached = true
for _, attachment := range out.Volumes[0].Attachments {
if attachment.State == ec2types.VolumeAttachmentStateAttached {
return true, nil
}
}

return attached, nil
return false, nil
}

func (v *Volume) Delete(ctx context.Context) error {
Expand Down

0 comments on commit 5205727

Please sign in to comment.