Skip to content

Commit

Permalink
rbd: return group not found error for Get,Delete RPC calls
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Nikhil-Ladha committed Dec 12, 2024
1 parent 53d5eda commit 7595457
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
12 changes: 10 additions & 2 deletions internal/csi-addons/rbd/volumegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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())
}
Expand Down
6 changes: 6 additions & 0 deletions internal/rbd/group/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,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, ErrRBDGroupNotFound
}

cvg.requestName = attrs.RequestName
cvg.name = attrs.GroupName
cvg.creationTime = attrs.CreationTime
Expand Down
6 changes: 5 additions & 1 deletion internal/rbd/group/volume_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down

0 comments on commit 7595457

Please sign in to comment.