Skip to content

Commit bc593d0

Browse files
committed
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 <nikhilladha1999@gmail.com>
1 parent a32ba13 commit bc593d0

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

internal/csi-addons/rbd/volumegroup.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ package rbd
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223
"slices"
2324

2425
"github.com/ceph/ceph-csi/internal/rbd"
26+
"github.com/ceph/ceph-csi/internal/rbd/group"
2527
"github.com/ceph/ceph-csi/internal/rbd/types"
2628
"github.com/ceph/ceph-csi/internal/util/log"
2729

@@ -192,9 +194,15 @@ func (vs *VolumeGroupServer) DeleteVolumeGroup(
192194
// resolve the volume group
193195
vg, err := mgr.GetVolumeGroupByID(ctx, req.GetVolumeGroupId())
194196
if err != nil {
197+
if errors.Is(err, group.ErrRBDGroupNotFound) {
198+
log.DebugLog(ctx, "VolumeGroup %q doesn't exists", req.GetVolumeGroupId())
199+
200+
return &volumegroup.DeleteVolumeGroupResponse{}, nil
201+
}
202+
195203
return nil, status.Errorf(
196-
codes.NotFound,
197-
"could not find volume group %q: %s",
204+
codes.Internal,
205+
"could not fetch volume group %q: %s",
198206
req.GetVolumeGroupId(),
199207
err.Error())
200208
}

internal/rbd/group/util.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"time"
2424

2525
"github.com/ceph/go-ceph/rados"
26+
librbd "github.com/ceph/go-ceph/rbd"
2627

2728
"github.com/ceph/ceph-csi/internal/journal"
2829
"github.com/ceph/ceph-csi/internal/util"
@@ -145,6 +146,12 @@ func (cvg *commonVolumeGroup) getVolumeGroupAttributes(ctx context.Context) (*jo
145146
attrs = &journal.VolumeGroupAttributes{}
146147
}
147148

149+
if attrs.GroupName == "" || attrs.CreationTime == nil {
150+
log.ErrorLog(ctx, "volume group with id %v not found", cvg.id)
151+
152+
return nil, librbd.ErrNotFound
153+
}
154+
148155
cvg.requestName = attrs.RequestName
149156
cvg.name = attrs.GroupName
150157
cvg.creationTime = attrs.CreationTime

internal/rbd/group/volume_group.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"fmt"
2323

2424
"github.com/ceph/go-ceph/rados"
25+
librados "github.com/ceph/go-ceph/rados"
2526
librbd "github.com/ceph/go-ceph/rbd"
2627
"github.com/container-storage-interface/spec/lib/go/csi"
2728
"github.com/csi-addons/spec/lib/go/volumegroup"
@@ -31,7 +32,10 @@ import (
3132
"github.com/ceph/ceph-csi/internal/util/log"
3233
)
3334

34-
var ErrRBDGroupNotConnected = errors.New("RBD group is not connected")
35+
var (
36+
ErrRBDGroupNotConnected = fmt.Errorf("%w: RBD group is not connected", librados.ErrNotConnected)
37+
ErrRBDGroupNotFound = fmt.Errorf("%w: RBD group not found", librbd.ErrNotFound)
38+
)
3539

3640
// volumeGroup handles all requests for 'rbd group' operations.
3741
type volumeGroup struct {

0 commit comments

Comments
 (0)