Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions pkg/disk/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,43 +379,6 @@ func (ad *DiskAttachDetach) attachMultiAttachDisk(ctx context.Context, diskID, n
return "", nil
}

func (ad *DiskAttachDetach) detachMultiAttachDisk(ctx context.Context, ecsClient cloud.ECSInterface, diskID, nodeID string) (isMultiAttach bool, err error) {
disk, err := ad.findDiskByID(ctx, diskID)
if err != nil {
klog.Errorf("DetachMultiAttachDisk: Describe volume: %s from node: %s, with error: %s", diskID, nodeID, err.Error())
return false, status.Error(codes.Aborted, err.Error())
}
if disk == nil {
klog.Infof("DetachMultiAttachDisk: Detach Disk %s from node %s describe and find disk not exist", diskID, nodeID)
return false, nil
}
if disk.MultiAttach == "Disabled" {
return false, nil
}

if waitstatus.IsInstanceAttached(disk, nodeID) {
klog.Infof("DetachMultiAttachDisk: Starting to Detach Disk %s from node %s", diskID, nodeID)
detachDiskRequest := ecs.CreateDetachDiskRequest()
detachDiskRequest.DiskId = disk.DiskId
detachDiskRequest.InstanceId = nodeID
response, err := ecsClient.DetachDisk(detachDiskRequest)
if err != nil {
return true, status.Errorf(codes.Aborted, "DetachMultiAttachDisk: Fail to detach %s: from Instance: %s with error: %v", disk.DiskId, disk.InstanceId, err)
}

// check disk detach
err = ad.waitForDiskDetached(ctx, diskID, nodeID)
if err != nil {
return true, status.Errorf(codes.Aborted, "DetachMultiAttachDisk: Detaching Disk %s failed: %v", diskID, err)
}
klog.Infof("DetachMultiAttachDisk: Volume: %s Success to detach disk %s from Instance %s, RequestId: %s", diskID, disk.DiskId, disk.InstanceId, response.RequestId)
} else {
klog.Infof("DetachMultiAttachDisk: Skip Detach, disk %s have not detachable instance", diskID)
}

return true, nil
}

func (ad *DiskAttachDetach) detachDisk(ctx context.Context, ecsClient cloud.ECSInterface, diskID, nodeID string, fromNode bool) (err error) {
disk, err := ad.findDiskByID(ctx, diskID)
if err != nil {
Expand Down
16 changes: 1 addition & 15 deletions pkg/disk/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,20 +358,6 @@ func (cs *controllerServer) ControllerPublishVolume(ctx context.Context, req *cs

// ControllerUnpublishVolume do detach
func (cs *controllerServer) ControllerUnpublishVolume(ctx context.Context, req *csi.ControllerUnpublishVolumeRequest) (*csi.ControllerUnpublishVolumeResponse, error) {
// Describe Disk Info
isMultiAttach, err := cs.ad.detachMultiAttachDisk(ctx, cs.ecs, req.VolumeId, req.NodeId)
if isMultiAttach && err != nil {
klog.Errorf("ControllerUnpublishVolume: detach multiAttach disk: %s from node: %s with error: %s", req.VolumeId, req.NodeId, err.Error())
return nil, err
} else if isMultiAttach {
klog.Infof("ControllerUnpublishVolume: Successful detach multiAttach disk: %s from node: %s", req.VolumeId, req.NodeId)
return &csi.ControllerUnpublishVolumeResponse{}, nil
}

if !GlobalConfigVar.ADControllerEnable {
klog.Infof("ControllerUnpublishVolume: ADController Disable to detach disk: %s from node: %s", req.VolumeId, req.NodeId)
return &csi.ControllerUnpublishVolumeResponse{}, nil
}

// if DetachDisabled is set to true, return
if GlobalConfigVar.DetachDisabled {
Expand All @@ -380,7 +366,7 @@ func (cs *controllerServer) ControllerUnpublishVolume(ctx context.Context, req *
}

klog.Infof("ControllerUnpublishVolume: detach disk: %s from node: %s", req.VolumeId, req.NodeId)
err = cs.ad.detachDisk(ctx, cs.ecs, req.VolumeId, req.NodeId, false)
err := cs.ad.detachDisk(ctx, cs.ecs, req.VolumeId, req.NodeId, false)
if err != nil {
klog.Errorf("ControllerUnpublishVolume: detach disk: %s from node: %s with error: %s", req.VolumeId, req.NodeId, err.Error())
return nil, err
Expand Down
Loading