@@ -252,7 +252,7 @@ func (cs *controllerServer) ControllerPublishVolume(ctx context.Context, req *cs
252252 }
253253
254254 if _ , err := cs .connector .GetVMByID (ctx , nodeID ); err == cloud .ErrNotFound {
255- return nil , status .Errorf (codes .NotFound , "VM %v not found" , volumeID )
255+ return nil , status .Errorf (codes .NotFound , "VM %v not found" , nodeID )
256256 } else if err != nil {
257257 // Error with CloudStack
258258 return nil , status .Errorf (codes .Internal , "Error %v" , err )
@@ -285,15 +285,6 @@ func (cs *controllerServer) ControllerUnpublishVolume(ctx context.Context, req *
285285 return nil , status .Error (codes .InvalidArgument , "Volume ID missing in request" )
286286 }
287287 volumeID := req .GetVolumeId ()
288-
289- // TODO: according to the spec, node_id is allowed to be empty:
290- //
291- // If the value is set, the SP MUST unpublish the volume from
292- // the specified node. If the value is unset, the SP MUST unpublish
293- // the volume from all nodes it is published to.
294- if req .GetNodeId () == "" {
295- return nil , status .Error (codes .InvalidArgument , "Node ID missing in request" )
296- }
297288 nodeID := req .GetNodeId ()
298289
299290 // Check volume
@@ -304,8 +295,8 @@ func (cs *controllerServer) ControllerUnpublishVolume(ctx context.Context, req *
304295 } else if err != nil {
305296 // Error with CloudStack
306297 return nil , status .Errorf (codes .Internal , "Error %v" , err )
307- } else if vol .VirtualMachineID != nodeID {
308- // Nothing to do
298+ } else if nodeID != "" && vol .VirtualMachineID != nodeID {
299+ // Volume is present but not attached to this particular nodeID
309300 return & csi.ControllerUnpublishVolumeResponse {}, nil
310301 }
311302
@@ -317,7 +308,7 @@ func (cs *controllerServer) ControllerUnpublishVolume(ctx context.Context, req *
317308 return nil , status .Errorf (codes .Internal , "Error %v" , err )
318309 }
319310
320- err := cs .connector .DetachVolume (ctx , volumeID )
311+ err := cs .connector .DetachVolume (ctx , volumeID , nodeID )
321312 if err != nil {
322313 return nil , status .Errorf (codes .Internal , "Cannot detach volume %s: %s" , volumeID , err .Error ())
323314 }
0 commit comments