Skip to content

Commit

Permalink
disk: also use waiter for describe before attach/detach
Browse files Browse the repository at this point in the history
  • Loading branch information
huww98 committed Jul 27, 2024
1 parent 590a07a commit 7134e46
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pkg/disk/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (ad *DiskAttachDetach) attachDisk(ctx context.Context, tenantUserUID, diskI

ecsClient, err := getEcsClientByID("", tenantUserUID)
// Step 1: check disk status
disk, err := findDiskByID(diskID, ecsClient)
disk, err := ad.findDiskByID(ctx, diskID)
if err != nil {
log.Errorf("AttachDisk: find disk: %s with error: %s", diskID, err.Error())
return "", status.Errorf(codes.Internal, "AttachDisk: find disk: %s with error: %s", diskID, err.Error())
Expand Down Expand Up @@ -300,7 +300,7 @@ func (ad *DiskAttachDetach) attachSharedDisk(ctx context.Context, tenantUserUID,

ecsClient, err := getEcsClientByID("", tenantUserUID)
// Step 1: check disk status
disk, err := findDiskByID(diskID, ecsClient)
disk, err := ad.findDiskByID(ctx, diskID)
if err != nil {
log.Errorf("AttachDisk: find disk: %s with error: %s", diskID, err.Error())
return "", status.Errorf(codes.Internal, "AttachSharedDisk: find disk: %s with error: %s", diskID, err.Error())
Expand Down Expand Up @@ -343,7 +343,7 @@ func (ad *DiskAttachDetach) attachSharedDisk(ctx context.Context, tenantUserUID,
}

func (ad *DiskAttachDetach) detachMultiAttachDisk(ctx context.Context, ecsClient *ecs.Client, diskID, nodeID string) (isMultiAttach bool, err error) {
disk, err := findDiskByID(diskID, ecsClient)
disk, err := ad.findDiskByID(ctx, diskID)
if err != nil {
log.Errorf("DetachSharedDisk: Describe volume: %s from node: %s, with error: %s", diskID, nodeID, err.Error())
return false, status.Error(codes.Aborted, err.Error())
Expand Down Expand Up @@ -385,7 +385,7 @@ func (ad *DiskAttachDetach) detachMultiAttachDisk(ctx context.Context, ecsClient
}

func (ad *DiskAttachDetach) detachDisk(ctx context.Context, ecsClient *ecs.Client, diskID, nodeID string) error {
disk, err := findDiskByID(diskID, ecsClient)
disk, err := ad.findDiskByID(ctx, diskID)
if err != nil {
log.Errorf("DetachDisk: Describe volume: %s from node: %s, with error: %s", diskID, nodeID, err.Error())
return status.Error(codes.Aborted, err.Error())
Expand Down Expand Up @@ -544,6 +544,12 @@ func (ad *DiskAttachDetach) waitForDiskDetached(ctx context.Context, diskID, nod
return nil
}

func (ad *DiskAttachDetach) findDiskByID(ctx context.Context, diskID string) (*ecs.Disk, error) {
return ad.waiter.WaitForDiskNextStatus(ctx, diskID, func(disk *ecs.Disk) bool {
return true
})
}

func findDiskByID(diskID string, ecsClient *ecs.Client) (*ecs.Disk, error) {
describeDisksRequest := ecs.CreateDescribeDisksRequest()
describeDisksRequest.RegionId = GlobalConfigVar.Region
Expand Down

0 comments on commit 7134e46

Please sign in to comment.