util: return correct status code for VolumeGroupSnapshot

Fix status codes that are returned for Get/Delete RPC calls
for VolumeGroup/VolumeGroupSnapshot.

Signed-off-by: Nikhil-Ladha <nikhilladha1999@gmail.com>
This commit is contained in:
Nikhil-Ladha
2024-12-16 10:51:18 +05:30
committed by mergify[bot]
parent ca1ccdd9bf
commit 18a62ec9de
8 changed files with 62 additions and 13 deletions

View File

@ -18,11 +18,13 @@ package rbd
import (
"context"
"errors"
"github.com/container-storage-interface/spec/lib/go/csi"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/ceph/ceph-csi/internal/rbd/group"
"github.com/ceph/ceph-csi/internal/rbd/types"
"github.com/ceph/ceph-csi/internal/util"
"github.com/ceph/ceph-csi/internal/util/log"
@ -213,10 +215,17 @@ func (cs *ControllerServer) DeleteVolumeGroupSnapshot(
groupSnapshot, err := mgr.GetVolumeGroupSnapshotByID(ctx, groupSnapshotID)
if err != nil {
if errors.Is(err, group.ErrRBDGroupNotFound) {
log.ErrorLog(ctx, "VolumeGroupSnapshot %q doesn't exists", groupSnapshotID)
return &csi.DeleteVolumeGroupSnapshotResponse{}, nil
}
return nil, status.Errorf(
codes.Internal,
"failed to get volume group snapshot with id %q: %v",
groupSnapshotID, err)
"could not fetch volume group snapshot with id %q: %s",
groupSnapshotID,
err.Error())
}
defer groupSnapshot.Destroy(ctx)
@ -252,10 +261,20 @@ func (cs *ControllerServer) GetVolumeGroupSnapshot(
groupSnapshot, err := mgr.GetVolumeGroupSnapshotByID(ctx, groupSnapshotID)
if err != nil {
if errors.Is(err, group.ErrRBDGroupNotFound) {
log.ErrorLog(ctx, "VolumeGroupSnapshot %q doesn't exists", groupSnapshotID)
return nil, status.Errorf(
codes.NotFound,
"failed to get volume group snapshot with id %q: %v",
groupSnapshotID, err)
}
return nil, status.Errorf(
codes.Internal,
"failed to get volume group snapshot with id %q: %v",
groupSnapshotID, err)
"could not fetch volume group snapshot with id %q: %s",
groupSnapshotID,
err.Error())
}
defer groupSnapshot.Destroy(ctx)