From bc593d0cb49584d8b85724953bd0cd7d3abc73ea Mon Sep 17 00:00:00 2001 From: Nikhil-Ladha Date: Wed, 4 Dec 2024 12:07:44 +0530 Subject: [PATCH] rbd: return group not found error for Get,Delete RPC calls We should return NotFound status if the group doesn't exists for ControllerGetVolumeGroup RPC call. And, an empty/OK response for DeleteVolumeGroup if the group doesn't exists Signed-off-by: Nikhil-Ladha --- internal/csi-addons/rbd/volumegroup.go | 12 ++++++++++-- internal/rbd/group/util.go | 7 +++++++ internal/rbd/group/volume_group.go | 6 +++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/internal/csi-addons/rbd/volumegroup.go b/internal/csi-addons/rbd/volumegroup.go index 065a6c517f8..10748b237de 100644 --- a/internal/csi-addons/rbd/volumegroup.go +++ b/internal/csi-addons/rbd/volumegroup.go @@ -18,10 +18,12 @@ package rbd import ( "context" + "errors" "fmt" "slices" "github.com/ceph/ceph-csi/internal/rbd" + "github.com/ceph/ceph-csi/internal/rbd/group" "github.com/ceph/ceph-csi/internal/rbd/types" "github.com/ceph/ceph-csi/internal/util/log" @@ -192,9 +194,15 @@ func (vs *VolumeGroupServer) DeleteVolumeGroup( // resolve the volume group vg, err := mgr.GetVolumeGroupByID(ctx, req.GetVolumeGroupId()) if err != nil { + if errors.Is(err, group.ErrRBDGroupNotFound) { + log.DebugLog(ctx, "VolumeGroup %q doesn't exists", req.GetVolumeGroupId()) + + return &volumegroup.DeleteVolumeGroupResponse{}, nil + } + return nil, status.Errorf( - codes.NotFound, - "could not find volume group %q: %s", + codes.Internal, + "could not fetch volume group %q: %s", req.GetVolumeGroupId(), err.Error()) } diff --git a/internal/rbd/group/util.go b/internal/rbd/group/util.go index 39583edf027..7928d0da937 100644 --- a/internal/rbd/group/util.go +++ b/internal/rbd/group/util.go @@ -23,6 +23,7 @@ import ( "time" "github.com/ceph/go-ceph/rados" + librbd "github.com/ceph/go-ceph/rbd" "github.com/ceph/ceph-csi/internal/journal" "github.com/ceph/ceph-csi/internal/util" @@ -145,6 +146,12 @@ func (cvg *commonVolumeGroup) getVolumeGroupAttributes(ctx context.Context) (*jo attrs = &journal.VolumeGroupAttributes{} } + if attrs.GroupName == "" || attrs.CreationTime == nil { + log.ErrorLog(ctx, "volume group with id %v not found", cvg.id) + + return nil, librbd.ErrNotFound + } + cvg.requestName = attrs.RequestName cvg.name = attrs.GroupName cvg.creationTime = attrs.CreationTime diff --git a/internal/rbd/group/volume_group.go b/internal/rbd/group/volume_group.go index cdb6a8cf0bf..50a3b24b51e 100644 --- a/internal/rbd/group/volume_group.go +++ b/internal/rbd/group/volume_group.go @@ -22,6 +22,7 @@ import ( "fmt" "github.com/ceph/go-ceph/rados" + librados "github.com/ceph/go-ceph/rados" librbd "github.com/ceph/go-ceph/rbd" "github.com/container-storage-interface/spec/lib/go/csi" "github.com/csi-addons/spec/lib/go/volumegroup" @@ -31,7 +32,10 @@ import ( "github.com/ceph/ceph-csi/internal/util/log" ) -var ErrRBDGroupNotConnected = errors.New("RBD group is not connected") +var ( + ErrRBDGroupNotConnected = fmt.Errorf("%w: RBD group is not connected", librados.ErrNotConnected) + ErrRBDGroupNotFound = fmt.Errorf("%w: RBD group not found", librbd.ErrNotFound) +) // volumeGroup handles all requests for 'rbd group' operations. type volumeGroup struct {