From 923e1e3af5df226806538d6128865d7a1705968c Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Mon, 20 Jan 2025 18:14:10 +0100 Subject: [PATCH] rbd: use `rbd.Manager` within `ControllerServer.DeleteVolume()` Signed-off-by: Niels de Vos --- internal/rbd/controllerserver.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/internal/rbd/controllerserver.go b/internal/rbd/controllerserver.go index 05a8f4bab..8e5e4441b 100644 --- a/internal/rbd/controllerserver.go +++ b/internal/rbd/controllerserver.go @@ -957,12 +957,17 @@ func (cs *ControllerServer) DeleteVolume( return &csi.DeleteVolumeResponse{}, nil } - rbdVol, err := GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets()) - defer func() { - if rbdVol != nil { - rbdVol.Destroy(ctx) - } - }() + mgr := NewManager(cs.Driver.GetInstanceID(), nil, req.GetSecrets()) + defer mgr.Destroy(ctx) + + vol, err := mgr.GetVolumeByID(ctx, volumeID) + if vol != nil { + defer vol.Destroy(ctx) + } + rbdVol, ok := vol.(*rbdVolume) // FIXME: temporary cast until rbdVolume is cleaned up + if !ok { + return nil, status.Error(codes.Internal, "BUG: failed to cast Volume to rbdVolume") + } if err != nil { return cs.checkErrAndUndoReserve(ctx, err, volumeID, rbdVol, cr) }