diff --git a/pkg/disk/cloud.go b/pkg/disk/cloud.go index a314cf3c6..4fca11099 100644 --- a/pkg/disk/cloud.go +++ b/pkg/disk/cloud.go @@ -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()) @@ -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()) @@ -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()) @@ -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()) @@ -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