Switch all logging to use containerd log pkg

This unifies our logging and allows us to propagate logging and trace
contexts together.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff
2023-06-23 00:33:17 +00:00
parent 8d070e30f5
commit 74da6a6363
304 changed files with 2062 additions and 1826 deletions

View File

@@ -3,12 +3,14 @@
package daemon // import "github.com/docker/docker/daemon"
import (
"context"
"fmt"
"os"
"path/filepath"
"strconv"
"syscall"
"github.com/containerd/containerd/log"
"github.com/docker/docker/container"
"github.com/docker/docker/daemon/config"
"github.com/docker/docker/daemon/links"
@@ -184,7 +186,7 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
for _, s := range c.SecretReferences {
// TODO (ehazlett): use type switch when more are supported
if s.File == nil {
logrus.Error("secret target type is not a file target")
log.G(context.TODO()).Error("secret target type is not a file target")
continue
}
@@ -198,7 +200,7 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
return errors.Wrap(err, "error creating secret mount path")
}
logrus.WithFields(logrus.Fields{
log.G(context.TODO()).WithFields(logrus.Fields{
"name": s.File.Name,
"path": fPath,
}).Debug("injecting secret")
@@ -234,7 +236,7 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
// a valid type of config so we should not error when we encounter
// one.
if configRef.Runtime == nil {
logrus.Error("config target type is not a file or runtime target")
log.G(context.TODO()).Error("config target type is not a file or runtime target")
}
// However, in any case, this isn't a file config, so we have no
// further work to do
@@ -249,7 +251,7 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
return errors.Wrap(err, "error creating config mount path")
}
logrus.WithFields(logrus.Fields{
log.G(context.TODO()).WithFields(logrus.Fields{
"name": configRef.File.Name,
"path": fPath,
}).Debug("injecting config")
@@ -309,7 +311,7 @@ func (daemon *Daemon) remountSecretDir(c *container.Container) error {
return errors.Wrap(err, "error getting container secrets path")
}
if err := label.Relabel(dir, c.MountLabel, false); err != nil {
logrus.WithError(err).WithField("dir", dir).Warn("Error while attempting to set selinux label")
log.G(context.TODO()).WithError(err).WithField("dir", dir).Warn("Error while attempting to set selinux label")
}
rootIDs := daemon.idMapping.RootPair()
tmpfsOwnership := fmt.Sprintf("uid=%d,gid=%d", rootIDs.UID, rootIDs.GID)
@@ -325,13 +327,13 @@ func (daemon *Daemon) remountSecretDir(c *container.Container) error {
func (daemon *Daemon) cleanupSecretDir(c *container.Container) {
dir, err := c.SecretMountPath()
if err != nil {
logrus.WithError(err).WithField("container", c.ID).Warn("error getting secrets mount path for container")
log.G(context.TODO()).WithError(err).WithField("container", c.ID).Warn("error getting secrets mount path for container")
}
if err := mount.RecursiveUnmount(dir); err != nil {
logrus.WithField("dir", dir).WithError(err).Warn("Error while attempting to unmount dir, this may prevent removal of container.")
log.G(context.TODO()).WithField("dir", dir).WithError(err).Warn("Error while attempting to unmount dir, this may prevent removal of container.")
}
if err := os.RemoveAll(dir); err != nil {
logrus.WithField("dir", dir).WithError(err).Error("Error removing dir.")
log.G(context.TODO()).WithField("dir", dir).WithError(err).Error("Error removing dir.")
}
}
@@ -347,7 +349,7 @@ func killProcessDirectly(container *container.Container) error {
return errdefs.System(err)
}
err = errNoSuchProcess{pid, syscall.SIGKILL}
logrus.WithError(err).WithField("container", container.ID).Debug("no such process")
log.G(context.TODO()).WithError(err).WithField("container", container.ID).Debug("no such process")
return err
}
@@ -356,7 +358,7 @@ func killProcessDirectly(container *container.Container) error {
// Since we can not kill a zombie pid, add zombie check here
isZombie, err := process.Zombie(pid)
if err != nil {
logrus.WithError(err).WithField("container", container.ID).Warn("Container state is invalid")
log.G(context.TODO()).WithError(err).WithField("container", container.ID).Warn("Container state is invalid")
return err
}
if isZombie {