Skip to content

Commit 7e9d238

Browse files
authored
Merge pull request #1422 from huww98/fix-multi-attach-detach
disk: fix multi-attach disk detaching from node.
2 parents 596a863 + a5fbf58 commit 7e9d238

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

pkg/disk/cloud.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ func (ad *DiskAttachDetach) detachMultiAttachDisk(ctx context.Context, ecsClient
409409
return true, nil
410410
}
411411

412-
func (ad *DiskAttachDetach) detachDisk(ctx context.Context, ecsClient *ecs.Client, diskID, nodeID string) (err error) {
412+
func (ad *DiskAttachDetach) detachDisk(ctx context.Context, ecsClient *ecs.Client, diskID, nodeID string, fromNode bool) (err error) {
413413
disk, err := ad.findDiskByID(ctx, diskID)
414414
if err != nil {
415415
klog.Errorf("DetachDisk: Describe volume: %s from node: %s, with error: %s", diskID, nodeID, err.Error())
@@ -419,6 +419,10 @@ func (ad *DiskAttachDetach) detachDisk(ctx context.Context, ecsClient *ecs.Clien
419419
klog.Infof("DetachDisk: Detach Disk %s from node %s describe and find disk not exist", diskID, nodeID)
420420
return nil
421421
}
422+
if fromNode && disk.MultiAttach == "Enabled" {
423+
klog.Infof("DetachDisk: Skip detach multi-attach disk %s from node, it will be detached by controller", diskID)
424+
return nil
425+
}
422426

423427
defer func() {
424428
if err == nil {
@@ -447,7 +451,7 @@ func (ad *DiskAttachDetach) detachDisk(ctx context.Context, ecsClient *ecs.Clien
447451
ad.detaching.Store(diskID, nodeID)
448452
detachDiskRequest := ecs.CreateDetachDiskRequest()
449453
detachDiskRequest.DiskId = disk.DiskId
450-
detachDiskRequest.InstanceId = disk.InstanceId
454+
detachDiskRequest.InstanceId = nodeID
451455
if AllCategories[Category(disk.Category)].SingleInstance {
452456
detachDiskRequest.DeleteWithInstance = requests.NewBoolean(true)
453457
}

pkg/disk/controllerserver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func (cs *controllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
257257
// TODO: ECI does not support multi-attach?
258258
return nil, status.Errorf(codes.Internal, "refuse to delete disk on serverless instance %s", disk.InstanceId)
259259
}
260-
err := cs.ad.detachDisk(ctx, ecsClient, req.VolumeId, disk.InstanceId)
260+
err := cs.ad.detachDisk(ctx, ecsClient, req.VolumeId, disk.InstanceId, false)
261261
if err != nil {
262262
newErrMsg := utils.FindSuggestionByErrorMessage(err.Error(), utils.DiskDelete)
263263
return nil, status.Errorf(codes.Internal, "DeleteVolume: detach disk: %s from node: %s with error: %s", req.VolumeId, disk.InstanceId, newErrMsg)
@@ -388,7 +388,7 @@ func (cs *controllerServer) ControllerUnpublishVolume(ctx context.Context, req *
388388
}
389389

390390
klog.Infof("ControllerUnpublishVolume: detach disk: %s from node: %s", req.VolumeId, req.NodeId)
391-
err = cs.ad.detachDisk(ctx, ecsClient, req.VolumeId, req.NodeId)
391+
err = cs.ad.detachDisk(ctx, ecsClient, req.VolumeId, req.NodeId, false)
392392
if err != nil {
393393
klog.Errorf("ControllerUnpublishVolume: detach disk: %s from node: %s with error: %s", req.VolumeId, req.NodeId, err.Error())
394394
return nil, err

pkg/disk/nodeserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ func (ns *nodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstag
785785
return &csi.NodeUnstageVolumeResponse{}, nil
786786
}
787787
ecsClient := updateEcsClient(GlobalConfigVar.EcsClient)
788-
err = ns.ad.detachDisk(ctx, ecsClient, req.VolumeId, ns.NodeID)
788+
err = ns.ad.detachDisk(ctx, ecsClient, req.VolumeId, ns.NodeID, true)
789789
if err != nil {
790790
klog.Errorf("NodeUnstageVolume: VolumeId: %s, Detach failed with error %v", req.VolumeId, err.Error())
791791
return nil, err

0 commit comments

Comments
 (0)