mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
cleanup: move log functions to new internal/util/log package
Moving the log functions into its own internal/util/log package makes it possible to split out the humongous internal/util packages in further smaller pieces. This reduces the inter-dependencies between utility functions and components, preventing circular dependencies which are not allowed in Go. Updates: #852 Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
committed by
mergify[bot]
parent
2036b587d7
commit
6d00b39886
@ -21,6 +21,7 @@ import (
|
||||
"errors"
|
||||
|
||||
"github.com/ceph/ceph-csi/internal/util"
|
||||
"github.com/ceph/ceph-csi/internal/util/log"
|
||||
|
||||
"github.com/ceph/go-ceph/rados"
|
||||
)
|
||||
@ -74,7 +75,7 @@ func getOMapValues(
|
||||
|
||||
if err != nil {
|
||||
if errors.Is(err, rados.ErrNotFound) {
|
||||
util.ErrorLog(ctx, "omap not found (pool=%q, namespace=%q, name=%q): %v",
|
||||
log.ErrorLog(ctx, "omap not found (pool=%q, namespace=%q, name=%q): %v",
|
||||
poolName, namespace, oid, err)
|
||||
|
||||
return nil, util.JoinErrors(util.ErrKeyNotFound, err)
|
||||
@ -83,7 +84,7 @@ func getOMapValues(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
util.DebugLog(ctx, "got omap values: (pool=%q, namespace=%q, name=%q): %+v",
|
||||
log.DebugLog(ctx, "got omap values: (pool=%q, namespace=%q, name=%q): %+v",
|
||||
poolName, namespace, oid, results)
|
||||
|
||||
return results, nil
|
||||
@ -110,16 +111,16 @@ func removeMapKeys(
|
||||
// the previous implementation of removing omap keys (via the cli)
|
||||
// treated failure to find the omap as a non-error. Do so here to
|
||||
// mimic the previous behavior.
|
||||
util.DebugLog(ctx, "when removing omap keys, omap not found (pool=%q, namespace=%q, name=%q): %+v",
|
||||
log.DebugLog(ctx, "when removing omap keys, omap not found (pool=%q, namespace=%q, name=%q): %+v",
|
||||
poolName, namespace, oid, keys)
|
||||
} else {
|
||||
util.ErrorLog(ctx, "failed removing omap keys (pool=%q, namespace=%q, name=%q): %v",
|
||||
log.ErrorLog(ctx, "failed removing omap keys (pool=%q, namespace=%q, name=%q): %v",
|
||||
poolName, namespace, oid, err)
|
||||
|
||||
return err
|
||||
}
|
||||
}
|
||||
util.DebugLog(ctx, "removed omap keys (pool=%q, namespace=%q, name=%q): %+v",
|
||||
log.DebugLog(ctx, "removed omap keys (pool=%q, namespace=%q, name=%q): %+v",
|
||||
poolName, namespace, oid, keys)
|
||||
|
||||
return nil
|
||||
@ -146,12 +147,12 @@ func setOMapKeys(
|
||||
}
|
||||
err = ioctx.SetOmap(oid, bpairs)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed setting omap keys (pool=%q, namespace=%q, name=%q, pairs=%+v): %v",
|
||||
log.ErrorLog(ctx, "failed setting omap keys (pool=%q, namespace=%q, name=%q, pairs=%+v): %v",
|
||||
poolName, namespace, oid, pairs, err)
|
||||
|
||||
return err
|
||||
}
|
||||
util.DebugLog(ctx, "set omap keys (pool=%q, namespace=%q, name=%q): %+v)",
|
||||
log.DebugLog(ctx, "set omap keys (pool=%q, namespace=%q, name=%q): %+v)",
|
||||
poolName, namespace, oid, pairs)
|
||||
|
||||
return nil
|
||||
|
@ -25,6 +25,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/ceph/ceph-csi/internal/util"
|
||||
"github.com/ceph/ceph-csi/internal/util/log"
|
||||
|
||||
"github.com/pborman/uuid"
|
||||
)
|
||||
@ -437,7 +438,7 @@ func (conn *Connection) UndoReservation(ctx context.Context,
|
||||
cj.cephUUIDDirectoryPrefix+imageUUID)
|
||||
if err != nil {
|
||||
if !errors.Is(err, util.ErrObjectNotFound) {
|
||||
util.ErrorLog(ctx, "failed removing oMap %s (%s)", cj.cephUUIDDirectoryPrefix+imageUUID, err)
|
||||
log.ErrorLog(ctx, "failed removing oMap %s (%s)", cj.cephUUIDDirectoryPrefix+imageUUID, err)
|
||||
|
||||
return err
|
||||
}
|
||||
@ -448,7 +449,7 @@ func (conn *Connection) UndoReservation(ctx context.Context,
|
||||
err := removeMapKeys(ctx, conn, csiJournalPool, cj.namespace, cj.csiDirectory,
|
||||
[]string{cj.csiNameKeyPrefix + reqName})
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed removing oMap key %s (%s)", cj.csiNameKeyPrefix+reqName, err)
|
||||
log.ErrorLog(ctx, "failed removing oMap key %s (%s)", cj.csiNameKeyPrefix+reqName, err)
|
||||
|
||||
return err
|
||||
}
|
||||
@ -486,7 +487,7 @@ func reserveOMapName(
|
||||
if volUUID == "" && errors.Is(err, util.ErrObjectExists) {
|
||||
attempt++
|
||||
// try again with a different uuid, for maxAttempts tries
|
||||
util.DebugLog(ctx, "uuid (%s) conflict detected, retrying (attempt %d of %d)",
|
||||
log.DebugLog(ctx, "uuid (%s) conflict detected, retrying (attempt %d of %d)",
|
||||
iterUUID, attempt, maxAttempts)
|
||||
|
||||
continue
|
||||
@ -590,10 +591,10 @@ func (conn *Connection) ReserveName(ctx context.Context,
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
util.WarningLog(ctx, "reservation failed for volume: %s", reqName)
|
||||
log.WarningLog(ctx, "reservation failed for volume: %s", reqName)
|
||||
errDefer := conn.UndoReservation(ctx, imagePool, journalPool, imageName, reqName)
|
||||
if errDefer != nil {
|
||||
util.WarningLog(ctx, "failed undoing reservation of volume: %s (%v)", reqName, errDefer)
|
||||
log.WarningLog(ctx, "failed undoing reservation of volume: %s (%v)", reqName, errDefer)
|
||||
}
|
||||
}
|
||||
}()
|
||||
@ -686,7 +687,7 @@ func (conn *Connection) GetImageAttributes(
|
||||
if !errors.Is(err, util.ErrKeyNotFound) && !errors.Is(err, util.ErrPoolNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
util.WarningLog(ctx, "unable to read omap keys: pool or key missing: %v", err)
|
||||
log.WarningLog(ctx, "unable to read omap keys: pool or key missing: %v", err)
|
||||
}
|
||||
|
||||
var found bool
|
||||
|
Reference in New Issue
Block a user