mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-18 04:10:22 +00:00
cleanup: address err113 warnings about direct error comparisons
Several places in the code compared errors directly with the go-ceph sentinel errors. This change uses the errors.Is() function of go 1.13 instead. The err113 linter reported this issue as: err113: do not compare errors directly, use errors.Is() instead Signed-off-by: Sven Anderson <sven@redhat.com>
This commit is contained in:
parent
7affb9289d
commit
de74c36d8c
@ -18,6 +18,7 @@ package journal
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/ceph/ceph-csi/internal/util"
|
"github.com/ceph/ceph-csi/internal/util"
|
||||||
|
|
||||||
@ -60,14 +61,13 @@ func getOMapValues(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
switch err {
|
if err != nil {
|
||||||
case nil:
|
if errors.Is(err, rados.ErrNotFound) {
|
||||||
case rados.ErrNotFound:
|
|
||||||
klog.Errorf(
|
klog.Errorf(
|
||||||
util.Log(ctx, "omap not found (pool=%q, namespace=%q, name=%q): %v"),
|
util.Log(ctx, "omap not found (pool=%q, namespace=%q, name=%q): %v"),
|
||||||
poolName, namespace, oid, err)
|
poolName, namespace, oid, err)
|
||||||
return nil, util.NewErrKeyNotFound(oid, err)
|
return nil, util.NewErrKeyNotFound(oid, err)
|
||||||
default:
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,21 +93,21 @@ func removeMapKeys(
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = ioctx.RmOmapKeys(oid, keys)
|
err = ioctx.RmOmapKeys(oid, keys)
|
||||||
switch err {
|
if err != nil {
|
||||||
case nil:
|
if errors.Is(err, rados.ErrNotFound) {
|
||||||
case rados.ErrNotFound:
|
|
||||||
// the previous implementation of removing omap keys (via the cli)
|
// the previous implementation of removing omap keys (via the cli)
|
||||||
// treated failure to find the omap as a non-error. Do so here to
|
// treated failure to find the omap as a non-error. Do so here to
|
||||||
// mimic the previous behavior.
|
// mimic the previous behavior.
|
||||||
klog.V(4).Infof(
|
klog.V(4).Infof(
|
||||||
util.Log(ctx, "when removing omap keys, omap not found (pool=%q, namespace=%q, name=%q): %+v"),
|
util.Log(ctx, "when removing omap keys, omap not found (pool=%q, namespace=%q, name=%q): %+v"),
|
||||||
poolName, namespace, oid, keys)
|
poolName, namespace, oid, keys)
|
||||||
default:
|
} else {
|
||||||
klog.Errorf(
|
klog.Errorf(
|
||||||
util.Log(ctx, "failed removing omap keys (pool=%q, namespace=%q, name=%q): %v"),
|
util.Log(ctx, "failed removing omap keys (pool=%q, namespace=%q, name=%q): %v"),
|
||||||
poolName, namespace, oid, err)
|
poolName, namespace, oid, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
klog.V(4).Infof(
|
klog.V(4).Infof(
|
||||||
util.Log(ctx, "removed omap keys (pool=%q, namespace=%q, name=%q): %+v"),
|
util.Log(ctx, "removed omap keys (pool=%q, namespace=%q, name=%q): %+v"),
|
||||||
poolName, namespace, oid, keys)
|
poolName, namespace, oid, keys)
|
||||||
@ -147,7 +147,7 @@ func setOMapKeys(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func omapPoolError(poolName string, err error) error {
|
func omapPoolError(poolName string, err error) error {
|
||||||
if err == rados.ErrNotFound {
|
if errors.Is(err, rados.ErrNotFound) {
|
||||||
return util.NewErrPoolNotFound(poolName, err)
|
return util.NewErrPoolNotFound(poolName, err)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
@ -269,7 +269,7 @@ func (rv *rbdVolume) open() (*librbd.Image, error) {
|
|||||||
|
|
||||||
image, err := librbd.OpenImage(rv.ioctx, rv.RbdImageName, librbd.NoSnapshot)
|
image, err := librbd.OpenImage(rv.ioctx, rv.RbdImageName, librbd.NoSnapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == librbd.ErrNotFound {
|
if errors.Is(err, librbd.ErrNotFound) {
|
||||||
err = ErrImageNotFound{rv.RbdImageName, err}
|
err = ErrImageNotFound{rv.RbdImageName, err}
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -851,7 +851,7 @@ func (rv *rbdVolume) deleteSnapshot(ctx context.Context, pOpts *rbdSnapshot) err
|
|||||||
return fmt.Errorf("snapshot value is nil for %s", pOpts.RbdSnapName)
|
return fmt.Errorf("snapshot value is nil for %s", pOpts.RbdSnapName)
|
||||||
}
|
}
|
||||||
err = snap.Remove()
|
err = snap.Remove()
|
||||||
if err == librbd.ErrNotFound {
|
if errors.Is(err, librbd.ErrNotFound) {
|
||||||
return ErrSnapNotFound{snapName: pOpts.RbdSnapName, err: err}
|
return ErrSnapNotFound{snapName: pOpts.RbdSnapName, err: err}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
@ -63,7 +63,7 @@ func GetPoolID(monitors string, cr *Credentials, poolName string) (int64, error)
|
|||||||
defer connPool.Put(conn)
|
defer connPool.Put(conn)
|
||||||
|
|
||||||
id, err := conn.GetPoolByName(poolName)
|
id, err := conn.GetPoolByName(poolName)
|
||||||
if err == rados.ErrNotFound {
|
if errors.Is(err, rados.ErrNotFound) {
|
||||||
return InvalidPoolID, ErrPoolNotFound{poolName, fmt.Errorf("pool (%s) not found in Ceph cluster", poolName)}
|
return InvalidPoolID, ErrPoolNotFound{poolName, fmt.Errorf("pool (%s) not found in Ceph cluster", poolName)}
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return InvalidPoolID, err
|
return InvalidPoolID, err
|
||||||
@ -247,7 +247,7 @@ func CreateObject(ctx context.Context, monitors string, cr *Credentials, poolNam
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = ioctx.Create(objectName, rados.CreateExclusive)
|
err = ioctx.Create(objectName, rados.CreateExclusive)
|
||||||
if err == rados.ErrObjectExists {
|
if errors.Is(err, rados.ErrObjectExists) {
|
||||||
return ErrObjectExists{objectName, err}
|
return ErrObjectExists{objectName, err}
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
klog.Errorf(Log(ctx, "failed creating omap (%s) in pool (%s): (%v)"), objectName, poolName, err)
|
klog.Errorf(Log(ctx, "failed creating omap (%s) in pool (%s): (%v)"), objectName, poolName, err)
|
||||||
@ -282,7 +282,7 @@ func RemoveObject(ctx context.Context, monitors string, cr *Credentials, poolNam
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = ioctx.Delete(oMapName)
|
err = ioctx.Delete(oMapName)
|
||||||
if err == rados.ErrNotFound {
|
if errors.Is(err, rados.ErrNotFound) {
|
||||||
return ErrObjectNotFound{oMapName, err}
|
return ErrObjectNotFound{oMapName, err}
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
klog.Errorf(Log(ctx, "failed removing omap (%s) in pool (%s): (%v)"), oMapName, poolName, err)
|
klog.Errorf(Log(ctx, "failed removing omap (%s) in pool (%s): (%v)"), oMapName, poolName, err)
|
||||||
|
@ -73,7 +73,7 @@ func (cc *ClusterConnection) GetIoctx(pool string) (*rados.IOContext, error) {
|
|||||||
ioctx, err := cc.conn.OpenIOContext(pool)
|
ioctx, err := cc.conn.OpenIOContext(pool)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// ErrNotFound indicates the Pool was not found
|
// ErrNotFound indicates the Pool was not found
|
||||||
if err == rados.ErrNotFound {
|
if errors.Is(err, rados.ErrNotFound) {
|
||||||
err = ErrPoolNotFound{pool, err}
|
err = ErrPoolNotFound{pool, err}
|
||||||
} else {
|
} else {
|
||||||
err = fmt.Errorf("failed to open IOContext for pool %s: %w", pool, err)
|
err = fmt.Errorf("failed to open IOContext for pool %s: %w", pool, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user