From 6f34da5f80f8e56ec6b0449a163af5d5096af50a Mon Sep 17 00:00:00 2001 From: Maksym Pavlenko Date: Fri, 5 May 2023 11:54:14 -0700 Subject: [PATCH] Cleanup logrus imports Signed-off-by: Maksym Pavlenko --- cmd/containerd-stress/cri_worker.go | 9 +++-- cmd/containerd-stress/density.go | 6 ++-- cmd/containerd-stress/exec_worker.go | 20 ++++++------ cmd/containerd-stress/main.go | 26 ++++++++------- cmd/containerd-stress/size.go | 6 ++-- cmd/containerd-stress/worker.go | 8 ++--- cmd/containerd/command/main_windows.go | 8 ++--- cmd/ctr/commands/containers/restore.go | 4 +-- cmd/ctr/commands/run/run.go | 8 ++--- cmd/ctr/commands/run/run_windows.go | 4 +-- cmd/ctr/commands/shim/shim.go | 4 +-- cmd/ctr/commands/signals.go | 10 +++--- cmd/ctr/commands/tasks/attach.go | 4 +-- cmd/ctr/commands/tasks/exec.go | 4 +-- cmd/ctr/commands/tasks/kill.go | 4 +-- cmd/ctr/commands/tasks/start.go | 4 +-- diff/stream_windows.go | 9 ++--- images/diffid.go | 9 ++--- metrics/cgroups/v1/cgroups.go | 3 +- pkg/cri/io/container_io.go | 13 ++++---- pkg/cri/io/exec_io.go | 13 ++++---- pkg/cri/opts/spec_linux.go | 5 ++- pkg/cri/opts/spec_linux_opts.go | 3 +- pkg/cri/sbserver/blockio_linux.go | 5 ++- pkg/cri/sbserver/cni_conf_syncer.go | 14 ++++---- pkg/cri/sbserver/container_remove.go | 3 +- pkg/cri/sbserver/container_start.go | 3 +- pkg/cri/sbserver/events.go | 40 +++++++++++------------ pkg/cri/sbserver/helpers.go | 17 +++++----- pkg/cri/sbserver/images/snapshots.go | 9 +++-- pkg/cri/sbserver/podsandbox/controller.go | 8 ++--- pkg/cri/sbserver/rdt.go | 5 ++- pkg/cri/sbserver/sandbox_remove.go | 3 +- pkg/cri/sbserver/sandbox_run.go | 3 +- pkg/cri/sbserver/service.go | 24 +++++++------- pkg/cri/sbserver/service_linux.go | 9 ++--- pkg/cri/server/blockio_linux.go | 5 ++- pkg/cri/server/cni_conf_syncer.go | 14 ++++---- pkg/cri/server/container_remove.go | 3 +- pkg/cri/server/container_start.go | 3 +- pkg/cri/server/events.go | 19 ++++++----- pkg/cri/server/helpers.go | 5 +-- pkg/cri/server/rdt_linux.go | 5 ++- pkg/cri/server/sandbox_remove.go | 3 +- pkg/cri/server/sandbox_run.go | 3 +- pkg/cri/server/service.go | 21 ++++++------ pkg/cri/server/service_linux.go | 6 ++-- pkg/cri/server/snapshots.go | 9 +++-- runtime/v2/runc/container.go | 16 ++++----- runtime/v2/runc/pause/sandbox.go | 12 +++---- runtime/v2/runc/task/service.go | 16 ++++----- runtime/v2/shim/publisher.go | 6 ++-- snapshots/btrfs/btrfs.go | 8 ++--- snapshots/devmapper/pool_device_test.go | 4 +-- 54 files changed, 237 insertions(+), 248 deletions(-) diff --git a/cmd/containerd-stress/cri_worker.go b/cmd/containerd-stress/cri_worker.go index 64fb6814e..99c5fbeac 100644 --- a/cmd/containerd-stress/cri_worker.go +++ b/cmd/containerd-stress/cri_worker.go @@ -23,9 +23,8 @@ import ( "sync" "time" - "github.com/sirupsen/logrus" - internalapi "github.com/containerd/containerd/integration/cri-api/pkg/apis" + "github.com/containerd/containerd/log" "github.com/containerd/containerd/pkg/cri/util" runtime "k8s.io/cri-api/pkg/apis/runtime/v1" ) @@ -63,7 +62,7 @@ func (w *criWorker) getFailures() int { func (w *criWorker) run(ctx, tctx context.Context) { defer func() { w.wg.Done() - logrus.Infof("worker %d finished", w.id) + log.L.Infof("worker %d finished", w.id) }() for { select { @@ -74,13 +73,13 @@ func (w *criWorker) run(ctx, tctx context.Context) { w.count++ id := w.getID() - logrus.Debugf("starting container %s", id) + log.L.Debugf("starting container %s", id) start := time.Now() if err := w.runSandbox(tctx, ctx, id); err != nil { if err != context.DeadlineExceeded || !strings.Contains(err.Error(), context.DeadlineExceeded.Error()) { w.failures++ - logrus.WithError(err).Errorf("running container %s", id) + log.L.WithError(err).Errorf("running container %s", id) errCounter.WithValues(err.Error()).Inc() } diff --git a/cmd/containerd-stress/density.go b/cmd/containerd-stress/density.go index 756892917..757b02471 100644 --- a/cmd/containerd-stress/density.go +++ b/cmd/containerd-stress/density.go @@ -31,9 +31,9 @@ import ( "github.com/containerd/containerd" "github.com/containerd/containerd/cio" + "github.com/containerd/containerd/log" "github.com/containerd/containerd/namespaces" "github.com/containerd/containerd/oci" - "github.com/sirupsen/logrus" "github.com/urfave/cli" ) @@ -76,12 +76,12 @@ var densityCommand = cli.Command{ if err := cleanup(ctx, client); err != nil { return err } - logrus.Infof("pulling %s", config.Image) + log.L.Infof("pulling %s", config.Image) image, err := client.Pull(ctx, config.Image, containerd.WithPullUnpack, containerd.WithPullSnapshotter(config.Snapshotter)) if err != nil { return err } - logrus.Info("generating spec from image") + log.L.Info("generating spec from image") s := make(chan os.Signal, 1) signal.Notify(s, syscall.SIGTERM, syscall.SIGINT) diff --git a/cmd/containerd-stress/exec_worker.go b/cmd/containerd-stress/exec_worker.go index 66aaa4267..0980b14c0 100644 --- a/cmd/containerd-stress/exec_worker.go +++ b/cmd/containerd-stress/exec_worker.go @@ -25,9 +25,9 @@ import ( "github.com/containerd/containerd" "github.com/containerd/containerd/cio" + "github.com/containerd/containerd/log" "github.com/containerd/containerd/oci" specs "github.com/opencontainers/runtime-spec/specs-go" - "github.com/sirupsen/logrus" ) type execWorker struct { @@ -37,7 +37,7 @@ type execWorker struct { func (w *execWorker) exec(ctx, tctx context.Context) { defer func() { w.wg.Done() - logrus.Infof("worker %d finished", w.id) + log.L.Infof("worker %d finished", w.id) }() id := fmt.Sprintf("exec-container-%d", w.id) c, err := w.client.NewContainer(ctx, id, @@ -46,32 +46,32 @@ func (w *execWorker) exec(ctx, tctx context.Context) { containerd.WithNewSpec(oci.WithImageConfig(w.image), oci.WithUsername("games"), oci.WithProcessArgs("sleep", "30d")), ) if err != nil { - logrus.WithError(err).Error("create exec container") + log.L.WithError(err).Error("create exec container") return } defer c.Delete(ctx, containerd.WithSnapshotCleanup) task, err := c.NewTask(ctx, cio.NullIO) if err != nil { - logrus.WithError(err).Error("create exec container's task") + log.L.WithError(err).Error("create exec container's task") return } defer task.Delete(ctx, containerd.WithProcessKill) statusC, err := task.Wait(ctx) if err != nil { - logrus.WithError(err).Error("wait exec container's task") + log.L.WithError(err).Error("wait exec container's task") return } if err := task.Start(ctx); err != nil { - logrus.WithError(err).Error("exec container start failure") + log.L.WithError(err).Error("exec container start failure") return } spec, err := c.Spec(ctx) if err != nil { - logrus.WithError(err).Error("failed to get spec") + log.L.WithError(err).Error("failed to get spec") return } @@ -82,7 +82,7 @@ func (w *execWorker) exec(ctx, tctx context.Context) { select { case <-tctx.Done(): if err := task.Kill(ctx, syscall.SIGKILL); err != nil { - logrus.WithError(err).Error("kill exec container's task") + log.L.WithError(err).Error("kill exec container's task") } <-statusC return @@ -91,14 +91,14 @@ func (w *execWorker) exec(ctx, tctx context.Context) { w.count++ id := w.getID() - logrus.Debugf("starting exec %s", id) + log.L.Debugf("starting exec %s", id) start := time.Now() if err := w.runExec(ctx, task, id, pspec); err != nil { if err != context.DeadlineExceeded || !strings.Contains(err.Error(), context.DeadlineExceeded.Error()) { w.failures++ - logrus.WithError(err).Errorf("running exec %s", id) + log.L.WithError(err).Errorf("running exec %s", id) errCounter.WithValues(err.Error()).Inc() } continue diff --git a/cmd/containerd-stress/main.go b/cmd/containerd-stress/main.go index f02fad73c..e8ae9c8db 100644 --- a/cmd/containerd-stress/main.go +++ b/cmd/containerd-stress/main.go @@ -30,10 +30,10 @@ import ( "github.com/containerd/containerd" "github.com/containerd/containerd/integration/remote" + "github.com/containerd/containerd/log" "github.com/containerd/containerd/namespaces" "github.com/containerd/containerd/plugin" metrics "github.com/docker/go-metrics" - "github.com/sirupsen/logrus" "github.com/urfave/cli" ) @@ -177,10 +177,14 @@ func main() { } app.Before = func(context *cli.Context) error { if context.GlobalBool("json") { - logrus.SetLevel(logrus.WarnLevel) + if err := log.SetLevel("warn"); err != nil { + return err + } } if context.GlobalBool("debug") { - logrus.SetLevel(logrus.DebugLevel) + if err := log.SetLevel("debug"); err != nil { + return err + } } return nil } @@ -241,7 +245,7 @@ func serve(c config) error { ReadHeaderTimeout: 5 * time.Minute, // "G112: Potential Slowloris Attack (gosec)"; not a real concern for our use, so setting a long timeout. } if err := srv.ListenAndServe(); err != nil { - logrus.WithError(err).Error("listen and serve") + log.L.WithError(err).Error("listen and serve") } }() checkBinarySizes() @@ -287,7 +291,7 @@ func criTest(c config) error { workers []worker r = &run{} ) - logrus.Info("starting stress test run...") + log.L.Info("starting stress test run...") // create the workers along with their spec for i := 0; i < c.Concurrency; i++ { wg.Add(1) @@ -312,9 +316,9 @@ func criTest(c config) error { r.end() results := r.gather(workers) - logrus.Infof("ending test run in %0.3f seconds", results.Seconds) + log.L.Infof("ending test run in %0.3f seconds", results.Seconds) - logrus.WithField("failures", r.failures).Infof( + log.L.WithField("failures", r.failures).Infof( "create/start/delete %d containers in %0.3f seconds (%0.3f c/sec) or (%0.3f sec/c)", results.Total, results.Seconds, @@ -345,7 +349,7 @@ func test(c config) error { return err } - logrus.Infof("pulling %s", c.Image) + log.L.Infof("pulling %s", c.Image) image, err := client.Pull(ctx, c.Image, containerd.WithPullUnpack, containerd.WithPullSnapshotter(c.Snapshotter)) if err != nil { return err @@ -367,7 +371,7 @@ func test(c config) error { workers []worker r = &run{} ) - logrus.Info("starting stress test run...") + log.L.Info("starting stress test run...") // create the workers along with their spec for i := 0; i < c.Concurrency; i++ { wg.Add(1) @@ -414,9 +418,9 @@ func test(c config) error { results.ExecTotal = exec.count results.ExecFailures = exec.failures } - logrus.Infof("ending test run in %0.3f seconds", results.Seconds) + log.L.Infof("ending test run in %0.3f seconds", results.Seconds) - logrus.WithField("failures", r.failures).Infof( + log.L.WithField("failures", r.failures).Infof( "create/start/delete %d containers in %0.3f seconds (%0.3f c/sec) or (%0.3f sec/c)", results.Total, results.Seconds, diff --git a/cmd/containerd-stress/size.go b/cmd/containerd-stress/size.go index abc54e575..02908a864 100644 --- a/cmd/containerd-stress/size.go +++ b/cmd/containerd-stress/size.go @@ -19,7 +19,7 @@ package main import ( "os" - "github.com/sirupsen/logrus" + "github.com/containerd/containerd/log" ) const defaultPath = "/usr/local/bin/" @@ -37,12 +37,12 @@ func checkBinarySizes() { for _, name := range binaries { fi, err := os.Stat(name) if err != nil { - logrus.WithError(err).Error("stat binary") + log.L.WithError(err).Error("stat binary") continue } if fi.IsDir() { - logrus.Error(name, "is not a file") + log.L.Error(name, "is not a file") continue } diff --git a/cmd/containerd-stress/worker.go b/cmd/containerd-stress/worker.go index 69be22ce7..d8bf742b9 100644 --- a/cmd/containerd-stress/worker.go +++ b/cmd/containerd-stress/worker.go @@ -25,8 +25,8 @@ import ( "github.com/containerd/containerd" "github.com/containerd/containerd/cio" + "github.com/containerd/containerd/log" "github.com/containerd/containerd/oci" - "github.com/sirupsen/logrus" ) type ctrWorker struct { @@ -44,7 +44,7 @@ type ctrWorker struct { func (w *ctrWorker) run(ctx, tctx context.Context) { defer func() { w.wg.Done() - logrus.Infof("worker %d finished", w.id) + log.L.Infof("worker %d finished", w.id) }() for { select { @@ -55,13 +55,13 @@ func (w *ctrWorker) run(ctx, tctx context.Context) { w.count++ id := w.getID() - logrus.Debugf("starting container %s", id) + log.L.Debugf("starting container %s", id) start := time.Now() if err := w.runContainer(ctx, id); err != nil { if err != context.DeadlineExceeded || !strings.Contains(err.Error(), context.DeadlineExceeded.Error()) { w.failures++ - logrus.WithError(err).Errorf("running container %s", id) + log.L.WithError(err).Errorf("running container %s", id) errCounter.WithValues(err.Error()).Inc() } diff --git a/cmd/containerd/command/main_windows.go b/cmd/containerd/command/main_windows.go index 602703527..757fc600d 100644 --- a/cmd/containerd/command/main_windows.go +++ b/cmd/containerd/command/main_windows.go @@ -75,7 +75,7 @@ func setupDumpStacks() { ev, _ := windows.UTF16PtrFromString(event) sd, err := windows.SecurityDescriptorFromString("D:P(A;;GA;;;BA)(A;;GA;;;SY)") if err != nil { - logrus.Errorf("failed to get security descriptor for debug stackdump event %s: %s", event, err.Error()) + log.L.Errorf("failed to get security descriptor for debug stackdump event %s: %s", event, err.Error()) return } var sa windows.SecurityAttributes @@ -84,11 +84,11 @@ func setupDumpStacks() { sa.SecurityDescriptor = sd h, err := windows.CreateEvent(&sa, 0, 0, ev) if h == 0 || err != nil { - logrus.Errorf("failed to create debug stackdump event %s: %s", event, err.Error()) + log.L.Errorf("failed to create debug stackdump event %s: %s", event, err.Error()) return } go func() { - logrus.Debugf("Stackdump - waiting signal at %s", event) + log.L.Debugf("Stackdump - waiting signal at %s", event) for { windows.WaitForSingleObject(h, windows.INFINITE) dumpStacks(true) @@ -109,7 +109,7 @@ func init() { // Microsoft/go-winio/tools/etw-provider-gen. provider, err := etw.NewProvider("ContainerD", etwCallback) if err != nil { - logrus.Error(err) + log.L.Error(err) } else { if hook, err := etwlogrus.NewHookFromProvider(provider); err == nil { logrus.AddHook(hook) diff --git a/cmd/ctr/commands/containers/restore.go b/cmd/ctr/commands/containers/restore.go index d4bd5a4da..e3c011dd7 100644 --- a/cmd/ctr/commands/containers/restore.go +++ b/cmd/ctr/commands/containers/restore.go @@ -25,7 +25,7 @@ import ( "github.com/containerd/containerd/cmd/ctr/commands" "github.com/containerd/containerd/cmd/ctr/commands/tasks" "github.com/containerd/containerd/errdefs" - "github.com/sirupsen/logrus" + "github.com/containerd/containerd/log" "github.com/urfave/cli" ) @@ -124,7 +124,7 @@ var restoreCommand = cli.Command{ } if err := tasks.HandleConsoleResize(ctx, task, con); err != nil { - logrus.WithError(err).Error("console resize") + log.G(ctx).WithError(err).Error("console resize") } status := <-statusC diff --git a/cmd/ctr/commands/run/run.go b/cmd/ctr/commands/run/run.go index c6833aeb7..9a71bb613 100644 --- a/cmd/ctr/commands/run/run.go +++ b/cmd/ctr/commands/run/run.go @@ -30,10 +30,10 @@ import ( "github.com/containerd/containerd/cmd/ctr/commands/tasks" "github.com/containerd/containerd/containers" clabels "github.com/containerd/containerd/labels" + "github.com/containerd/containerd/log" "github.com/containerd/containerd/oci" gocni "github.com/containerd/go-cni" specs "github.com/opencontainers/runtime-spec/specs-go" - "github.com/sirupsen/logrus" "github.com/urfave/cli" ) @@ -199,7 +199,7 @@ var Command = cli.Command{ defer func() { if enableCNI { if err := network.Remove(ctx, commands.FullID(ctx, container), ""); err != nil { - logrus.WithError(err).Error("network review") + log.L.WithError(err).Error("network review") } } task.Delete(ctx) @@ -232,7 +232,7 @@ var Command = cli.Command{ } if tty { if err := tasks.HandleConsoleResize(ctx, task, con); err != nil { - logrus.WithError(err).Error("console resize") + log.L.WithError(err).Error("console resize") } } else { sigc := commands.ForwardAllSignals(ctx, task) @@ -262,7 +262,7 @@ func buildLabels(cmdLabels, imageLabels map[string]string) map[string]string { } 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 command line will override image and the initial image config labels diff --git a/cmd/ctr/commands/run/run_windows.go b/cmd/ctr/commands/run/run_windows.go index 09353a209..b6a8a96dc 100644 --- a/cmd/ctr/commands/run/run_windows.go +++ b/cmd/ctr/commands/run/run_windows.go @@ -25,11 +25,11 @@ import ( "github.com/containerd/console" "github.com/containerd/containerd" "github.com/containerd/containerd/cmd/ctr/commands" + "github.com/containerd/containerd/log" "github.com/containerd/containerd/oci" "github.com/containerd/containerd/pkg/netns" "github.com/containerd/containerd/snapshots" specs "github.com/opencontainers/runtime-spec/specs-go" - "github.com/sirupsen/logrus" "github.com/urfave/cli" ) @@ -122,7 +122,7 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli con := console.Current() size, err := con.Size() if err != nil { - logrus.WithError(err).Error("console size") + log.L.WithError(err).Error("console size") } opts = append(opts, oci.WithTTYSize(int(size.Width), int(size.Height))) } diff --git a/cmd/ctr/commands/shim/shim.go b/cmd/ctr/commands/shim/shim.go index dfbb1f255..a49007650 100644 --- a/cmd/ctr/commands/shim/shim.go +++ b/cmd/ctr/commands/shim/shim.go @@ -30,13 +30,13 @@ import ( "github.com/containerd/console" "github.com/containerd/containerd/api/runtime/task/v2" "github.com/containerd/containerd/cmd/ctr/commands" + "github.com/containerd/containerd/log" "github.com/containerd/containerd/namespaces" ptypes "github.com/containerd/containerd/protobuf/types" "github.com/containerd/containerd/runtime/v2/shim" "github.com/containerd/ttrpc" "github.com/containerd/typeurl/v2" "github.com/opencontainers/runtime-spec/specs-go" - "github.com/sirupsen/logrus" "github.com/urfave/cli" ) @@ -204,7 +204,7 @@ var execCommand = cli.Command{ } fmt.Printf("exec running with pid %d\n", r.Pid) if context.Bool("attach") { - logrus.Info("attaching") + log.L.Info("attaching") if tty { current := console.Current() defer current.Reset() diff --git a/cmd/ctr/commands/signals.go b/cmd/ctr/commands/signals.go index 311608c26..4a8e165d2 100644 --- a/cmd/ctr/commands/signals.go +++ b/cmd/ctr/commands/signals.go @@ -24,7 +24,7 @@ import ( "github.com/containerd/containerd" "github.com/containerd/containerd/errdefs" - "github.com/sirupsen/logrus" + "github.com/containerd/containerd/log" ) type killer interface { @@ -38,16 +38,16 @@ func ForwardAllSignals(ctx gocontext.Context, task killer) chan os.Signal { go func() { for s := range sigc { if canIgnoreSignal(s) { - logrus.Debugf("Ignoring signal %s", s) + log.L.Debugf("Ignoring signal %s", s) continue } - logrus.Debug("forwarding signal ", s) + log.L.Debug("forwarding signal ", s) if err := task.Kill(ctx, s.(syscall.Signal)); err != nil { if errdefs.IsNotFound(err) { - logrus.WithError(err).Debugf("Not forwarding signal %s", s) + log.L.WithError(err).Debugf("Not forwarding signal %s", s) return } - logrus.WithError(err).Errorf("forward signal %s", s) + log.L.WithError(err).Errorf("forward signal %s", s) } } }() diff --git a/cmd/ctr/commands/tasks/attach.go b/cmd/ctr/commands/tasks/attach.go index a51e80651..634419ec2 100644 --- a/cmd/ctr/commands/tasks/attach.go +++ b/cmd/ctr/commands/tasks/attach.go @@ -20,7 +20,7 @@ import ( "github.com/containerd/console" "github.com/containerd/containerd/cio" "github.com/containerd/containerd/cmd/ctr/commands" - "github.com/sirupsen/logrus" + "github.com/containerd/containerd/log" "github.com/urfave/cli" ) @@ -66,7 +66,7 @@ var attachCommand = cli.Command{ if tty { if err := HandleConsoleResize(ctx, task, con); err != nil { - logrus.WithError(err).Error("console resize") + log.L.WithError(err).Error("console resize") } } else { sigc := commands.ForwardAllSignals(ctx, task) diff --git a/cmd/ctr/commands/tasks/exec.go b/cmd/ctr/commands/tasks/exec.go index 96a034b63..a7c1fb5ef 100644 --- a/cmd/ctr/commands/tasks/exec.go +++ b/cmd/ctr/commands/tasks/exec.go @@ -26,8 +26,8 @@ import ( "github.com/containerd/containerd" "github.com/containerd/containerd/cio" "github.com/containerd/containerd/cmd/ctr/commands" + "github.com/containerd/containerd/log" "github.com/containerd/containerd/oci" - "github.com/sirupsen/logrus" "github.com/urfave/cli" ) @@ -174,7 +174,7 @@ var execCommand = cli.Command{ } if tty { if err := HandleConsoleResize(ctx, process, con); err != nil { - logrus.WithError(err).Error("console resize") + log.L.WithError(err).Error("console resize") } } else { sigc := commands.ForwardAllSignals(ctx, process) diff --git a/cmd/ctr/commands/tasks/kill.go b/cmd/ctr/commands/tasks/kill.go index 4042df076..52211b65d 100644 --- a/cmd/ctr/commands/tasks/kill.go +++ b/cmd/ctr/commands/tasks/kill.go @@ -23,10 +23,10 @@ import ( "github.com/containerd/containerd" "github.com/containerd/containerd/cmd/ctr/commands" + "github.com/containerd/containerd/log" gocni "github.com/containerd/go-cni" "github.com/containerd/typeurl/v2" "github.com/moby/sys/signal" - "github.com/sirupsen/logrus" "github.com/urfave/cli" ) @@ -54,7 +54,7 @@ func RemoveCniNetworkIfExist(ctx context.Context, container containerd.Container return err } if err := network.Remove(ctx, commands.FullID(ctx, container), ""); err != nil { - logrus.WithError(err).Error("network remove error") + log.L.WithError(err).Error("network remove error") return err } } diff --git a/cmd/ctr/commands/tasks/start.go b/cmd/ctr/commands/tasks/start.go index 874074a01..4daf6d0ac 100644 --- a/cmd/ctr/commands/tasks/start.go +++ b/cmd/ctr/commands/tasks/start.go @@ -23,7 +23,7 @@ import ( "github.com/containerd/containerd" "github.com/containerd/containerd/cio" "github.com/containerd/containerd/cmd/ctr/commands" - "github.com/sirupsen/logrus" + "github.com/containerd/containerd/log" "github.com/urfave/cli" ) @@ -115,7 +115,7 @@ var startCommand = cli.Command{ } if tty { if err := HandleConsoleResize(ctx, task, con); err != nil { - logrus.WithError(err).Error("console resize") + log.L.WithError(err).Error("console resize") } } else { sigc := commands.ForwardAllSignals(ctx, task) diff --git a/diff/stream_windows.go b/diff/stream_windows.go index e6026f4e9..dc9a0caf1 100644 --- a/diff/stream_windows.go +++ b/diff/stream_windows.go @@ -26,12 +26,13 @@ import ( "path/filepath" "sync" - winio "github.com/Microsoft/go-winio" + "github.com/Microsoft/go-winio" + exec "golang.org/x/sys/execabs" + + "github.com/containerd/containerd/log" "github.com/containerd/containerd/protobuf" "github.com/containerd/containerd/protobuf/proto" "github.com/containerd/typeurl/v2" - "github.com/sirupsen/logrus" - exec "golang.org/x/sys/execabs" ) const processorPipe = "STREAM_PROCESSOR_PIPE" @@ -61,7 +62,7 @@ func NewBinaryProcessor(ctx context.Context, imt, rmt string, stream StreamProce defer l.Close() conn, err := l.Accept() if err != nil { - logrus.WithError(err).Error("accept npipe connection") + log.G(ctx).WithError(err).Error("accept npipe connection") return } io.Copy(conn, bytes.NewReader(data)) diff --git a/images/diffid.go b/images/diffid.go index 56193cc28..1bd5256e2 100644 --- a/images/diffid.go +++ b/images/diffid.go @@ -20,12 +20,13 @@ import ( "context" "io" + "github.com/opencontainers/go-digest" + ocispec "github.com/opencontainers/image-spec/specs-go/v1" + "github.com/containerd/containerd/archive/compression" "github.com/containerd/containerd/content" "github.com/containerd/containerd/labels" - "github.com/opencontainers/go-digest" - ocispec "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/sirupsen/logrus" + "github.com/containerd/containerd/log" ) // GetDiffID gets the diff ID of the layer blob descriptor. @@ -75,7 +76,7 @@ func GetDiffID(ctx context.Context, cs content.Store, desc ocispec.Descriptor) ( } info.Labels[labels.LabelUncompressed] = digest.String() if _, err := cs.Update(ctx, info, "labels"); err != nil { - logrus.WithError(err).Warnf("failed to set %s label for %s", labels.LabelUncompressed, desc.Digest) + log.G(ctx).WithError(err).Warnf("failed to set %s label for %s", labels.LabelUncompressed, desc.Digest) } return digest, nil } diff --git a/metrics/cgroups/v1/cgroups.go b/metrics/cgroups/v1/cgroups.go index 9bd366fbc..0cc3e9787 100644 --- a/metrics/cgroups/v1/cgroups.go +++ b/metrics/cgroups/v1/cgroups.go @@ -29,7 +29,6 @@ import ( "github.com/containerd/containerd/namespaces" "github.com/containerd/containerd/runtime" "github.com/docker/go-metrics" - "github.com/sirupsen/logrus" ) // NewTaskMonitor returns a new cgroups monitor @@ -75,7 +74,7 @@ func (m *cgroupsMonitor) Monitor(c runtime.Task, labels map[string]string) error } err = m.oom.Add(c.ID(), c.Namespace(), cg, m.trigger) if err == cgroups.ErrMemoryNotSupported { - logrus.WithError(err).Warn("OOM monitoring failed") + log.L.WithError(err).Warn("OOM monitoring failed") return nil } return err diff --git a/pkg/cri/io/container_io.go b/pkg/cri/io/container_io.go index 70bc8b789..e7725a8f1 100644 --- a/pkg/cri/io/container_io.go +++ b/pkg/cri/io/container_io.go @@ -23,6 +23,7 @@ import ( "sync" "github.com/containerd/containerd/cio" + "github.com/containerd/containerd/log" "github.com/sirupsen/logrus" "github.com/containerd/containerd/pkg/cri/util" @@ -109,12 +110,12 @@ func (c *ContainerIO) Pipe() { wg.Add(1) go func() { if _, err := io.Copy(c.stdoutGroup, c.stdout); err != nil { - logrus.WithError(err).Errorf("Failed to pipe stdout of container %q", c.id) + log.L.WithError(err).Errorf("Failed to pipe stdout of container %q", c.id) } c.stdout.Close() c.stdoutGroup.Close() wg.Done() - logrus.Debugf("Finish piping stdout of container %q", c.id) + log.L.Debugf("Finish piping stdout of container %q", c.id) }() } @@ -122,12 +123,12 @@ func (c *ContainerIO) Pipe() { wg.Add(1) go func() { if _, err := io.Copy(c.stderrGroup, c.stderr); err != nil { - logrus.WithError(err).Errorf("Failed to pipe stderr of container %q", c.id) + log.L.WithError(err).Errorf("Failed to pipe stderr of container %q", c.id) } c.stderr.Close() c.stderrGroup.Close() wg.Done() - logrus.Debugf("Finish piping stderr of container %q", c.id) + log.L.Debugf("Finish piping stderr of container %q", c.id) }() } } @@ -150,9 +151,9 @@ func (c *ContainerIO) Attach(opts AttachOptions) { wg.Add(1) go func() { if _, err := io.Copy(c.stdin, stdinStreamRC); err != nil { - logrus.WithError(err).Errorf("Failed to pipe stdin for container attach %q", c.id) + log.L.WithError(err).Errorf("Failed to pipe stdin for container attach %q", c.id) } - logrus.Infof("Attach stream %q closed", stdinKey) + log.L.Infof("Attach stream %q closed", stdinKey) if opts.StdinOnce && !opts.Tty { // Due to kubectl requirements and current docker behavior, when (opts.StdinOnce && // opts.Tty) we have to close container stdin and keep stdout and stderr open until diff --git a/pkg/cri/io/exec_io.go b/pkg/cri/io/exec_io.go index 1d2a4f2c7..70fb98120 100644 --- a/pkg/cri/io/exec_io.go +++ b/pkg/cri/io/exec_io.go @@ -21,8 +21,7 @@ import ( "sync" "github.com/containerd/containerd/cio" - "github.com/sirupsen/logrus" - + "github.com/containerd/containerd/log" cioutil "github.com/containerd/containerd/pkg/ioutil" ) @@ -68,13 +67,13 @@ func (e *ExecIO) Attach(opts AttachOptions) <-chan struct{} { wg.Add(1) go func() { if _, err := io.Copy(e.stdin, stdinStreamRC); err != nil { - logrus.WithError(err).Errorf("Failed to redirect stdin for container exec %q", e.id) + log.L.WithError(err).Errorf("Failed to redirect stdin for container exec %q", e.id) } - logrus.Infof("Container exec %q stdin closed", e.id) + log.L.Infof("Container exec %q stdin closed", e.id) if opts.StdinOnce && !opts.Tty { e.stdin.Close() if err := opts.CloseStdin(); err != nil { - logrus.WithError(err).Errorf("Failed to close stdin for container exec %q", e.id) + log.L.WithError(err).Errorf("Failed to close stdin for container exec %q", e.id) } } else { if e.stdout != nil { @@ -90,7 +89,7 @@ func (e *ExecIO) Attach(opts AttachOptions) <-chan struct{} { attachOutput := func(t StreamType, stream io.WriteCloser, out io.ReadCloser) { if _, err := io.Copy(stream, out); err != nil { - logrus.WithError(err).Errorf("Failed to pipe %q for container exec %q", t, e.id) + log.L.WithError(err).Errorf("Failed to pipe %q for container exec %q", t, e.id) } out.Close() stream.Close() @@ -99,7 +98,7 @@ func (e *ExecIO) Attach(opts AttachOptions) <-chan struct{} { } e.closer.wg.Done() wg.Done() - logrus.Debugf("Finish piping %q of container exec %q", t, e.id) + log.L.Debugf("Finish piping %q of container exec %q", t, e.id) } if opts.Stdout != nil { diff --git a/pkg/cri/opts/spec_linux.go b/pkg/cri/opts/spec_linux.go index 69621e8a9..8dae6735f 100644 --- a/pkg/cri/opts/spec_linux.go +++ b/pkg/cri/opts/spec_linux.go @@ -28,7 +28,6 @@ import ( "github.com/container-orchestrated-devices/container-device-interface/pkg/cdi" "github.com/containerd/cgroups/v3" - "github.com/sirupsen/logrus" "golang.org/x/sys/unix" "github.com/containerd/containerd/containers" @@ -53,14 +52,14 @@ func SwapControllerAvailable() bool { _, unified, err := cgroups.ParseCgroupFileUnified("/proc/self/cgroup") if err != nil { err = fmt.Errorf("failed to parse /proc/self/cgroup: %w", err) - logrus.WithError(err).Warn(warn) + log.L.WithError(err).Warn(warn) return } p = filepath.Join("/sys/fs/cgroup", unified, "memory.swap.max") } if _, err := os.Stat(p); err != nil { if !errors.Is(err, os.ErrNotExist) { - logrus.WithError(err).Warn(warn) + log.L.WithError(err).Warn(warn) } return } diff --git a/pkg/cri/opts/spec_linux_opts.go b/pkg/cri/opts/spec_linux_opts.go index 354977f32..357d3ea45 100644 --- a/pkg/cri/opts/spec_linux_opts.go +++ b/pkg/cri/opts/spec_linux_opts.go @@ -29,7 +29,6 @@ import ( runtimespec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/selinux/go-selinux/label" - "github.com/sirupsen/logrus" runtime "k8s.io/cri-api/pkg/apis/runtime/v1" "github.com/containerd/containerd/containers" @@ -347,7 +346,7 @@ func WithResources(resources *runtime.LinuxContainerResources, tolerateMissingHu return errors.New("huge pages limits are specified but hugetlb cgroup controller is missing. " + "Please set tolerate_missing_hugetlb_controller to `true` to ignore this error") } - logrus.Warn("hugetlb cgroup controller is absent. skipping huge pages limits") + log.L.Warn("hugetlb cgroup controller is absent. skipping huge pages limits") } } diff --git a/pkg/cri/sbserver/blockio_linux.go b/pkg/cri/sbserver/blockio_linux.go index b957563d6..bbc58d18f 100644 --- a/pkg/cri/sbserver/blockio_linux.go +++ b/pkg/cri/sbserver/blockio_linux.go @@ -21,8 +21,7 @@ package sbserver import ( "fmt" - "github.com/sirupsen/logrus" - + "github.com/containerd/containerd/log" "github.com/containerd/containerd/pkg/blockio" ) @@ -37,7 +36,7 @@ func (c *criService) blockIOClassFromAnnotations(containerName string, container if cls != "" && !blockio.IsEnabled() { if c.config.ContainerdConfig.IgnoreBlockIONotEnabledErrors { cls = "" - logrus.Debugf("continuing create container %s, ignoring blockio not enabled (%v)", containerName, err) + log.L.Debugf("continuing create container %s, ignoring blockio not enabled (%v)", containerName, err) } else { return "", fmt.Errorf("blockio disabled, refusing to set blockio class of container %q to %q", containerName, cls) } diff --git a/pkg/cri/sbserver/cni_conf_syncer.go b/pkg/cri/sbserver/cni_conf_syncer.go index 551e0b924..dc0b917a1 100644 --- a/pkg/cri/sbserver/cni_conf_syncer.go +++ b/pkg/cri/sbserver/cni_conf_syncer.go @@ -22,9 +22,9 @@ import ( "path/filepath" "sync" + "github.com/containerd/containerd/log" "github.com/containerd/go-cni" "github.com/fsnotify/fsnotify" - "github.com/sirupsen/logrus" ) // cniNetConfSyncer is used to reload cni network conf triggered by fs change @@ -70,7 +70,7 @@ func newCNINetConfSyncer(confDir string, netPlugin cni.CNI, loadOpts []cni.Opt) } if err := syncer.netPlugin.Load(syncer.loadOpts...); err != nil { - logrus.WithError(err).Error("failed to load cni during init, please check CRI plugin status before setting up network for pods") + log.L.WithError(err).Error("failed to load cni during init, please check CRI plugin status before setting up network for pods") syncer.updateLastStatus(err) } return syncer, nil @@ -83,7 +83,7 @@ func (syncer *cniNetConfSyncer) syncLoop() error { select { case event, ok := <-syncer.watcher.Events: if !ok { - logrus.Debugf("cni watcher channel is closed") + log.L.Debugf("cni watcher channel is closed") return nil } // Only reload config when receiving write/rename/remove @@ -92,21 +92,21 @@ func (syncer *cniNetConfSyncer) syncLoop() error { // TODO(fuweid): Might only reload target cni config // files to prevent no-ops. if event.Has(fsnotify.Chmod) || event.Has(fsnotify.Create) { - logrus.Debugf("ignore event from cni conf dir: %s", event) + log.L.Debugf("ignore event from cni conf dir: %s", event) continue } - logrus.Debugf("receiving change event from cni conf dir: %s", event) + log.L.Debugf("receiving change event from cni conf dir: %s", event) lerr := syncer.netPlugin.Load(syncer.loadOpts...) if lerr != nil { - logrus.WithError(lerr). + log.L.WithError(lerr). Errorf("failed to reload cni configuration after receiving fs change event(%s)", event) } syncer.updateLastStatus(lerr) case err := <-syncer.watcher.Errors: if err != nil { - logrus.WithError(err).Error("failed to continue sync cni conf change") + log.L.WithError(err).Error("failed to continue sync cni conf change") return err } } diff --git a/pkg/cri/sbserver/container_remove.go b/pkg/cri/sbserver/container_remove.go index e40d1fae0..9cc568f4b 100644 --- a/pkg/cri/sbserver/container_remove.go +++ b/pkg/cri/sbserver/container_remove.go @@ -26,7 +26,6 @@ import ( "github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/log" containerstore "github.com/containerd/containerd/pkg/cri/store/container" - "github.com/sirupsen/logrus" runtime "k8s.io/cri-api/pkg/apis/runtime/v1" ) @@ -62,7 +61,7 @@ func (c *criService) RemoveContainer(ctx context.Context, r *runtime.RemoveConta state := container.Status.Get().State() if state == runtime.ContainerState_CONTAINER_RUNNING || state == runtime.ContainerState_CONTAINER_UNKNOWN { - logrus.Infof("Forcibly stopping container %q", id) + log.L.Infof("Forcibly stopping container %q", id) if err := c.stopContainer(ctx, container, 0); err != nil { return nil, fmt.Errorf("failed to forcibly stop container %q: %w", id, err) } diff --git a/pkg/cri/sbserver/container_start.go b/pkg/cri/sbserver/container_start.go index dd6413ce9..15252a29e 100644 --- a/pkg/cri/sbserver/container_start.go +++ b/pkg/cri/sbserver/container_start.go @@ -27,7 +27,6 @@ import ( containerdio "github.com/containerd/containerd/cio" "github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/log" - "github.com/sirupsen/logrus" runtime "k8s.io/cri-api/pkg/apis/runtime/v1" cio "github.com/containerd/containerd/pkg/cri/io" @@ -242,7 +241,7 @@ func (c *criService) createContainerLoggers(logPath string, tty bool) (stdout io if stderrCh != nil { <-stderrCh } - logrus.Debugf("Finish redirecting log file %q, closing it", logPath) + log.L.Debugf("Finish redirecting log file %q, closing it", logPath) f.Close() }() } else { diff --git a/pkg/cri/sbserver/events.go b/pkg/cri/sbserver/events.go index 9e62ae1cb..d5abe820b 100644 --- a/pkg/cri/sbserver/events.go +++ b/pkg/cri/sbserver/events.go @@ -28,13 +28,13 @@ import ( containerdio "github.com/containerd/containerd/cio" "github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/events" + "github.com/containerd/containerd/log" "github.com/containerd/containerd/pkg/cri/constants" containerstore "github.com/containerd/containerd/pkg/cri/store/container" sandboxstore "github.com/containerd/containerd/pkg/cri/store/sandbox" 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" ) @@ -115,7 +115,7 @@ func (em *eventMonitor) startSandboxExitMonitor(ctx context.Context, id string, case exitRes := <-exitCh: exitStatus, exitedAt, err := exitRes.Result() if err != nil { - logrus.WithError(err).Errorf("failed to get task exit status for %q", id) + log.L.WithError(err).Errorf("failed to get task exit status for %q", id) exitStatus = unknownExitCode exitedAt = time.Now() } @@ -128,7 +128,7 @@ func (em *eventMonitor) startSandboxExitMonitor(ctx context.Context, id string, ExitedAt: protobuf.ToTimestamp(exitedAt), } - logrus.Debugf("received exit event %+v", e) + log.L.Debugf("received exit event %+v", e) err = func() error { dctx := ctrdutil.NamespacedContext() @@ -147,7 +147,7 @@ func (em *eventMonitor) startSandboxExitMonitor(ctx context.Context, id string, return nil }() if err != nil { - logrus.WithError(err).Errorf("failed to handle sandbox TaskExit event %+v", e) + log.L.WithError(err).Errorf("failed to handle sandbox TaskExit event %+v", e) em.backOff.enBackOff(id, e) } return @@ -166,7 +166,7 @@ func (em *eventMonitor) startContainerExitMonitor(ctx context.Context, id string case exitRes := <-exitCh: exitStatus, exitedAt, err := exitRes.Result() if err != nil { - logrus.WithError(err).Errorf("failed to get task exit status for %q", id) + log.L.WithError(err).Errorf("failed to get task exit status for %q", id) exitStatus = unknownExitCode exitedAt = time.Now() } @@ -179,7 +179,7 @@ func (em *eventMonitor) startContainerExitMonitor(ctx context.Context, id string ExitedAt: protobuf.ToTimestamp(exitedAt), } - logrus.Debugf("received exit event %+v", e) + log.L.Debugf("received exit event %+v", e) err = func() error { dctx := ctrdutil.NamespacedContext() @@ -198,7 +198,7 @@ func (em *eventMonitor) startContainerExitMonitor(ctx context.Context, id string return nil }() if err != nil { - logrus.WithError(err).Errorf("failed to handle container TaskExit event %+v", e) + log.L.WithError(err).Errorf("failed to handle container TaskExit event %+v", e) em.backOff.enBackOff(id, e) } return @@ -251,29 +251,29 @@ func (em *eventMonitor) start() <-chan error { for { select { case e := <-em.ch: - logrus.Debugf("Received containerd event timestamp - %v, namespace - %q, topic - %q", e.Timestamp, e.Namespace, e.Topic) + log.L.Debugf("Received containerd event timestamp - %v, namespace - %q, topic - %q", e.Timestamp, e.Namespace, e.Topic) if e.Namespace != constants.K8sContainerdNamespace { - logrus.Debugf("Ignoring events in namespace - %q", e.Namespace) + log.L.Debugf("Ignoring events in namespace - %q", e.Namespace) break } id, evt, err := convertEvent(e.Event) if err != nil { - logrus.WithError(err).Errorf("Failed to convert event %+v", e) + log.L.WithError(err).Errorf("Failed to convert event %+v", e) 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 @@ -283,7 +283,7 @@ func (em *eventMonitor) start() <-chan error { queue := em.backOff.deBackOff(id) for i, any := range queue.events { if err := em.handleEvent(any); err != nil { - logrus.WithError(err).Errorf("Failed to handle backOff event %+v for %s", any, id) + log.L.WithError(err).Errorf("Failed to handle backOff event %+v for %s", any, id) em.backOff.reBackOff(id, queue.events[i:], queue.duration) break } @@ -310,7 +310,7 @@ func (em *eventMonitor) handleEvent(any interface{}) error { switch e := any.(type) { case *eventtypes.TaskExit: - logrus.Infof("TaskExit event %+v", e) + log.L.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 { @@ -332,7 +332,7 @@ func (em *eventMonitor) handleEvent(any interface{}) error { } return nil case *eventtypes.TaskOOM: - logrus.Infof("TaskOOM event %+v", e) + log.L.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 { @@ -349,13 +349,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.L.Infof("ImageCreate event %+v", e) return em.c.UpdateImage(ctx, e.Name) case *eventtypes.ImageUpdate: - logrus.Infof("ImageUpdate event %+v", e) + log.L.Infof("ImageUpdate event %+v", e) return em.c.UpdateImage(ctx, e.Name) case *eventtypes.ImageDelete: - logrus.Infof("ImageDelete event %+v", e) + log.L.Infof("ImageDelete event %+v", e) return em.c.UpdateImage(ctx, e.Name) } @@ -402,7 +402,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.L.Debugf("Container %q transited from UNKNOWN to EXITED", cntr.ID) status.Unknown = false } return status, nil diff --git a/pkg/cri/sbserver/helpers.go b/pkg/cri/sbserver/helpers.go index 0e93a48be..fefb1646c 100644 --- a/pkg/cri/sbserver/helpers.go +++ b/pkg/cri/sbserver/helpers.go @@ -27,14 +27,17 @@ import ( "strings" "time" + runhcsoptions "github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/options" "github.com/containerd/typeurl/v2" runtimespec "github.com/opencontainers/runtime-spec/specs-go" - "github.com/sirupsen/logrus" + "github.com/pelletier/go-toml" + runtime "k8s.io/cri-api/pkg/apis/runtime/v1" "github.com/containerd/containerd" "github.com/containerd/containerd/containers" "github.com/containerd/containerd/errdefs" clabels "github.com/containerd/containerd/labels" + "github.com/containerd/containerd/log" criconfig "github.com/containerd/containerd/pkg/cri/config" containerstore "github.com/containerd/containerd/pkg/cri/store/container" imagestore "github.com/containerd/containerd/pkg/cri/store/image" @@ -42,10 +45,6 @@ import ( runtimeoptions "github.com/containerd/containerd/pkg/runtimeoptions/v1" "github.com/containerd/containerd/plugin" runcoptions "github.com/containerd/containerd/runtime/v2/runc/options" - - runhcsoptions "github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/options" - "github.com/pelletier/go-toml" - runtime "k8s.io/cri-api/pkg/apis/runtime/v1" ) // TODO: Move common helpers for sbserver and podsandbox to a dedicated package once basic services are functinal. @@ -254,7 +253,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 @@ -448,12 +447,12 @@ func copyResourcesToStatus(spec *runtimespec.Spec, status containerstore.Status) func (c *criService) generateAndSendContainerEvent(ctx context.Context, containerID string, sandboxID string, eventType runtime.ContainerEventType) { podSandboxStatus, err := c.getPodSandboxStatus(ctx, sandboxID) if err != nil { - logrus.Warnf("Failed to get podSandbox status for container event for sandboxID %q: %v. Sending the event with nil podSandboxStatus.", sandboxID, err) + log.G(ctx).Warnf("Failed to get podSandbox status for container event for sandboxID %q: %v. Sending the event with nil podSandboxStatus.", sandboxID, err) podSandboxStatus = nil } 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{ @@ -468,7 +467,7 @@ func (c *criService) generateAndSendContainerEvent(ctx context.Context, containe select { case c.containerEventsChan <- event: default: - logrus.Debugf("containerEventsChan is full, discarding event %+v", event) + log.G(ctx).Debugf("containerEventsChan is full, discarding event %+v", event) } } diff --git a/pkg/cri/sbserver/images/snapshots.go b/pkg/cri/sbserver/images/snapshots.go index ca6e9b9b1..6bb06da45 100644 --- a/pkg/cri/sbserver/images/snapshots.go +++ b/pkg/cri/sbserver/images/snapshots.go @@ -22,11 +22,10 @@ import ( "time" "github.com/containerd/containerd/errdefs" - snapshot "github.com/containerd/containerd/snapshots" - "github.com/sirupsen/logrus" - + "github.com/containerd/containerd/log" snapshotstore "github.com/containerd/containerd/pkg/cri/store/snapshot" ctrdutil "github.com/containerd/containerd/pkg/cri/util" + snapshot "github.com/containerd/containerd/snapshots" ) // snapshotsSyncer syncs snapshot stats periodically. imagefs info and container stats @@ -60,7 +59,7 @@ func (s *snapshotsSyncer) start() { // check the resource usage and optimize this. for { if err := s.sync(); err != nil { - logrus.WithError(err).Error("Failed to sync snapshot stats") + log.L.WithError(err).Error("Failed to sync snapshot stats") } <-tick.C } @@ -101,7 +100,7 @@ func (s *snapshotsSyncer) sync() error { usage, err := s.snapshotter.Usage(ctx, info.Name) if err != nil { if !errdefs.IsNotFound(err) { - logrus.WithError(err).Errorf("Failed to get usage for snapshot %q", info.Name) + log.L.WithError(err).Errorf("Failed to get usage for snapshot %q", info.Name) } continue } diff --git a/pkg/cri/sbserver/podsandbox/controller.go b/pkg/cri/sbserver/podsandbox/controller.go index 2c66d356b..0be73ffe5 100644 --- a/pkg/cri/sbserver/podsandbox/controller.go +++ b/pkg/cri/sbserver/podsandbox/controller.go @@ -21,7 +21,7 @@ import ( "fmt" "time" - "github.com/sirupsen/logrus" + "github.com/containerd/containerd/log" runtime "k8s.io/cri-api/pkg/apis/runtime/v1" "github.com/containerd/containerd" @@ -122,11 +122,11 @@ func (c *Controller) waitSandboxExit(ctx context.Context, id string, exitCh <-ch exitedAt = time.Now() select { case exitRes := <-exitCh: - logrus.Debugf("received sandbox exit %+v", exitRes) + log.G(ctx).Debugf("received sandbox exit %+v", exitRes) exitStatus, exitedAt, err = exitRes.Result() if err != nil { - logrus.WithError(err).Errorf("failed to get task exit status for %q", id) + log.G(ctx).WithError(err).Errorf("failed to get task exit status for %q", id) exitStatus = unknownExitCode exitedAt = time.Now() } @@ -148,7 +148,7 @@ func (c *Controller) waitSandboxExit(ctx context.Context, id string, exitCh <-ch return nil }() if err != nil { - logrus.WithError(err).Errorf("failed to handle sandbox TaskExit %s", id) + log.G(ctx).WithError(err).Errorf("failed to handle sandbox TaskExit %s", id) // Don't backoff, the caller is responsible for. return } diff --git a/pkg/cri/sbserver/rdt.go b/pkg/cri/sbserver/rdt.go index 665029096..f0360ef5c 100644 --- a/pkg/cri/sbserver/rdt.go +++ b/pkg/cri/sbserver/rdt.go @@ -21,8 +21,7 @@ package sbserver import ( "fmt" - "github.com/sirupsen/logrus" - + "github.com/containerd/containerd/log" "github.com/containerd/containerd/pkg/rdt" ) @@ -40,7 +39,7 @@ func (c *criService) rdtClassFromAnnotations(containerName string, containerAnno if err != nil { if !rdt.IsEnabled() && c.config.ContainerdConfig.IgnoreRdtNotEnabledErrors { - logrus.Debugf("continuing create container %s, ignoring rdt not enabled (%v)", containerName, err) + log.L.Debugf("continuing create container %s, ignoring rdt not enabled (%v)", containerName, err) return "", nil } return "", err diff --git a/pkg/cri/sbserver/sandbox_remove.go b/pkg/cri/sbserver/sandbox_remove.go index cd1228daf..80b642151 100644 --- a/pkg/cri/sbserver/sandbox_remove.go +++ b/pkg/cri/sbserver/sandbox_remove.go @@ -24,7 +24,6 @@ import ( "github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/log" - "github.com/sirupsen/logrus" runtime "k8s.io/cri-api/pkg/apis/runtime/v1" ) @@ -49,7 +48,7 @@ func (c *criService) RemovePodSandbox(ctx context.Context, r *runtime.RemovePodS // If the sandbox is still running, not ready, or in an unknown state, forcibly stop it. // Even if it's in a NotReady state, this will close its network namespace, if open. // This can happen if the task process associated with the Pod died or it was killed. - logrus.Infof("Forcibly stopping sandbox %q", id) + log.G(ctx).Infof("Forcibly stopping sandbox %q", id) if err := c.stopPodSandbox(ctx, sandbox); err != nil { return nil, fmt.Errorf("failed to forcibly stop sandbox %q: %w", id, err) } diff --git a/pkg/cri/sbserver/sandbox_run.go b/pkg/cri/sbserver/sandbox_run.go index 8e036e14b..c168fd31d 100644 --- a/pkg/cri/sbserver/sandbox_run.go +++ b/pkg/cri/sbserver/sandbox_run.go @@ -29,7 +29,6 @@ import ( "github.com/containerd/go-cni" "github.com/containerd/typeurl/v2" "github.com/hashicorp/go-multierror" - "github.com/sirupsen/logrus" runtime "k8s.io/cri-api/pkg/apis/runtime/v1" "github.com/containerd/containerd" @@ -598,7 +597,7 @@ func (c *criService) getSandboxController(config *runtime.PodSandboxConfig, runt } func logDebugCNIResult(ctx context.Context, sandboxID string, result *cni.Result) { - if logrus.GetLevel() < logrus.DebugLevel { + if log.GetLevel() < log.DebugLevel { return } cniResult, err := json.Marshal(result) diff --git a/pkg/cri/sbserver/service.go b/pkg/cri/sbserver/service.go index 6c18e89c6..6ed414df3 100644 --- a/pkg/cri/sbserver/service.go +++ b/pkg/cri/sbserver/service.go @@ -28,6 +28,7 @@ import ( "sync/atomic" "github.com/containerd/containerd" + "github.com/containerd/containerd/log" "github.com/containerd/containerd/oci" "github.com/containerd/containerd/pkg/cri/instrument" "github.com/containerd/containerd/pkg/cri/nri" @@ -39,7 +40,6 @@ import ( "github.com/containerd/containerd/plugin" "github.com/containerd/containerd/sandbox" "github.com/containerd/go-cni" - "github.com/sirupsen/logrus" "google.golang.org/grpc" runtime "k8s.io/cri-api/pkg/apis/runtime/v1" @@ -140,7 +140,7 @@ func NewCRIService(config criconfig.Config, client *containerd.Client, nri *nri. } imageFSPath := imageFSPath(config.ContainerdRootDir, config.ContainerdConfig.Snapshotter) - logrus.Infof("Get image filesystem path %q", imageFSPath) + log.L.Infof("Get image filesystem path %q", imageFSPath) // TODO: expose this as a separate containerd plugin. imageService, err := images.NewService(config, imageFSPath, client) @@ -238,16 +238,16 @@ func (c *criService) RegisterTCP(s *grpc.Server) error { // Run starts the CRI service. func (c *criService) Run() error { - logrus.Info("Start subscribing containerd event") + log.L.Info("Start subscribing containerd event") c.eventMonitor.subscribe(c.client) - logrus.Infof("Start recovering state") + log.L.Infof("Start recovering state") if err := c.recover(ctrdutil.NamespacedContext()); err != nil { return fmt.Errorf("failed to recover state: %w", err) } // Start event handler. - logrus.Info("Start event monitor") + log.L.Info("Start event monitor") eventMonitorErrCh := c.eventMonitor.start() // Start CNI network conf syncers @@ -255,7 +255,7 @@ func (c *criService) Run() error { var netSyncGroup sync.WaitGroup for name, h := range c.cniNetConfMonitor { netSyncGroup.Add(1) - logrus.Infof("Start cni network conf syncer for %s", name) + log.L.Infof("Start cni network conf syncer for %s", name) go func(h *cniNetConfSyncer) { cniNetConfMonitorErrCh <- h.syncLoop() netSyncGroup.Done() @@ -274,12 +274,12 @@ func (c *criService) Run() error { } // Start streaming server. - logrus.Info("Start streaming server") + log.L.Info("Start streaming server") streamServerErrCh := make(chan error) go func() { defer close(streamServerErrCh) if err := c.streamServer.Start(true); err != nil && err != http.ErrServerClosed { - logrus.WithError(err).Error("Failed to start streaming server") + log.L.WithError(err).Error("Failed to start streaming server") streamServerErrCh <- err } }() @@ -307,11 +307,11 @@ func (c *criService) Run() error { if err := <-eventMonitorErrCh; err != nil { eventMonitorErr = err } - logrus.Info("Event monitor stopped") + log.L.Info("Event monitor stopped") if err := <-streamServerErrCh; err != nil { streamServerErr = err } - logrus.Info("Stream server stopped") + log.L.Info("Stream server stopped") if eventMonitorErr != nil { return fmt.Errorf("event monitor error: %w", eventMonitorErr) } @@ -327,10 +327,10 @@ func (c *criService) Run() 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() diff --git a/pkg/cri/sbserver/service_linux.go b/pkg/cri/sbserver/service_linux.go index c5da2d46f..67a4865b9 100644 --- a/pkg/cri/sbserver/service_linux.go +++ b/pkg/cri/sbserver/service_linux.go @@ -20,11 +20,12 @@ import ( "fmt" "github.com/container-orchestrated-devices/container-device-interface/pkg/cdi" + "github.com/opencontainers/selinux/go-selinux" + + "github.com/containerd/containerd/log" "github.com/containerd/containerd/pkg/cap" "github.com/containerd/containerd/pkg/userns" "github.com/containerd/go-cni" - "github.com/opencontainers/selinux/go-selinux" - "github.com/sirupsen/logrus" ) // networkAttachCount is the minimum number of networks the PodSandbox @@ -35,13 +36,13 @@ const networkAttachCount = 2 func (c *criService) initPlatform() (err error) { if userns.RunningInUserNS() { if !(c.config.DisableCgroup && !c.apparmorEnabled() && c.config.RestrictOOMScoreAdj) { - logrus.Warn("Running containerd in a user namespace typically requires disable_cgroup, disable_apparmor, restrict_oom_score_adj set to be true") + log.L.Warn("Running containerd in a user namespace typically requires disable_cgroup, disable_apparmor, restrict_oom_score_adj set to be true") } } if c.config.EnableSelinux { if !selinux.GetEnabled() { - logrus.Warn("Selinux is not supported") + log.L.Warn("Selinux is not supported") } if r := c.config.SelinuxCategoryRange; r > 0 { selinux.CategoryRange = uint32(r) diff --git a/pkg/cri/server/blockio_linux.go b/pkg/cri/server/blockio_linux.go index 24ba0540e..c1746d8e7 100644 --- a/pkg/cri/server/blockio_linux.go +++ b/pkg/cri/server/blockio_linux.go @@ -21,8 +21,7 @@ package server import ( "fmt" - "github.com/sirupsen/logrus" - + "github.com/containerd/containerd/log" "github.com/containerd/containerd/pkg/blockio" ) @@ -37,7 +36,7 @@ func (c *criService) blockIOClassFromAnnotations(containerName string, container if cls != "" && !blockio.IsEnabled() { if c.config.ContainerdConfig.IgnoreBlockIONotEnabledErrors { cls = "" - logrus.Debugf("continuing create container %s, ignoring blockio not enabled (%v)", containerName, err) + log.L.Debugf("continuing create container %s, ignoring blockio not enabled (%v)", containerName, err) } else { return "", fmt.Errorf("blockio disabled, refusing to set blockio class of container %q to %q", containerName, cls) } diff --git a/pkg/cri/server/cni_conf_syncer.go b/pkg/cri/server/cni_conf_syncer.go index 9e2a459ec..8b5e4bc44 100644 --- a/pkg/cri/server/cni_conf_syncer.go +++ b/pkg/cri/server/cni_conf_syncer.go @@ -22,9 +22,9 @@ import ( "path/filepath" "sync" + "github.com/containerd/containerd/log" cni "github.com/containerd/go-cni" "github.com/fsnotify/fsnotify" - "github.com/sirupsen/logrus" ) // cniNetConfSyncer is used to reload cni network conf triggered by fs change @@ -70,7 +70,7 @@ func newCNINetConfSyncer(confDir string, netPlugin cni.CNI, loadOpts []cni.Opt) } if err := syncer.netPlugin.Load(syncer.loadOpts...); err != nil { - logrus.WithError(err).Error("failed to load cni during init, please check CRI plugin status before setting up network for pods") + log.L.WithError(err).Error("failed to load cni during init, please check CRI plugin status before setting up network for pods") syncer.updateLastStatus(err) } return syncer, nil @@ -83,7 +83,7 @@ func (syncer *cniNetConfSyncer) syncLoop() error { select { case event, ok := <-syncer.watcher.Events: if !ok { - logrus.Debugf("cni watcher channel is closed") + log.L.Debugf("cni watcher channel is closed") return nil } // Only reload config when receiving write/rename/remove @@ -92,21 +92,21 @@ func (syncer *cniNetConfSyncer) syncLoop() error { // TODO(fuweid): Might only reload target cni config // files to prevent no-ops. if event.Has(fsnotify.Chmod) || event.Has(fsnotify.Create) { - logrus.Debugf("ignore event from cni conf dir: %s", event) + log.L.Debugf("ignore event from cni conf dir: %s", event) continue } - logrus.Debugf("receiving change event from cni conf dir: %s", event) + log.L.Debugf("receiving change event from cni conf dir: %s", event) lerr := syncer.netPlugin.Load(syncer.loadOpts...) if lerr != nil { - logrus.WithError(lerr). + log.L.WithError(lerr). Errorf("failed to reload cni configuration after receiving fs change event(%s)", event) } syncer.updateLastStatus(lerr) case err := <-syncer.watcher.Errors: if err != nil { - logrus.WithError(err).Error("failed to continue sync cni conf change") + log.L.WithError(err).Error("failed to continue sync cni conf change") return err } } diff --git a/pkg/cri/server/container_remove.go b/pkg/cri/server/container_remove.go index 8f95e05f1..e8655315c 100644 --- a/pkg/cri/server/container_remove.go +++ b/pkg/cri/server/container_remove.go @@ -26,7 +26,6 @@ import ( "github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/log" containerstore "github.com/containerd/containerd/pkg/cri/store/container" - "github.com/sirupsen/logrus" runtime "k8s.io/cri-api/pkg/apis/runtime/v1" ) @@ -62,7 +61,7 @@ func (c *criService) RemoveContainer(ctx context.Context, r *runtime.RemoveConta state := container.Status.Get().State() if state == runtime.ContainerState_CONTAINER_RUNNING || state == runtime.ContainerState_CONTAINER_UNKNOWN { - logrus.Infof("Forcibly stopping container %q", id) + log.L.Infof("Forcibly stopping container %q", id) if err := c.stopContainer(ctx, container, 0); err != nil { return nil, fmt.Errorf("failed to forcibly stop container %q: %w", id, err) } diff --git a/pkg/cri/server/container_start.go b/pkg/cri/server/container_start.go index d5a7b595e..6132d573f 100644 --- a/pkg/cri/server/container_start.go +++ b/pkg/cri/server/container_start.go @@ -27,7 +27,6 @@ import ( containerdio "github.com/containerd/containerd/cio" "github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/log" - "github.com/sirupsen/logrus" runtime "k8s.io/cri-api/pkg/apis/runtime/v1" cio "github.com/containerd/containerd/pkg/cri/io" @@ -241,7 +240,7 @@ func (c *criService) createContainerLoggers(logPath string, tty bool) (stdout io if stderrCh != nil { <-stderrCh } - logrus.Debugf("Finish redirecting log file %q, closing it", logPath) + log.L.Debugf("Finish redirecting log file %q, closing it", logPath) f.Close() }() } else { diff --git a/pkg/cri/server/events.go b/pkg/cri/server/events.go index c7d31d5d8..675437018 100644 --- a/pkg/cri/server/events.go +++ b/pkg/cri/server/events.go @@ -28,6 +28,7 @@ import ( containerdio "github.com/containerd/containerd/cio" "github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/events" + "github.com/containerd/containerd/log" "github.com/containerd/containerd/pkg/cri/constants" containerstore "github.com/containerd/containerd/pkg/cri/store/container" sandboxstore "github.com/containerd/containerd/pkg/cri/store/sandbox" @@ -115,7 +116,7 @@ func (em *eventMonitor) startSandboxExitMonitor(ctx context.Context, id string, case exitRes := <-exitCh: exitStatus, exitedAt, err := exitRes.Result() if err != nil { - logrus.WithError(err).Errorf("failed to get task exit status for %q", id) + log.L.WithError(err).Errorf("failed to get task exit status for %q", id) exitStatus = unknownExitCode exitedAt = time.Now() } @@ -128,7 +129,7 @@ func (em *eventMonitor) startSandboxExitMonitor(ctx context.Context, id string, ExitedAt: protobuf.ToTimestamp(exitedAt), } - logrus.Debugf("received exit event %+v", e) + log.L.Debugf("received exit event %+v", e) err = func() error { dctx := ctrdutil.NamespacedContext() @@ -147,7 +148,7 @@ func (em *eventMonitor) startSandboxExitMonitor(ctx context.Context, id string, return nil }() if err != nil { - logrus.WithError(err).Errorf("failed to handle sandbox TaskExit event %+v", e) + log.L.WithError(err).Errorf("failed to handle sandbox TaskExit event %+v", e) em.backOff.enBackOff(id, e) } return @@ -166,7 +167,7 @@ func (em *eventMonitor) startContainerExitMonitor(ctx context.Context, id string case exitRes := <-exitCh: exitStatus, exitedAt, err := exitRes.Result() if err != nil { - logrus.WithError(err).Errorf("failed to get task exit status for %q", id) + log.L.WithError(err).Errorf("failed to get task exit status for %q", id) exitStatus = unknownExitCode exitedAt = time.Now() } @@ -179,7 +180,7 @@ func (em *eventMonitor) startContainerExitMonitor(ctx context.Context, id string ExitedAt: protobuf.ToTimestamp(exitedAt), } - logrus.Debugf("received exit event %+v", e) + log.L.Debugf("received exit event %+v", e) err = func() error { dctx := ctrdutil.NamespacedContext() @@ -198,7 +199,7 @@ func (em *eventMonitor) startContainerExitMonitor(ctx context.Context, id string return nil }() if err != nil { - logrus.WithError(err).Errorf("failed to handle container TaskExit event %+v", e) + log.L.WithError(err).Errorf("failed to handle container TaskExit event %+v", e) em.backOff.enBackOff(id, e) } return @@ -251,14 +252,14 @@ func (em *eventMonitor) start() <-chan error { for { select { case e := <-em.ch: - logrus.Debugf("Received containerd event timestamp - %v, namespace - %q, topic - %q", e.Timestamp, e.Namespace, e.Topic) + log.L.Debugf("Received containerd event timestamp - %v, namespace - %q, topic - %q", e.Timestamp, e.Namespace, e.Topic) if e.Namespace != constants.K8sContainerdNamespace { - logrus.Debugf("Ignoring events in namespace - %q", e.Namespace) + log.L.Debugf("Ignoring events in namespace - %q", e.Namespace) break } id, evt, err := convertEvent(e.Event) if err != nil { - logrus.WithError(err).Errorf("Failed to convert event %+v", e) + log.L.WithError(err).Errorf("Failed to convert event %+v", e) break } if em.backOff.isInBackOff(id) { diff --git a/pkg/cri/server/helpers.go b/pkg/cri/server/helpers.go index ca586f820..24519fd08 100644 --- a/pkg/cri/server/helpers.go +++ b/pkg/cri/server/helpers.go @@ -30,6 +30,7 @@ import ( "github.com/containerd/containerd/containers" "github.com/containerd/containerd/errdefs" clabels "github.com/containerd/containerd/labels" + "github.com/containerd/containerd/log" criconfig "github.com/containerd/containerd/pkg/cri/config" containerstore "github.com/containerd/containerd/pkg/cri/store/container" imagestore "github.com/containerd/containerd/pkg/cri/store/image" @@ -295,7 +296,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 @@ -517,7 +518,7 @@ func copyResourcesToStatus(spec *runtimespec.Spec, status containerstore.Status) func (c *criService) generateAndSendContainerEvent(ctx context.Context, containerID string, sandboxID string, eventType runtime.ContainerEventType) { podSandboxStatus, err := c.getPodSandboxStatus(ctx, sandboxID) if err != nil { - logrus.Warnf("Failed to get podSandbox status for container event for sandboxID %q: %v. Sending the event with nil podSandboxStatus.", sandboxID, err) + log.L.Warnf("Failed to get podSandbox status for container event for sandboxID %q: %v. Sending the event with nil podSandboxStatus.", sandboxID, err) podSandboxStatus = nil } containerStatuses, err := c.getContainerStatuses(ctx, sandboxID) diff --git a/pkg/cri/server/rdt_linux.go b/pkg/cri/server/rdt_linux.go index 5f982fb1b..5e83061a7 100644 --- a/pkg/cri/server/rdt_linux.go +++ b/pkg/cri/server/rdt_linux.go @@ -21,8 +21,7 @@ package server import ( "fmt" - "github.com/sirupsen/logrus" - + "github.com/containerd/containerd/log" "github.com/containerd/containerd/pkg/rdt" ) @@ -40,7 +39,7 @@ func (c *criService) rdtClassFromAnnotations(containerName string, containerAnno if err != nil { if !rdt.IsEnabled() && c.config.ContainerdConfig.IgnoreRdtNotEnabledErrors { - logrus.Debugf("continuing create container %s, ignoring rdt not enabled (%v)", containerName, err) + log.L.Debugf("continuing create container %s, ignoring rdt not enabled (%v)", containerName, err) return "", nil } return "", err diff --git a/pkg/cri/server/sandbox_remove.go b/pkg/cri/server/sandbox_remove.go index 2789fc16b..1541a0a67 100644 --- a/pkg/cri/server/sandbox_remove.go +++ b/pkg/cri/server/sandbox_remove.go @@ -25,7 +25,6 @@ import ( "github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/log" - "github.com/sirupsen/logrus" runtime "k8s.io/cri-api/pkg/apis/runtime/v1" ) @@ -50,7 +49,7 @@ func (c *criService) RemovePodSandbox(ctx context.Context, r *runtime.RemovePodS // If the sandbox is still running, not ready, or in an unknown state, forcibly stop it. // Even if it's in a NotReady state, this will close its network namespace, if open. // This can happen if the task process associated with the Pod died or it was killed. - logrus.Infof("Forcibly stopping sandbox %q", id) + log.L.Infof("Forcibly stopping sandbox %q", id) if err := c.stopPodSandbox(ctx, sandbox); err != nil { return nil, fmt.Errorf("failed to forcibly stop sandbox %q: %w", id, err) } diff --git a/pkg/cri/server/sandbox_run.go b/pkg/cri/server/sandbox_run.go index 91126535d..40cf75858 100644 --- a/pkg/cri/server/sandbox_run.go +++ b/pkg/cri/server/sandbox_run.go @@ -31,7 +31,6 @@ import ( "github.com/containerd/typeurl/v2" "github.com/davecgh/go-spew/spew" selinux "github.com/opencontainers/selinux/go-selinux" - "github.com/sirupsen/logrus" runtime "k8s.io/cri-api/pkg/apis/runtime/v1" "github.com/containerd/containerd" @@ -765,7 +764,7 @@ func (c *criService) getSandboxRuntime(config *runtime.PodSandboxConfig, runtime } func logDebugCNIResult(ctx context.Context, sandboxID string, result *cni.Result) { - if logrus.GetLevel() < logrus.DebugLevel { + if log.GetLevel() < log.DebugLevel { return } cniResult, err := json.Marshal(result) diff --git a/pkg/cri/server/service.go b/pkg/cri/server/service.go index c39bb5054..8ac36fb66 100644 --- a/pkg/cri/server/service.go +++ b/pkg/cri/server/service.go @@ -28,6 +28,7 @@ import ( "time" "github.com/containerd/containerd" + "github.com/containerd/containerd/log" "github.com/containerd/containerd/oci" "github.com/containerd/containerd/pkg/cri/instrument" "github.com/containerd/containerd/pkg/cri/nri" @@ -144,7 +145,7 @@ func NewCRIService(config criconfig.Config, client *containerd.Client, nri *nri. } c.imageFSPath = imageFSPath(config.ContainerdRootDir, config.ContainerdConfig.Snapshotter) - logrus.Infof("Get image filesystem path %q", c.imageFSPath) + log.L.Infof("Get image filesystem path %q", c.imageFSPath) if err := c.initPlatform(); err != nil { return nil, fmt.Errorf("initialize platform: %w", err) @@ -203,20 +204,20 @@ func (c *criService) RegisterTCP(s *grpc.Server) error { // Run starts the CRI service. func (c *criService) Run() error { - logrus.Info("Start subscribing containerd event") + log.L.Info("Start subscribing containerd event") c.eventMonitor.subscribe(c.client) - logrus.Infof("Start recovering state") + log.L.Infof("Start recovering state") if err := c.recover(ctrdutil.NamespacedContext()); err != nil { return fmt.Errorf("failed to recover state: %w", err) } // Start event handler. - logrus.Info("Start event monitor") + log.L.Info("Start event monitor") eventMonitorErrCh := c.eventMonitor.start() // Start snapshot stats syncer, it doesn't need to be stopped. - logrus.Info("Start snapshots syncer") + log.L.Info("Start snapshots syncer") snapshotsSyncer := newSnapshotsSyncer( c.snapshotStore, c.client.SnapshotService(c.config.ContainerdConfig.Snapshotter), @@ -229,7 +230,7 @@ func (c *criService) Run() error { var netSyncGroup sync.WaitGroup for name, h := range c.cniNetConfMonitor { netSyncGroup.Add(1) - logrus.Infof("Start cni network conf syncer for %s", name) + log.L.Infof("Start cni network conf syncer for %s", name) go func(h *cniNetConfSyncer) { cniNetConfMonitorErrCh <- h.syncLoop() netSyncGroup.Done() @@ -248,12 +249,12 @@ func (c *criService) Run() error { } // Start streaming server. - logrus.Info("Start streaming server") + log.L.Info("Start streaming server") streamServerErrCh := make(chan error) go func() { defer close(streamServerErrCh) if err := c.streamServer.Start(true); err != nil && err != http.ErrServerClosed { - logrus.WithError(err).Error("Failed to start streaming server") + log.L.WithError(err).Error("Failed to start streaming server") streamServerErrCh <- err } }() @@ -281,11 +282,11 @@ func (c *criService) Run() error { if err := <-eventMonitorErrCh; err != nil { eventMonitorErr = err } - logrus.Info("Event monitor stopped") + log.L.Info("Event monitor stopped") if err := <-streamServerErrCh; err != nil { streamServerErr = err } - logrus.Info("Stream server stopped") + log.L.Info("Stream server stopped") if eventMonitorErr != nil { return fmt.Errorf("event monitor error: %w", eventMonitorErr) } diff --git a/pkg/cri/server/service_linux.go b/pkg/cri/server/service_linux.go index 612bff87d..178b4540c 100644 --- a/pkg/cri/server/service_linux.go +++ b/pkg/cri/server/service_linux.go @@ -20,11 +20,11 @@ import ( "fmt" "github.com/container-orchestrated-devices/container-device-interface/pkg/cdi" + "github.com/containerd/containerd/log" "github.com/containerd/containerd/pkg/cap" "github.com/containerd/containerd/pkg/userns" cni "github.com/containerd/go-cni" "github.com/opencontainers/selinux/go-selinux" - "github.com/sirupsen/logrus" ) // networkAttachCount is the minimum number of networks the PodSandbox @@ -35,13 +35,13 @@ const networkAttachCount = 2 func (c *criService) initPlatform() (err error) { if userns.RunningInUserNS() { if !(c.config.DisableCgroup && !c.apparmorEnabled() && c.config.RestrictOOMScoreAdj) { - logrus.Warn("Running containerd in a user namespace typically requires disable_cgroup, disable_apparmor, restrict_oom_score_adj set to be true") + log.L.Warn("Running containerd in a user namespace typically requires disable_cgroup, disable_apparmor, restrict_oom_score_adj set to be true") } } if c.config.EnableSelinux { if !selinux.GetEnabled() { - logrus.Warn("Selinux is not supported") + log.L.Warn("Selinux is not supported") } if r := c.config.SelinuxCategoryRange; r > 0 { selinux.CategoryRange = uint32(r) diff --git a/pkg/cri/server/snapshots.go b/pkg/cri/server/snapshots.go index ed672752f..d86db5cdf 100644 --- a/pkg/cri/server/snapshots.go +++ b/pkg/cri/server/snapshots.go @@ -22,11 +22,10 @@ import ( "time" "github.com/containerd/containerd/errdefs" - snapshot "github.com/containerd/containerd/snapshots" - "github.com/sirupsen/logrus" - + "github.com/containerd/containerd/log" snapshotstore "github.com/containerd/containerd/pkg/cri/store/snapshot" ctrdutil "github.com/containerd/containerd/pkg/cri/util" + snapshot "github.com/containerd/containerd/snapshots" ) // snapshotsSyncer syncs snapshot stats periodically. imagefs info and container stats @@ -60,7 +59,7 @@ func (s *snapshotsSyncer) start() { // check the resource usage and optimize this. for { if err := s.sync(); err != nil { - logrus.WithError(err).Error("Failed to sync snapshot stats") + log.L.WithError(err).Error("Failed to sync snapshot stats") } <-tick.C } @@ -101,7 +100,7 @@ func (s *snapshotsSyncer) sync() error { usage, err := s.snapshotter.Usage(ctx, info.Name) if err != nil { if !errdefs.IsNotFound(err) { - logrus.WithError(err).Errorf("Failed to get usage for snapshot %q", info.Name) + log.L.WithError(err).Errorf("Failed to get usage for snapshot %q", info.Name) } continue } diff --git a/runtime/v2/runc/container.go b/runtime/v2/runc/container.go index 7536c206a..2ed5b5407 100644 --- a/runtime/v2/runc/container.go +++ b/runtime/v2/runc/container.go @@ -32,13 +32,13 @@ import ( "github.com/containerd/console" "github.com/containerd/containerd/api/runtime/task/v2" "github.com/containerd/containerd/errdefs" + "github.com/containerd/containerd/log" "github.com/containerd/containerd/mount" "github.com/containerd/containerd/namespaces" "github.com/containerd/containerd/pkg/process" "github.com/containerd/containerd/pkg/stdio" "github.com/containerd/containerd/runtime/v2/runc/options" "github.com/containerd/typeurl/v2" - "github.com/sirupsen/logrus" ) // NewContainer returns a new runc container @@ -111,7 +111,7 @@ func NewContainer(ctx context.Context, platform stdio.Platform, r *task.CreateTa defer func() { if retErr != nil { if err := mount.UnmountMounts(mounts, rootfs, 0); err != nil { - logrus.WithError(err).Warn("failed to cleanup rootfs mount") + log.G(ctx).WithError(err).Warn("failed to cleanup rootfs mount") } } }() @@ -148,17 +148,17 @@ func NewContainer(ctx context.Context, platform stdio.Platform, r *task.CreateTa if cgroups.Mode() == cgroups.Unified { g, err := cgroupsv2.PidGroupPath(pid) if err != nil { - logrus.WithError(err).Errorf("loading cgroup2 for %d", pid) + log.G(ctx).WithError(err).Errorf("loading cgroup2 for %d", pid) return container, nil } cg, err = cgroupsv2.Load(g) if err != nil { - logrus.WithError(err).Errorf("loading cgroup2 for %d", pid) + log.G(ctx).WithError(err).Errorf("loading cgroup2 for %d", pid) } } else { cg, err = cgroup1.Load(cgroup1.PidPath(pid)) if err != nil { - logrus.WithError(err).Errorf("loading cgroup for %d", pid) + log.G(ctx).WithError(err).Errorf("loading cgroup for %d", pid) } } container.cgroup = cg @@ -369,16 +369,16 @@ func (c *Container) Start(ctx context.Context, r *task.StartRequest) (process.Pr if cgroups.Mode() == cgroups.Unified { g, err := cgroupsv2.PidGroupPath(p.Pid()) if err != nil { - logrus.WithError(err).Errorf("loading cgroup2 for %d", p.Pid()) + log.G(ctx).WithError(err).Errorf("loading cgroup2 for %d", p.Pid()) } cg, err = cgroupsv2.Load(g) if err != nil { - logrus.WithError(err).Errorf("loading cgroup2 for %d", p.Pid()) + log.G(ctx).WithError(err).Errorf("loading cgroup2 for %d", p.Pid()) } } else { cg, err = cgroup1.Load(cgroup1.PidPath(p.Pid())) if err != nil { - logrus.WithError(err).Errorf("loading cgroup for %d", p.Pid()) + log.G(ctx).WithError(err).Errorf("loading cgroup for %d", p.Pid()) } } c.cgroup = cg diff --git a/runtime/v2/runc/pause/sandbox.go b/runtime/v2/runc/pause/sandbox.go index 2d79c22db..a85bfa989 100644 --- a/runtime/v2/runc/pause/sandbox.go +++ b/runtime/v2/runc/pause/sandbox.go @@ -23,9 +23,9 @@ import ( "runtime" "github.com/containerd/containerd/api/types" + "github.com/containerd/containerd/log" "github.com/containerd/containerd/pkg/shutdown" "github.com/containerd/ttrpc" - log "github.com/sirupsen/logrus" api "github.com/containerd/containerd/api/runtime/sandbox/v1" "github.com/containerd/containerd/plugin" @@ -64,17 +64,17 @@ func (p *pauseService) RegisterTTRPC(server *ttrpc.Server) error { } func (p *pauseService) CreateSandbox(ctx context.Context, req *api.CreateSandboxRequest) (*api.CreateSandboxResponse, error) { - log.Debugf("create sandbox request: %+v", req) + log.G(ctx).Debugf("create sandbox request: %+v", req) return &api.CreateSandboxResponse{}, nil } func (p *pauseService) StartSandbox(ctx context.Context, req *api.StartSandboxRequest) (*api.StartSandboxResponse, error) { - log.Debugf("start sandbox request: %+v", req) + log.G(ctx).Debugf("start sandbox request: %+v", req) return &api.StartSandboxResponse{}, nil } func (p *pauseService) Platform(ctx context.Context, req *api.PlatformRequest) (*api.PlatformResponse, error) { - log.Debugf("platform request: %+v", req) + log.G(ctx).Debugf("platform request: %+v", req) platform := types.Platform{ OS: runtime.GOOS, @@ -85,7 +85,7 @@ func (p *pauseService) Platform(ctx context.Context, req *api.PlatformRequest) ( } func (p *pauseService) StopSandbox(ctx context.Context, req *api.StopSandboxRequest) (*api.StopSandboxResponse, error) { - log.Debugf("stop sandbox request: %+v", req) + log.G(ctx).Debugf("stop sandbox request: %+v", req) p.shutdown.Shutdown() return &api.StopSandboxResponse{}, nil } @@ -97,7 +97,7 @@ func (p *pauseService) WaitSandbox(ctx context.Context, req *api.WaitSandboxRequ } func (p *pauseService) SandboxStatus(ctx context.Context, req *api.SandboxStatusRequest) (*api.SandboxStatusResponse, error) { - log.Debugf("sandbox status request: %+v", req) + log.G(ctx).Debugf("sandbox status request: %+v", req) return &api.SandboxStatusResponse{}, nil } diff --git a/runtime/v2/runc/task/service.go b/runtime/v2/runc/task/service.go index c281491b6..0e0f49705 100644 --- a/runtime/v2/runc/task/service.go +++ b/runtime/v2/runc/task/service.go @@ -31,6 +31,7 @@ import ( taskAPI "github.com/containerd/containerd/api/runtime/task/v2" "github.com/containerd/containerd/api/types/task" "github.com/containerd/containerd/errdefs" + "github.com/containerd/containerd/log" "github.com/containerd/containerd/namespaces" "github.com/containerd/containerd/pkg/oom" oomv1 "github.com/containerd/containerd/pkg/oom/v1" @@ -48,7 +49,6 @@ import ( runcC "github.com/containerd/go-runc" "github.com/containerd/ttrpc" "github.com/containerd/typeurl/v2" - "github.com/sirupsen/logrus" ) var ( @@ -170,23 +170,23 @@ func (s *service) Start(ctx context.Context, r *taskAPI.StartRequest) (*taskAPI. switch cg := container.Cgroup().(type) { case cgroup1.Cgroup: if err := s.ep.Add(container.ID, cg); err != nil { - logrus.WithError(err).Error("add cg to OOM monitor") + log.G(ctx).WithError(err).Error("add cg to OOM monitor") } case *cgroupsv2.Manager: allControllers, err := cg.RootControllers() if err != nil { - logrus.WithError(err).Error("failed to get root controllers") + log.G(ctx).WithError(err).Error("failed to get root controllers") } else { if err := cg.ToggleControllers(allControllers, cgroupsv2.Enable); err != nil { if userns.RunningInUserNS() { - logrus.WithError(err).Debugf("failed to enable controllers (%v)", allControllers) + log.G(ctx).WithError(err).Debugf("failed to enable controllers (%v)", allControllers) } else { - logrus.WithError(err).Errorf("failed to enable controllers (%v)", allControllers) + log.G(ctx).WithError(err).Errorf("failed to enable controllers (%v)", allControllers) } } } if err := s.ep.Add(container.ID, cg); err != nil { - logrus.WithError(err).Error("add cg to OOM monitor") + log.G(ctx).WithError(err).Error("add cg to OOM monitor") } } @@ -541,7 +541,7 @@ func (s *service) checkProcesses(e runcC.Exit) { // Ensure all children are killed if runc.ShouldKillAllOnExit(s.context, container.Bundle) { if err := ip.KillAll(s.context); err != nil { - logrus.WithError(err).WithField("id", ip.ID()). + log.L.WithError(err).WithField("id", ip.ID()). Error("failed to kill init's children") } } @@ -587,7 +587,7 @@ func (s *service) forward(ctx context.Context, publisher shim.Publisher) { for e := range s.events { err := publisher.Publish(ctx, runc.GetTopic(e), e) if err != nil { - logrus.WithError(err).Error("post event") + log.G(ctx).WithError(err).Error("post event") } } publisher.Close() diff --git a/runtime/v2/shim/publisher.go b/runtime/v2/shim/publisher.go index 5aa78a5d1..c90bf4d2a 100644 --- a/runtime/v2/shim/publisher.go +++ b/runtime/v2/shim/publisher.go @@ -23,11 +23,11 @@ import ( v1 "github.com/containerd/containerd/api/services/ttrpc/events/v1" "github.com/containerd/containerd/events" + "github.com/containerd/containerd/log" "github.com/containerd/containerd/namespaces" "github.com/containerd/containerd/pkg/ttrpcutil" "github.com/containerd/containerd/protobuf" "github.com/containerd/ttrpc" - "github.com/sirupsen/logrus" ) const ( @@ -83,13 +83,13 @@ func (l *RemoteEventsPublisher) Close() (err error) { func (l *RemoteEventsPublisher) processQueue() { for i := range l.requeue { if i.count > maxRequeue { - logrus.Errorf("evicting %s from queue because of retry count", i.ev.Topic) + log.L.Errorf("evicting %s from queue because of retry count", i.ev.Topic) // drop the event continue } if err := l.forwardRequest(i.ctx, &v1.ForwardRequest{Envelope: i.ev}); err != nil { - logrus.WithError(err).Error("forward event") + log.L.WithError(err).Error("forward event") l.queue(i) } } diff --git a/snapshots/btrfs/btrfs.go b/snapshots/btrfs/btrfs.go index a6a41e68e..b91f0cb63 100644 --- a/snapshots/btrfs/btrfs.go +++ b/snapshots/btrfs/btrfs.go @@ -33,8 +33,6 @@ import ( "github.com/containerd/containerd/plugin" "github.com/containerd/containerd/snapshots" "github.com/containerd/containerd/snapshots/storage" - - "github.com/sirupsen/logrus" ) type snapshotter struct { @@ -364,9 +362,9 @@ func (b *snapshotter) Remove(ctx context.Context, key string) (err error) { // Attempt to restore source if err1 := btrfs.SubvolSnapshot(source, removed, readonly); err1 != nil { log.G(ctx).WithFields(log.Fields{ - logrus.ErrorKey: err1, - "subvolume": source, - "renamed": removed, + "error": err1, + "subvolume": source, + "renamed": removed, }).Error("failed to restore subvolume from renamed") // Keep removed to allow for manual restore removed = "" diff --git a/snapshots/devmapper/pool_device_test.go b/snapshots/devmapper/pool_device_test.go index 02c5fec7c..da8abac1c 100644 --- a/snapshots/devmapper/pool_device_test.go +++ b/snapshots/devmapper/pool_device_test.go @@ -26,11 +26,11 @@ import ( "testing" "time" + "github.com/containerd/containerd/log" "github.com/containerd/containerd/mount" "github.com/containerd/containerd/pkg/testutil" "github.com/containerd/containerd/snapshots/devmapper/dmsetup" "github.com/docker/go-units" - "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" exec "golang.org/x/sys/execabs" ) @@ -57,7 +57,7 @@ const ( func TestPoolDevice(t *testing.T) { testutil.RequiresRoot(t) - logrus.SetLevel(logrus.DebugLevel) + assert.NoError(t, log.SetLevel("debug")) ctx := context.Background() tempDir := t.TempDir()