Skip to content

Commit

Permalink
Ensure that LinodeID matches before detach.
Browse files Browse the repository at this point in the history
Avoid calling detach when Volume is assigned to different LinodeID.
  • Loading branch information
Michkov committed Jan 15, 2024
1 parent bc685b1 commit 16fed95
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/linode-bs/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,15 @@ func (linodeCS *LinodeControllerServer) ControllerUnpublishVolume(ctx context.Co
"method": "controller_unpublish_volume",
})

volume, err := linodeCS.CloudProvider.GetVolume(ctx, volumeID)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
if *volume.LinodeID != linodeID {
klog.V(4).Infof("volume is attached to %d, not to %d, skipping", *volume.LinodeID, linodeID)
return &csi.ControllerUnpublishVolumeResponse{}, nil
}

if err := linodeCS.CloudProvider.DetachVolume(ctx, volumeID); err != nil {
if apiErr, ok := err.(*linodego.Error); ok && apiErr.Code == 404 {
return &csi.ControllerUnpublishVolumeResponse{}, nil
Expand Down

0 comments on commit 16fed95

Please sign in to comment.