From 24f2d770c8e31b97dd6537841b2df184c1b38fde 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 | 5 +++++ internal/rbd/group/volume_group.go | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/internal/csi-addons/rbd/volumegroup.go b/internal/csi-addons/rbd/volumegroup.go index 065a6c517f8..add4b7e4345 100644 --- a/internal/csi-addons/rbd/volumegroup.go +++ b/internal/csi-addons/rbd/volumegroup.go @@ -22,6 +22,7 @@ import ( "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,6 +193,10 @@ func (vs *VolumeGroupServer) DeleteVolumeGroup( // resolve the volume group vg, err := mgr.GetVolumeGroupByID(ctx, req.GetVolumeGroupId()) if err != nil { + if 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", diff --git a/internal/rbd/group/volume_group.go b/internal/rbd/group/volume_group.go index cdb6a8cf0bf..7a824270051 100644 --- a/internal/rbd/group/volume_group.go +++ b/internal/rbd/group/volume_group.go @@ -31,7 +31,10 @@ import ( "github.com/ceph/ceph-csi/internal/util/log" ) -var ErrRBDGroupNotConnected = errors.New("RBD group is not connected") +var ( + ErrRBDGroupNotConnected = errors.New("RBD group is not connected") + ErrRBDGroupNotFound = errors.New("RBD group not found") +) // volumeGroup handles all requests for 'rbd group' operations. type volumeGroup struct { @@ -82,6 +85,11 @@ func GetVolumeGroup( return nil, fmt.Errorf("failed to get volume attributes for id %q: %w", vg, err) } + if attrs.GroupName == "" || attrs.CreationTime == nil { + log.ErrorLog(ctx, "volume group with id %v not found", id) + return nil, ErrRBDGroupNotFound + } + var volumes []types.Volume // it is needed to free the previously allocated volumes defer func() {