Skip to content

Commit

Permalink
rbd: use internal as default error code in getGRPCError()
Browse files Browse the repository at this point in the history
This commit replaces codes.Unknown with codes.Internal
as the default error code in getGRPCError().

Signed-off-by: Rakshith R <rar@redhat.com>
  • Loading branch information
Rakshith-R authored and mergify[bot] committed Jun 11, 2024
1 parent f8b9bc0 commit ec80175
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 43 deletions.
16 changes: 6 additions & 10 deletions internal/csi-addons/rbd/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,14 +776,10 @@ func getGRPCError(err error) error {
}

errorStatusMap := map[error]codes.Code{
corerbd.ErrFetchingLocalState: codes.Internal,
corerbd.ErrResyncImageFailed: codes.Internal,
corerbd.ErrDisableImageMirroringFailed: codes.Internal,
corerbd.ErrFetchingMirroringInfo: codes.Internal,
corerbd.ErrInvalidArgument: codes.InvalidArgument,
corerbd.ErrAborted: codes.Aborted,
corerbd.ErrFailedPrecondition: codes.FailedPrecondition,
corerbd.ErrUnavailable: codes.Unavailable,
corerbd.ErrInvalidArgument: codes.InvalidArgument,
corerbd.ErrAborted: codes.Aborted,
corerbd.ErrFailedPrecondition: codes.FailedPrecondition,
corerbd.ErrUnavailable: codes.Unavailable,
}

for e, code := range errorStatusMap {
Expand All @@ -792,8 +788,8 @@ func getGRPCError(err error) error {
}
}

// Handle any other non nil error not listed in the map
return status.Error(codes.Unknown, err.Error())
// Handle any other non nil error not listed in the map as internal error
return status.Error(codes.Internal, err.Error())
}

// GetVolumeReplicationInfo extracts the RBD volume information from the volumeID, If the
Expand Down
22 changes: 1 addition & 21 deletions internal/csi-addons/rbd/replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,26 +541,6 @@ func TestGetGRPCError(t *testing.T) {
err error
expectedErr error
}{
{
name: "FetchingLocalStateFailed",
err: corerbd.ErrFetchingLocalState,
expectedErr: status.Error(codes.Internal, corerbd.ErrFetchingLocalState.Error()),
},
{
name: "ResyncImageFailed",
err: corerbd.ErrResyncImageFailed,
expectedErr: status.Error(codes.Internal, corerbd.ErrResyncImageFailed.Error()),
},
{
name: "DisableImageMirroringFailed",
err: corerbd.ErrDisableImageMirroringFailed,
expectedErr: status.Error(codes.Internal, corerbd.ErrDisableImageMirroringFailed.Error()),
},
{
name: "FetchingMirroringInfoFailed",
err: corerbd.ErrFetchingMirroringInfo,
expectedErr: status.Error(codes.Internal, corerbd.ErrFetchingMirroringInfo.Error()),
},
{
name: "InvalidArgument",
err: corerbd.ErrInvalidArgument,
Expand All @@ -584,7 +564,7 @@ func TestGetGRPCError(t *testing.T) {
{
name: "InvalidError",
err: errors.New("some error"),
expectedErr: status.Error(codes.Unknown, "some error"),
expectedErr: status.Error(codes.Internal, "some error"),
},
{
name: "NilError",
Expand Down
8 changes: 0 additions & 8 deletions internal/rbd/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@ var (
ErrAborted = errors.New("operation got aborted")
// ErrInvalidArgument is returned when the client specified an invalid argument.
ErrInvalidArgument = errors.New("invalid arguments provided")
// ErrFetchingLocalState is returned when the operation to fetch local state fails.
ErrFetchingLocalState = errors.New("failed to get local state")
// ErrDisableImageMirroringFailed is returned when the operation to disable image mirroring fails.
ErrDisableImageMirroringFailed = errors.New("failed to disable image mirroring")
// ErrFetchingMirroringInfo is returned when the operation to fetch mirroring info of image fails.
ErrFetchingMirroringInfo = errors.New("failed to get mirroring info of image")
// ErrResyncImageFailed is returned when the operation to resync the image fails.
ErrResyncImageFailed = errors.New("failed to resync image")
// ErrImageInUse is returned when the image is in use.
ErrImageInUse = errors.New("image is in use")
)
8 changes: 4 additions & 4 deletions internal/rbd/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

func (rv *rbdVolume) ResyncVol(localStatus librbd.SiteMirrorImageStatus) error {
if err := rv.resyncImage(); err != nil {
return fmt.Errorf("%w: failed to resync image: %w", ErrResyncImageFailed, err)
return fmt.Errorf("failed to resync image: %w", err)
}

// If we issued a resync, return a non-final error as image needs to be recreated
Expand Down Expand Up @@ -73,7 +73,7 @@ func (rv *rbdVolume) DisableVolumeReplication(
// replication Kubernetes artifacts after failback operation.
localStatus, rErr := rv.GetLocalState()
if rErr != nil {
return fmt.Errorf("%w: %w", ErrFetchingLocalState, rErr)
return fmt.Errorf("failed to get local state: %w", rErr)
}
if localStatus.Up && localStatus.State == librbd.MirrorImageStatusStateReplaying {
return nil
Expand All @@ -84,13 +84,13 @@ func (rv *rbdVolume) DisableVolumeReplication(
}
err := rv.DisableImageMirroring(force)
if err != nil {
return fmt.Errorf("%w: %w", ErrDisableImageMirroringFailed, err)
return fmt.Errorf("failed to disable image mirroring: %w", err)
}
// the image state can be still disabling once we disable the mirroring
// check the mirroring is disabled or not
mirroringInfo, err = rv.GetImageMirroringInfo()
if err != nil {
return fmt.Errorf("%w: %w", ErrFetchingMirroringInfo, err)
return fmt.Errorf("failed to get mirroring info of image: %w", err)
}
if mirroringInfo.State == librbd.MirrorImageDisabling {
return fmt.Errorf("%w: %q is in disabling state", ErrAborted, rv.VolID)
Expand Down

0 comments on commit ec80175

Please sign in to comment.