mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-14 02:10:21 +00:00
cephfs: simplify error handling
This change replaces the sentinel errors in cephfs module with standard errors created with errors.New(). Related: #1203 Signed-off-by: Sven Anderson <sven@redhat.com>
This commit is contained in:
parent
7c9c7c78a7
commit
dba2c27bcb
@ -184,8 +184,7 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
|
|||||||
}
|
}
|
||||||
|
|
||||||
// All errors other than ErrVolumeNotFound should return an error back to the caller
|
// All errors other than ErrVolumeNotFound should return an error back to the caller
|
||||||
var evnf ErrVolumeNotFound
|
if !errors.Is(err, ErrVolumeNotFound) {
|
||||||
if !errors.As(err, &evnf) {
|
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,8 +220,7 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
|
|||||||
if err = purgeVolume(ctx, volumeID(vID.FsSubvolName), cr, volOptions); err != nil {
|
if err = purgeVolume(ctx, volumeID(vID.FsSubvolName), cr, volOptions); err != nil {
|
||||||
klog.Errorf(util.Log(ctx, "failed to delete volume %s: %v"), volID, err)
|
klog.Errorf(util.Log(ctx, "failed to delete volume %s: %v"), volID, err)
|
||||||
// All errors other than ErrVolumeNotFound should return an error back to the caller
|
// All errors other than ErrVolumeNotFound should return an error back to the caller
|
||||||
var evnf ErrVolumeNotFound
|
if !errors.Is(err, ErrVolumeNotFound) {
|
||||||
if !errors.As(err, &evnf) {
|
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,49 +16,15 @@ limitations under the License.
|
|||||||
|
|
||||||
package cephfs
|
package cephfs
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
var (
|
||||||
// ErrInvalidVolID is returned when a CSI passed VolumeID is not conformant to any known volume ID
|
// ErrInvalidVolID is returned when a CSI passed VolumeID is not conformant to any known volume ID
|
||||||
// formats.
|
// formats.
|
||||||
type ErrInvalidVolID struct {
|
ErrInvalidVolID = errors.New("invalid VolumeID")
|
||||||
err error
|
|
||||||
}
|
|
||||||
|
|
||||||
// Error returns a user presentable string of the error.
|
|
||||||
func (e ErrInvalidVolID) Error() string {
|
|
||||||
return e.err.Error()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unwrap returns the encapsulated error of ErrInvalidVolID.
|
|
||||||
func (e ErrInvalidVolID) Unwrap() error {
|
|
||||||
return e.err
|
|
||||||
}
|
|
||||||
|
|
||||||
// ErrNonStaticVolume is returned when a volume is detected as not being
|
// ErrNonStaticVolume is returned when a volume is detected as not being
|
||||||
// statically provisioned.
|
// statically provisioned.
|
||||||
type ErrNonStaticVolume struct {
|
ErrNonStaticVolume = errors.New("volume not static")
|
||||||
err error
|
|
||||||
}
|
|
||||||
|
|
||||||
// Error returns a user presentable string of the error.
|
|
||||||
func (e ErrNonStaticVolume) Error() string {
|
|
||||||
return e.err.Error()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unwrap returns the encapsulated error of ErrNonStaticVolume.
|
|
||||||
func (e ErrNonStaticVolume) Unwrap() error {
|
|
||||||
return e.err
|
|
||||||
}
|
|
||||||
|
|
||||||
// ErrVolumeNotFound is returned when a subvolume is not found in CephFS.
|
// ErrVolumeNotFound is returned when a subvolume is not found in CephFS.
|
||||||
type ErrVolumeNotFound struct {
|
ErrVolumeNotFound = errors.New("volume not found")
|
||||||
err error
|
)
|
||||||
}
|
|
||||||
|
|
||||||
// Error returns a user presentable string of the error.
|
|
||||||
func (e ErrVolumeNotFound) Error() string {
|
|
||||||
return e.err.Error()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unwrap returns the encapsulated error of ErrVolumeNotFound.
|
|
||||||
func (e ErrVolumeNotFound) Unwrap() error {
|
|
||||||
return e.err
|
|
||||||
}
|
|
||||||
|
@ -72,8 +72,7 @@ func checkVolExists(ctx context.Context, volOptions *volumeOptions, secret map[s
|
|||||||
|
|
||||||
_, err = getVolumeRootPathCeph(ctx, volOptions, cr, volumeID(vid.FsSubvolName))
|
_, err = getVolumeRootPathCeph(ctx, volOptions, cr, volumeID(vid.FsSubvolName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var evnf ErrVolumeNotFound
|
if errors.Is(err, ErrVolumeNotFound) {
|
||||||
if errors.As(err, &evnf) {
|
|
||||||
err = j.UndoReservation(ctx, volOptions.MetadataPool,
|
err = j.UndoReservation(ctx, volOptions.MetadataPool,
|
||||||
volOptions.MetadataPool, vid.FsSubvolName, volOptions.RequestName)
|
volOptions.MetadataPool, vid.FsSubvolName, volOptions.RequestName)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -89,16 +89,14 @@ func (ns *NodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
|
|||||||
|
|
||||||
volOptions, _, err := newVolumeOptionsFromVolID(ctx, string(volID), req.GetVolumeContext(), req.GetSecrets())
|
volOptions, _, err := newVolumeOptionsFromVolID(ctx, string(volID), req.GetVolumeContext(), req.GetSecrets())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var eivi ErrInvalidVolID
|
if !errors.Is(err, ErrInvalidVolID) {
|
||||||
if !errors.As(err, &eivi) {
|
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// gets mon IPs from the supplied cluster info
|
// gets mon IPs from the supplied cluster info
|
||||||
volOptions, _, err = newVolumeOptionsFromStaticVolume(string(volID), req.GetVolumeContext())
|
volOptions, _, err = newVolumeOptionsFromStaticVolume(string(volID), req.GetVolumeContext())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var ensv ErrNonStaticVolume
|
if !errors.Is(err, ErrNonStaticVolume) {
|
||||||
if !errors.As(err, &ensv) {
|
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ func getVolumeRootPathCeph(ctx context.Context, volOptions *volumeOptions, cr *u
|
|||||||
klog.Errorf(util.Log(ctx, "failed to get the rootpath for the vol %s(%s) stdError %s"), string(volID), err, stdErrString)
|
klog.Errorf(util.Log(ctx, "failed to get the rootpath for the vol %s(%s) stdError %s"), string(volID), err, stdErrString)
|
||||||
|
|
||||||
if strings.HasPrefix(stdErrString, errNotFoundString) {
|
if strings.HasPrefix(stdErrString, errNotFoundString) {
|
||||||
return "", ErrVolumeNotFound{err}
|
return "", util.JoinErrors(ErrVolumeNotFound, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return "", err
|
return "", err
|
||||||
@ -215,7 +215,7 @@ func purgeVolume(ctx context.Context, volID volumeID, cr *util.Credentials, volO
|
|||||||
klog.Errorf(util.Log(ctx, "failed to purge subvolume %s(%s) in fs %s"), string(volID), err, volOptions.FsName)
|
klog.Errorf(util.Log(ctx, "failed to purge subvolume %s(%s) in fs %s"), string(volID), err, volOptions.FsName)
|
||||||
|
|
||||||
if strings.HasPrefix(err.Error(), errNotFoundString) {
|
if strings.HasPrefix(err.Error(), errNotFoundString) {
|
||||||
return ErrVolumeNotFound{err}
|
return util.JoinErrors(ErrVolumeNotFound, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
@ -230,8 +230,8 @@ func newVolumeOptionsFromVolID(ctx context.Context, volID string, volOpt, secret
|
|||||||
// before other errors
|
// before other errors
|
||||||
err := vi.DecomposeCSIID(volID)
|
err := vi.DecomposeCSIID(volID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("error decoding volume ID (%s) (%s)", err, volID)
|
err = fmt.Errorf("error decoding volume ID (%s): %w", volID, err)
|
||||||
return nil, nil, ErrInvalidVolID{err}
|
return nil, nil, util.JoinErrors(ErrInvalidVolID, err)
|
||||||
}
|
}
|
||||||
volOptions.ClusterID = vi.ClusterID
|
volOptions.ClusterID = vi.ClusterID
|
||||||
vid.VolumeID = volID
|
vid.VolumeID = volID
|
||||||
@ -372,7 +372,7 @@ func newVolumeOptionsFromStaticVolume(volID string, options map[string]string) (
|
|||||||
|
|
||||||
val, ok := options["staticVolume"]
|
val, ok := options["staticVolume"]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, nil, ErrNonStaticVolume{err}
|
return nil, nil, ErrNonStaticVolume
|
||||||
}
|
}
|
||||||
|
|
||||||
if staticVol, err = strconv.ParseBool(val); err != nil {
|
if staticVol, err = strconv.ParseBool(val); err != nil {
|
||||||
@ -380,7 +380,7 @@ func newVolumeOptionsFromStaticVolume(volID string, options map[string]string) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !staticVol {
|
if !staticVol {
|
||||||
return nil, nil, ErrNonStaticVolume{err}
|
return nil, nil, ErrNonStaticVolume
|
||||||
}
|
}
|
||||||
|
|
||||||
// Volume is static, and ProvisionVolume carries bool stating if it was provisioned, hence
|
// Volume is static, and ProvisionVolume carries bool stating if it was provisioned, hence
|
||||||
|
Loading…
Reference in New Issue
Block a user