Merge pull request #8481 from mxpv/logrus

Cleanup logrus imports
This commit is contained in:
Maksym Pavlenko 2023-05-05 18:21:55 -07:00 committed by GitHub
commit 98f48d485d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
54 changed files with 237 additions and 248 deletions

View File

@ -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()
}

View File

@ -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)

View File

@ -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

View File

@ -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,

View File

@ -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
}

View File

@ -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()
}

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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)))
}

View File

@ -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()

View File

@ -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)
}
}
}()

View File

@ -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)

View File

@ -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)

View File

@ -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
}
}

View File

@ -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)

View File

@ -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))

View File

@ -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
}

View File

@ -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

View File

@ -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

View File

@ -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 {

View File

@ -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
}

View File

@ -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")
}
}

View File

@ -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)
}

View File

@ -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
}
}

View File

@ -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)
}

View File

@ -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 {

View File

@ -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

View File

@ -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)
}
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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

View File

@ -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)
}

View File

@ -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)

View File

@ -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()

View File

@ -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)

View File

@ -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)
}

View File

@ -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
}
}

View File

@ -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)
}

View File

@ -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 {

View File

@ -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) {

View File

@ -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)

View File

@ -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

View File

@ -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)
}

View File

@ -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)

View File

@ -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)
}

View File

@ -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)

View File

@ -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
}

View File

@ -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

View File

@ -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
}

View File

@ -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()

View File

@ -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)
}
}

View File

@ -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 = ""

View File

@ -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()