Merge pull request #9016 from djdongjin/remove-most-logrus
Remove most logrus import
This commit is contained in:
@@ -24,7 +24,6 @@ import (
|
||||
|
||||
"github.com/containerd/containerd/cio"
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/containerd/containerd/pkg/cri/util"
|
||||
cioutil "github.com/containerd/containerd/pkg/ioutil"
|
||||
@@ -161,7 +160,7 @@ func (c *ContainerIO) Attach(opts AttachOptions) {
|
||||
c.stdin.Close()
|
||||
// Also closes the containerd side.
|
||||
if err := opts.CloseStdin(); err != nil {
|
||||
logrus.WithError(err).Errorf("Failed to close stdin for container %q", c.id)
|
||||
log.L.WithError(err).Errorf("Failed to close stdin for container %q", c.id)
|
||||
}
|
||||
} else {
|
||||
if opts.Stdout != nil {
|
||||
@@ -177,7 +176,7 @@ func (c *ContainerIO) Attach(opts AttachOptions) {
|
||||
|
||||
attachStream := func(key string, close <-chan struct{}) {
|
||||
<-close
|
||||
logrus.Infof("Attach stream %q closed", key)
|
||||
log.L.Infof("Attach stream %q closed", key)
|
||||
// Make sure stdin gets closed.
|
||||
if stdinStreamRC != nil {
|
||||
stdinStreamRC.Close()
|
||||
|
||||
@@ -23,9 +23,9 @@ import (
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||
|
||||
"github.com/containerd/containerd/log"
|
||||
cioutil "github.com/containerd/containerd/pkg/ioutil"
|
||||
)
|
||||
|
||||
@@ -51,7 +51,7 @@ func NewDiscardLogger() io.WriteCloser {
|
||||
// maxLen is the max length limit of a line. A line longer than the
|
||||
// limit will be cut into multiple lines.
|
||||
func NewCRILogger(path string, w io.Writer, stream StreamType, maxLen int) (io.WriteCloser, <-chan struct{}) {
|
||||
logrus.Debugf("Start writing stream %q to log file %q", stream, path)
|
||||
log.L.Debugf("Start writing stream %q to log file %q", stream, path)
|
||||
prc, pwc := io.Pipe()
|
||||
stop := make(chan struct{})
|
||||
go func() {
|
||||
@@ -147,7 +147,7 @@ func redirectLogs(path string, rc io.ReadCloser, w io.Writer, s StreamType, maxL
|
||||
outputEntries.Inc()
|
||||
outputBytes.Inc(float64(n))
|
||||
} else {
|
||||
logrus.WithError(err).Errorf("Fail to write %q log to log file %q", s, path)
|
||||
log.L.WithError(err).Errorf("Fail to write %q log to log file %q", s, path)
|
||||
// Continue on write error to drain the container output.
|
||||
}
|
||||
}
|
||||
@@ -167,9 +167,9 @@ func redirectLogs(path string, rc io.ReadCloser, w io.Writer, s StreamType, maxL
|
||||
}
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
logrus.Debugf("Getting EOF from stream %q while redirecting to log file %q", s, path)
|
||||
log.L.Debugf("Getting EOF from stream %q while redirecting to log file %q", s, path)
|
||||
} else {
|
||||
logrus.WithError(err).Errorf("An error occurred when redirecting stream %q to log file %q", s, path)
|
||||
log.L.WithError(err).Errorf("An error occurred when redirecting stream %q to log file %q", s, path)
|
||||
}
|
||||
if length == 0 {
|
||||
// No content left to write, break.
|
||||
@@ -209,5 +209,5 @@ func redirectLogs(path string, rc io.ReadCloser, w io.Writer, s StreamType, maxL
|
||||
break
|
||||
}
|
||||
}
|
||||
logrus.Debugf("Finish redirecting stream %q to log file %q", s, path)
|
||||
log.L.Debugf("Finish redirecting stream %q to log file %q", s, path)
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ import (
|
||||
"github.com/containerd/containerd/pkg/kmutex"
|
||||
"github.com/containerd/containerd/reference/docker"
|
||||
imagedigest "github.com/opencontainers/go-digest"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type CRIImageService struct {
|
||||
@@ -64,7 +63,7 @@ func NewService(config criconfig.Config, imageFSPath string, client *containerd.
|
||||
}
|
||||
|
||||
// Start snapshot stats syncer, it doesn't need to be stopped.
|
||||
logrus.Info("Start snapshots syncer")
|
||||
log.L.Info("Start snapshots syncer")
|
||||
snapshotsSyncer := newSnapshotsSyncer(
|
||||
svc.snapshotStore,
|
||||
svc.client.SnapshotService(svc.config.ContainerdConfig.Snapshotter),
|
||||
|
||||
@@ -33,7 +33,6 @@ import (
|
||||
ctrdutil "github.com/containerd/containerd/pkg/cri/util"
|
||||
"github.com/containerd/containerd/reference/docker"
|
||||
runtimespec "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
imagedigest "github.com/opencontainers/go-digest"
|
||||
)
|
||||
@@ -111,7 +110,7 @@ func buildLabels(configLabels, imageConfigLabels map[string]string, containerTyp
|
||||
} else {
|
||||
// In case the image label is invalid, we output a warning and skip adding it to the
|
||||
// container.
|
||||
logrus.WithError(err).Warnf("unable to add image label with key %s to the container", k)
|
||||
log.L.WithError(err).Warnf("unable to add image label with key %s to the container", k)
|
||||
}
|
||||
}
|
||||
// labels from the CRI request (config) will override labels in the image config
|
||||
|
||||
@@ -22,10 +22,9 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
eventtypes "github.com/containerd/containerd/api/events"
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/log"
|
||||
sandboxstore "github.com/containerd/containerd/pkg/cri/store/sandbox"
|
||||
ctrdutil "github.com/containerd/containerd/pkg/cri/util"
|
||||
"github.com/containerd/containerd/protobuf"
|
||||
@@ -98,7 +97,7 @@ func (c *Controller) stopSandboxContainer(ctx context.Context, sandbox sandboxst
|
||||
ExitStatus: exitStatus,
|
||||
ExitedAt: protobuf.ToTimestamp(exitedAt),
|
||||
}
|
||||
logrus.WithError(err).Errorf("Failed to wait sandbox exit %+v", e)
|
||||
log.G(ctx).WithError(err).Errorf("Failed to wait sandbox exit %+v", e)
|
||||
// TODO: how to backoff
|
||||
c.cri.BackOffEvent(id, e)
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ import (
|
||||
ctrdutil "github.com/containerd/containerd/pkg/cri/util"
|
||||
"github.com/containerd/containerd/protobuf"
|
||||
"github.com/containerd/typeurl/v2"
|
||||
"github.com/sirupsen/logrus"
|
||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||
"k8s.io/utils/clock"
|
||||
)
|
||||
@@ -264,18 +263,18 @@ func (em *eventMonitor) start() <-chan error {
|
||||
break
|
||||
}
|
||||
if em.backOff.isInBackOff(id) {
|
||||
logrus.Infof("Events for %q is in backoff, enqueue event %+v", id, evt)
|
||||
log.L.Infof("Events for %q is in backoff, enqueue event %+v", id, evt)
|
||||
em.backOff.enBackOff(id, evt)
|
||||
break
|
||||
}
|
||||
if err := em.handleEvent(evt); err != nil {
|
||||
logrus.WithError(err).Errorf("Failed to handle event %+v for %s", evt, id)
|
||||
log.L.WithError(err).Errorf("Failed to handle event %+v for %s", evt, id)
|
||||
em.backOff.enBackOff(id, evt)
|
||||
}
|
||||
case err := <-em.errCh:
|
||||
// Close errCh in defer directly if there is no error.
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("Failed to handle event stream")
|
||||
log.L.WithError(err).Error("Failed to handle event stream")
|
||||
errCh <- err
|
||||
}
|
||||
return
|
||||
@@ -285,7 +284,7 @@ func (em *eventMonitor) start() <-chan error {
|
||||
queue := em.backOff.deBackOff(id)
|
||||
for i, evt := range queue.events {
|
||||
if err := em.handleEvent(evt); err != nil {
|
||||
logrus.WithError(err).Errorf("Failed to handle backOff event %+v for %s", evt, id)
|
||||
log.L.WithError(err).Errorf("Failed to handle backOff event %+v for %s", evt, id)
|
||||
em.backOff.reBackOff(id, queue.events[i:], queue.duration)
|
||||
break
|
||||
}
|
||||
@@ -312,7 +311,7 @@ func (em *eventMonitor) handleEvent(any interface{}) error {
|
||||
|
||||
switch e := any.(type) {
|
||||
case *eventtypes.TaskExit:
|
||||
logrus.Infof("TaskExit event %+v", e)
|
||||
log.G(ctx).Infof("TaskExit event %+v", e)
|
||||
// Use ID instead of ContainerID to rule out TaskExit event for exec.
|
||||
cntr, err := em.c.containerStore.Get(e.ID)
|
||||
if err == nil {
|
||||
@@ -334,7 +333,7 @@ func (em *eventMonitor) handleEvent(any interface{}) error {
|
||||
}
|
||||
return nil
|
||||
case *eventtypes.TaskOOM:
|
||||
logrus.Infof("TaskOOM event %+v", e)
|
||||
log.G(ctx).Infof("TaskOOM event %+v", e)
|
||||
// For TaskOOM, we only care which container it belongs to.
|
||||
cntr, err := em.c.containerStore.Get(e.ContainerID)
|
||||
if err != nil {
|
||||
@@ -351,13 +350,13 @@ func (em *eventMonitor) handleEvent(any interface{}) error {
|
||||
return fmt.Errorf("failed to update container status for TaskOOM event: %w", err)
|
||||
}
|
||||
case *eventtypes.ImageCreate:
|
||||
logrus.Infof("ImageCreate event %+v", e)
|
||||
log.G(ctx).Infof("ImageCreate event %+v", e)
|
||||
return em.c.updateImage(ctx, e.Name)
|
||||
case *eventtypes.ImageUpdate:
|
||||
logrus.Infof("ImageUpdate event %+v", e)
|
||||
log.G(ctx).Infof("ImageUpdate event %+v", e)
|
||||
return em.c.updateImage(ctx, e.Name)
|
||||
case *eventtypes.ImageDelete:
|
||||
logrus.Infof("ImageDelete event %+v", e)
|
||||
log.G(ctx).Infof("ImageDelete event %+v", e)
|
||||
return em.c.updateImage(ctx, e.Name)
|
||||
}
|
||||
|
||||
@@ -436,7 +435,7 @@ func handleContainerExit(ctx context.Context, e *eventtypes.TaskExit, cntr conta
|
||||
return fmt.Errorf("failed to cleanup container %s in task-service: %w", cntr.Container.ID(), err)
|
||||
}
|
||||
}
|
||||
logrus.Infof("Ensure that container %s in task-service has been cleanup successfully", cntr.Container.ID())
|
||||
log.G(ctx).Infof("Ensure that container %s in task-service has been cleanup successfully", cntr.Container.ID())
|
||||
}
|
||||
|
||||
err = cntr.Status.UpdateSync(func(status containerstore.Status) (containerstore.Status, error) {
|
||||
@@ -449,7 +448,7 @@ func handleContainerExit(ctx context.Context, e *eventtypes.TaskExit, cntr conta
|
||||
// Unknown state can only transit to EXITED state, so we need
|
||||
// to handle unknown state here.
|
||||
if status.Unknown {
|
||||
logrus.Debugf("Container %q transited from UNKNOWN to EXITED", cntr.ID)
|
||||
log.G(ctx).Debugf("Container %q transited from UNKNOWN to EXITED", cntr.ID)
|
||||
status.Unknown = false
|
||||
}
|
||||
return status, nil
|
||||
@@ -522,7 +521,7 @@ func handleSandboxExit(ctx context.Context, e *eventtypes.TaskExit, sb sandboxst
|
||||
return fmt.Errorf("failed to cleanup sandbox %s in task-service: %w", sb.Container.ID(), err)
|
||||
}
|
||||
}
|
||||
logrus.Infof("Ensure that sandbox %s in task-service has been cleanup successfully", sb.Container.ID())
|
||||
log.G(ctx).Infof("Ensure that sandbox %s in task-service has been cleanup successfully", sb.Container.ID())
|
||||
}
|
||||
err = sb.Status.Update(func(status sandboxstore.Status) (sandboxstore.Status, error) {
|
||||
status.State = sandboxstore.StateNotReady
|
||||
|
||||
@@ -41,7 +41,6 @@ import (
|
||||
runcoptions "github.com/containerd/containerd/runtime/v2/runc/options"
|
||||
"github.com/containerd/typeurl/v2"
|
||||
runtimespec "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
runhcsoptions "github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/options"
|
||||
imagedigest "github.com/opencontainers/go-digest"
|
||||
@@ -519,7 +518,7 @@ func (c *criService) generateAndSendContainerEvent(ctx context.Context, containe
|
||||
}
|
||||
containerStatuses, err := c.getContainerStatuses(ctx, sandboxID)
|
||||
if err != nil {
|
||||
logrus.Errorf("Failed to get container statuses for container event for sandboxID %q: %v", sandboxID, err)
|
||||
log.G(ctx).Errorf("Failed to get container statuses for container event for sandboxID %q: %v", sandboxID, err)
|
||||
}
|
||||
|
||||
event := runtime.ContainerEventResponse{
|
||||
@@ -535,7 +534,7 @@ func (c *criService) generateAndSendContainerEvent(ctx context.Context, containe
|
||||
case c.containerEventsChan <- event:
|
||||
default:
|
||||
containerEventsDroppedCount.Inc()
|
||||
logrus.Debugf("containerEventsChan is full, discarding event %+v", event)
|
||||
log.G(ctx).Debugf("containerEventsChan is full, discarding event %+v", event)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ import (
|
||||
"github.com/containerd/containerd/pkg/kmutex"
|
||||
"github.com/containerd/containerd/plugin"
|
||||
cni "github.com/containerd/go-cni"
|
||||
"github.com/sirupsen/logrus"
|
||||
"google.golang.org/grpc"
|
||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||
|
||||
@@ -304,10 +303,10 @@ func (c *criService) Run(ready func()) error {
|
||||
// Close stops the CRI service.
|
||||
// TODO(random-liu): Make close synchronous.
|
||||
func (c *criService) Close() error {
|
||||
logrus.Info("Stop CRI service")
|
||||
log.L.Info("Stop CRI service")
|
||||
for name, h := range c.cniNetConfMonitor {
|
||||
if err := h.stop(); err != nil {
|
||||
logrus.WithError(err).Errorf("failed to stop cni network conf monitor for %s", name)
|
||||
log.L.WithError(err).Errorf("failed to stop cni network conf monitor for %s", name)
|
||||
}
|
||||
}
|
||||
c.eventMonitor.stop()
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/containerd/containerd/log"
|
||||
)
|
||||
|
||||
// SourceDateEpochEnv is the SOURCE_DATE_EPOCH env var.
|
||||
@@ -49,7 +49,7 @@ func SourceDateEpoch() (*time.Time, error) {
|
||||
func SourceDateEpochOrNow() time.Time {
|
||||
epoch, err := SourceDateEpoch()
|
||||
if err != nil {
|
||||
logrus.WithError(err).Warnf("Invalid %s", SourceDateEpochEnv)
|
||||
log.L.WithError(err).Warnf("Invalid %s", SourceDateEpochEnv)
|
||||
}
|
||||
if epoch != nil {
|
||||
return *epoch
|
||||
|
||||
@@ -25,7 +25,6 @@ import (
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/namespaces"
|
||||
nri "github.com/containerd/nri/pkg/adaptation"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Domain implements the functions the generic NRI interface needs to
|
||||
@@ -57,10 +56,10 @@ type Domain interface {
|
||||
func RegisterDomain(d Domain) {
|
||||
err := domains.add(d)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Fatalf("Failed to register namespace %q with NRI", d.GetName())
|
||||
log.L.WithError(err).Fatalf("Failed to register namespace %q with NRI", d.GetName())
|
||||
}
|
||||
|
||||
logrus.Infof("Registered namespace %q with NRI", d.GetName())
|
||||
log.L.Infof("Registered namespace %q with NRI", d.GetName())
|
||||
}
|
||||
|
||||
type domainTable struct {
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/containerd/containerd/version"
|
||||
nri "github.com/containerd/nri/pkg/adaptation"
|
||||
@@ -110,7 +109,7 @@ func New(cfg *Config) (API, error) {
|
||||
}
|
||||
|
||||
if cfg.Disable {
|
||||
logrus.Info("NRI interface is disabled by configuration.")
|
||||
log.L.Info("NRI interface is disabled by configuration.")
|
||||
return l, nil
|
||||
}
|
||||
|
||||
@@ -132,7 +131,7 @@ func New(cfg *Config) (API, error) {
|
||||
|
||||
l.state = make(map[string]State)
|
||||
|
||||
logrus.Info("created NRI interface")
|
||||
log.L.Info("created NRI interface")
|
||||
|
||||
return l, nil
|
||||
}
|
||||
|
||||
@@ -25,10 +25,10 @@ import (
|
||||
|
||||
"github.com/containerd/cgroups/v3/cgroup1"
|
||||
eventstypes "github.com/containerd/containerd/api/events"
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/pkg/oom"
|
||||
"github.com/containerd/containerd/runtime"
|
||||
"github.com/containerd/containerd/runtime/v2/shim"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
@@ -79,7 +79,7 @@ func (e *epoller) Run(ctx context.Context) {
|
||||
if err == unix.EINTR {
|
||||
continue
|
||||
}
|
||||
logrus.WithError(err).Error("cgroups: epoll wait")
|
||||
log.G(ctx).WithError(err).Error("cgroups: epoll wait")
|
||||
}
|
||||
for i := 0; i < n; i++ {
|
||||
e.process(ctx, uintptr(events[i].Fd))
|
||||
@@ -130,7 +130,7 @@ func (e *epoller) process(ctx context.Context, fd uintptr) {
|
||||
if err := e.publisher.Publish(ctx, runtime.TaskOOMEventTopic, &eventstypes.TaskOOM{
|
||||
ContainerID: i.id,
|
||||
}); err != nil {
|
||||
logrus.WithError(err).Error("publish OOM event")
|
||||
log.G(ctx).WithError(err).Error("publish OOM event")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,10 +24,10 @@ import (
|
||||
|
||||
cgroupsv2 "github.com/containerd/cgroups/v3/cgroup2"
|
||||
eventstypes "github.com/containerd/containerd/api/events"
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/pkg/oom"
|
||||
"github.com/containerd/containerd/runtime"
|
||||
"github.com/containerd/containerd/runtime/v2/shim"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// New returns an implementation that listens to OOM events
|
||||
@@ -74,7 +74,7 @@ func (w *watcher) Run(ctx context.Context) {
|
||||
if err := w.publisher.Publish(ctx, runtime.TaskOOMEventTopic, &eventstypes.TaskOOM{
|
||||
ContainerID: i.id,
|
||||
}); err != nil {
|
||||
logrus.WithError(err).Error("publish OOM event")
|
||||
log.G(ctx).WithError(err).Error("publish OOM event")
|
||||
}
|
||||
}
|
||||
if i.ev.OOMKill > 0 {
|
||||
@@ -106,7 +106,7 @@ func (w *watcher) Add(id string, cgx interface{}) error {
|
||||
i.err = err
|
||||
w.itemCh <- i
|
||||
// we no longer get any event/err when we got an err
|
||||
logrus.WithError(err).Warn("error from *cgroupsv2.Manager.EventChan")
|
||||
log.L.WithError(err).Warn("error from *cgroupsv2.Manager.EventChan")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/containerd/containerd/log"
|
||||
google_protobuf "github.com/containerd/containerd/protobuf/types"
|
||||
runc "github.com/containerd/go-runc"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type initState interface {
|
||||
@@ -341,7 +341,7 @@ func (s *pausedState) SetExited(status int) {
|
||||
s.p.setExited(status)
|
||||
|
||||
if err := s.p.runtime.Resume(context.Background(), s.p.id); err != nil {
|
||||
logrus.WithError(err).Error("resuming exited container from paused state")
|
||||
log.L.WithError(err).Error("resuming exited container from paused state")
|
||||
}
|
||||
|
||||
if err := s.transition("stopped"); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user