Skip to content

Commit

Permalink
Only send API request if NodeID is set in request and volume is attac…
Browse files Browse the repository at this point in the history
…hed to that node.
  • Loading branch information
alakae committed Mar 20, 2024
1 parent 759f775 commit 502133e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func (d *Driver) ControllerUnpublishVolume(ctx context.Context, req *csi.Control
ll.Info("controller unpublish volume called")

// check if volume exist before trying to detach it
_, err := d.cloudscaleClient.Volumes.Get(ctx, req.VolumeId)
volume, err := d.cloudscaleClient.Volumes.Get(ctx, req.VolumeId)
if err != nil {
errorResponse, ok := err.(*cloudscale.ErrorResponse)
if ok {
Expand All @@ -308,6 +308,20 @@ func (d *Driver) ControllerUnpublishVolume(ctx context.Context, req *csi.Control
return nil, err
}

isAttachedToNode := false
for _, serverUUID := range *volume.ServerUUIDs {
if serverUUID == req.NodeId {
isAttachedToNode = true
}
}

if req.NodeId != "" && !isAttachedToNode {
ll.WithField("volume", volume).Warn("Volume is not attached to node given in request.")
return &csi.ControllerUnpublishVolumeResponse{}, nil
}

ll.WithField("volume", volume).Warn("Volume is attached to node given in request or NodeID in request is not set.")

detachRequest := &cloudscale.VolumeRequest{
ServerUUIDs: &[]string{},
}
Expand Down

0 comments on commit 502133e

Please sign in to comment.