remove more direct uses of logrus
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
a07f6470b7
commit
bd523abd44
24 changed files with 96 additions and 92 deletions
|
@ -916,15 +916,19 @@ func systemContainerdRunning(honorXDG bool) (string, bool, error) {
|
||||||
func configureDaemonLogs(conf *config.Config) {
|
func configureDaemonLogs(conf *config.Config) {
|
||||||
switch log.OutputFormat(conf.LogFormat) {
|
switch log.OutputFormat(conf.LogFormat) {
|
||||||
case log.JSONFormat:
|
case log.JSONFormat:
|
||||||
logrus.SetFormatter(&logrus.JSONFormatter{
|
if err := log.SetFormat(log.JSONFormat); err != nil {
|
||||||
TimestampFormat: log.RFC3339NanoFixed,
|
panic(err.Error())
|
||||||
})
|
}
|
||||||
case log.TextFormat, "":
|
case log.TextFormat, "":
|
||||||
logrus.SetFormatter(&logrus.TextFormatter{
|
if err := log.SetFormat(log.TextFormat); err != nil {
|
||||||
TimestampFormat: log.RFC3339NanoFixed,
|
panic(err.Error())
|
||||||
DisableColors: conf.RawLogs,
|
}
|
||||||
FullTimestamp: true,
|
if conf.RawLogs {
|
||||||
})
|
// FIXME(thaJeztah): this needs a better solution: containerd doesn't allow disabling colors, and this code is depending on internal knowledge of "log.SetFormat"
|
||||||
|
if l, ok := log.L.Logger.Formatter.(*logrus.TextFormatter); ok {
|
||||||
|
l.DisableColors = true
|
||||||
|
}
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
panic("unsupported log format " + conf.LogFormat)
|
panic("unsupported log format " + conf.LogFormat)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/docker/docker/daemon/config"
|
"github.com/docker/docker/daemon/config"
|
||||||
"github.com/google/go-cmp/cmp/cmpopts"
|
"github.com/google/go-cmp/cmp/cmpopts"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
is "gotest.tools/v3/assert/cmp"
|
is "gotest.tools/v3/assert/cmp"
|
||||||
|
@ -221,8 +220,7 @@ func TestConfigureDaemonLogs(t *testing.T) {
|
||||||
|
|
||||||
conf.LogLevel = "warn"
|
conf.LogLevel = "warn"
|
||||||
configureDaemonLogs(conf)
|
configureDaemonLogs(conf)
|
||||||
// TODO (thaJeztah): add more aliases in log package
|
assert.Check(t, is.Equal(log.WarnLevel, log.GetLevel()))
|
||||||
assert.Check(t, is.Equal(logrus.WarnLevel, log.GetLevel()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCDISpecDirs(t *testing.T) {
|
func TestCDISpecDirs(t *testing.T) {
|
||||||
|
|
|
@ -13,7 +13,6 @@ import (
|
||||||
"github.com/docker/docker/pkg/rootless"
|
"github.com/docker/docker/pkg/rootless"
|
||||||
"github.com/moby/buildkit/util/apicaps"
|
"github.com/moby/buildkit/util/apicaps"
|
||||||
"github.com/moby/term"
|
"github.com/moby/term"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -82,23 +81,22 @@ func main() {
|
||||||
// Fixes https://github.com/docker/docker/issues/19728
|
// Fixes https://github.com/docker/docker/issues/19728
|
||||||
signal.Ignore(syscall.SIGPIPE)
|
signal.Ignore(syscall.SIGPIPE)
|
||||||
|
|
||||||
// initial log formatting; this setting is updated after the daemon configuration is loaded.
|
|
||||||
logrus.SetFormatter(&logrus.TextFormatter{
|
|
||||||
TimestampFormat: log.RFC3339NanoFixed,
|
|
||||||
FullTimestamp: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
// Set terminal emulation based on platform as required.
|
// Set terminal emulation based on platform as required.
|
||||||
_, stdout, stderr := term.StdStreams()
|
_, stdout, stderr := term.StdStreams()
|
||||||
|
|
||||||
initLogging(stdout, stderr)
|
|
||||||
configureGRPCLog()
|
|
||||||
|
|
||||||
onError := func(err error) {
|
onError := func(err error) {
|
||||||
fmt.Fprintf(stderr, "%s\n", err)
|
fmt.Fprintf(stderr, "%s\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// initial log formatting; this setting is updated after the daemon configuration is loaded.
|
||||||
|
err := log.SetFormat(log.TextFormat)
|
||||||
|
if err != nil {
|
||||||
|
onError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
initLogging(stdout, stderr)
|
||||||
|
configureGRPCLog()
|
||||||
|
|
||||||
cmd, err := newDaemonCommand()
|
cmd, err := newDaemonCommand()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
onError(err)
|
onError(err)
|
||||||
|
|
|
@ -5,7 +5,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/containerd/containerd/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func runDaemon(opts *daemonOptions) error {
|
func runDaemon(opts *daemonOptions) error {
|
||||||
|
@ -14,5 +14,5 @@ func runDaemon(opts *daemonOptions) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func initLogging(_, stderr io.Writer) {
|
func initLogging(_, stderr io.Writer) {
|
||||||
logrus.SetOutput(stderr)
|
log.L.Logger.SetOutput(stderr)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/Microsoft/go-winio/pkg/etwlogrus"
|
"github.com/Microsoft/go-winio/pkg/etwlogrus"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/containerd/containerd/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func runDaemon(opts *daemonOptions) error {
|
func runDaemon(opts *daemonOptions) error {
|
||||||
|
@ -41,13 +41,13 @@ func runDaemon(opts *daemonOptions) error {
|
||||||
func initLogging(stdout, _ io.Writer) {
|
func initLogging(stdout, _ io.Writer) {
|
||||||
// Maybe there is a historic reason why on non-Windows, stderr is used
|
// Maybe there is a historic reason why on non-Windows, stderr is used
|
||||||
// for output. However, on Windows it makes no sense and there is no need.
|
// for output. However, on Windows it makes no sense and there is no need.
|
||||||
logrus.SetOutput(stdout)
|
log.L.Logger.SetOutput(stdout)
|
||||||
|
|
||||||
// Provider ID: {6996f090-c5de-5082-a81e-5841acc3a635}
|
// Provider ID: {6996f090-c5de-5082-a81e-5841acc3a635}
|
||||||
// Hook isn't closed explicitly, as it will exist until process exit.
|
// Hook isn't closed explicitly, as it will exist until process exit.
|
||||||
// GUID is generated based on name - see Microsoft/go-winio/tools/etw-provider-gen.
|
// GUID is generated based on name - see Microsoft/go-winio/tools/etw-provider-gen.
|
||||||
if hook, err := etwlogrus.NewHook("Moby"); err == nil {
|
if hook, err := etwlogrus.NewHook("Moby"); err == nil {
|
||||||
logrus.AddHook(hook)
|
log.L.Logger.AddHook(hook)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"google.golang.org/grpc/grpclog"
|
"google.golang.org/grpc/grpclog"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -16,5 +15,5 @@ import (
|
||||||
// error => warn
|
// error => warn
|
||||||
func configureGRPCLog() {
|
func configureGRPCLog() {
|
||||||
l := log.G(context.TODO()).WithField("library", "grpc")
|
l := log.G(context.TODO()).WithField("library", "grpc")
|
||||||
grpclog.SetLoggerV2(grpclog.NewLoggerV2(l.WriterLevel(logrus.TraceLevel), l.WriterLevel(logrus.DebugLevel), l.WriterLevel(logrus.WarnLevel)))
|
grpclog.SetLoggerV2(grpclog.NewLoggerV2(l.WriterLevel(log.TraceLevel), l.WriterLevel(log.DebugLevel), l.WriterLevel(log.WarnLevel)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,6 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
|
@ -63,40 +61,40 @@ type etwHook struct {
|
||||||
log *eventlog.Log
|
log *eventlog.Log
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *etwHook) Levels() []logrus.Level {
|
func (h *etwHook) Levels() []log.Level {
|
||||||
return []logrus.Level{
|
return []log.Level{
|
||||||
logrus.PanicLevel,
|
log.PanicLevel,
|
||||||
logrus.FatalLevel,
|
log.FatalLevel,
|
||||||
logrus.ErrorLevel,
|
log.ErrorLevel,
|
||||||
logrus.WarnLevel,
|
log.WarnLevel,
|
||||||
logrus.InfoLevel,
|
log.InfoLevel,
|
||||||
logrus.DebugLevel,
|
log.DebugLevel,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *etwHook) Fire(e *logrus.Entry) error {
|
func (h *etwHook) Fire(e *log.Entry) error {
|
||||||
var (
|
var (
|
||||||
etype uint16
|
etype uint16
|
||||||
eid uint32
|
eid uint32
|
||||||
)
|
)
|
||||||
|
|
||||||
switch e.Level {
|
switch e.Level {
|
||||||
case logrus.PanicLevel:
|
case log.PanicLevel:
|
||||||
etype = windows.EVENTLOG_ERROR_TYPE
|
etype = windows.EVENTLOG_ERROR_TYPE
|
||||||
eid = eventPanic
|
eid = eventPanic
|
||||||
case logrus.FatalLevel:
|
case log.FatalLevel:
|
||||||
etype = windows.EVENTLOG_ERROR_TYPE
|
etype = windows.EVENTLOG_ERROR_TYPE
|
||||||
eid = eventFatal
|
eid = eventFatal
|
||||||
case logrus.ErrorLevel:
|
case log.ErrorLevel:
|
||||||
etype = windows.EVENTLOG_ERROR_TYPE
|
etype = windows.EVENTLOG_ERROR_TYPE
|
||||||
eid = eventError
|
eid = eventError
|
||||||
case logrus.WarnLevel:
|
case log.WarnLevel:
|
||||||
etype = windows.EVENTLOG_WARNING_TYPE
|
etype = windows.EVENTLOG_WARNING_TYPE
|
||||||
eid = eventWarn
|
eid = eventWarn
|
||||||
case logrus.InfoLevel:
|
case log.InfoLevel:
|
||||||
etype = windows.EVENTLOG_INFORMATION_TYPE
|
etype = windows.EVENTLOG_INFORMATION_TYPE
|
||||||
eid = eventInfo
|
eid = eventInfo
|
||||||
case logrus.DebugLevel:
|
case log.DebugLevel:
|
||||||
etype = windows.EVENTLOG_INFORMATION_TYPE
|
etype = windows.EVENTLOG_INFORMATION_TYPE
|
||||||
eid = eventDebug
|
eid = eventDebug
|
||||||
default:
|
default:
|
||||||
|
@ -246,16 +244,16 @@ func initService(daemonCli *DaemonCli) (bool, bool, error) {
|
||||||
daemonCli: daemonCli,
|
daemonCli: daemonCli,
|
||||||
}
|
}
|
||||||
|
|
||||||
var log *eventlog.Log
|
var eventLog *eventlog.Log
|
||||||
if isService {
|
if isService {
|
||||||
log, err = eventlog.Open(*flServiceName)
|
eventLog, err = eventlog.Open(*flServiceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, false, err
|
return false, false, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.AddHook(&etwHook{log})
|
log.L.Logger.AddHook(&etwHook{eventLog})
|
||||||
logrus.SetOutput(io.Discard)
|
log.L.Logger.SetOutput(io.Discard)
|
||||||
|
|
||||||
service = h
|
service = h
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -373,7 +371,7 @@ func initPanicFile(path string) error {
|
||||||
os.Stderr = os.NewFile(panicFile.Fd(), "/dev/stderr")
|
os.Stderr = os.NewFile(panicFile.Fd(), "/dev/stderr")
|
||||||
|
|
||||||
// Force threads that panic to write to stderr (the panicFile handle now), otherwise it will go into the ether
|
// Force threads that panic to write to stderr (the panicFile handle now), otherwise it will go into the ether
|
||||||
logrus.SetOutput(os.Stderr)
|
log.L.Logger.SetOutput(os.Stderr)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ import (
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
"github.com/moby/swarmkit/v2/api"
|
"github.com/moby/swarmkit/v2/api"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Controller is the controller for the plugin backend.
|
// Controller is the controller for the plugin backend.
|
||||||
|
@ -31,7 +30,7 @@ import (
|
||||||
type Controller struct {
|
type Controller struct {
|
||||||
backend Backend
|
backend Backend
|
||||||
spec runtime.PluginSpec
|
spec runtime.PluginSpec
|
||||||
logger *logrus.Entry
|
logger *log.Entry
|
||||||
|
|
||||||
pluginID string
|
pluginID string
|
||||||
serviceID string
|
serviceID string
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/distribution/reference"
|
"github.com/distribution/reference"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/registry"
|
"github.com/docker/docker/api/types/registry"
|
||||||
|
@ -321,7 +322,7 @@ func TestRemove(t *testing.T) {
|
||||||
|
|
||||||
func newTestController(b Backend, disabled bool) *Controller {
|
func newTestController(b Backend, disabled bool) *Controller {
|
||||||
return &Controller{
|
return &Controller{
|
||||||
logger: &logrus.Entry{Logger: &logrus.Logger{Out: io.Discard}},
|
logger: &log.Entry{Logger: &logrus.Logger{Out: io.Discard}},
|
||||||
backend: b,
|
backend: b,
|
||||||
spec: runtime.PluginSpec{
|
spec: runtime.PluginSpec{
|
||||||
Name: pluginTestName,
|
Name: pluginTestName,
|
||||||
|
|
|
@ -19,7 +19,6 @@ import (
|
||||||
"github.com/docker/docker/registry"
|
"github.com/docker/docker/registry"
|
||||||
"github.com/imdario/mergo"
|
"github.com/imdario/mergo"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -586,7 +585,12 @@ func findConfigurationConflicts(config map[string]interface{}, flags *pflag.Flag
|
||||||
func Validate(config *Config) error {
|
func Validate(config *Config) error {
|
||||||
// validate log-level
|
// validate log-level
|
||||||
if config.LogLevel != "" {
|
if config.LogLevel != "" {
|
||||||
if _, err := logrus.ParseLevel(config.LogLevel); err != nil {
|
// FIXME(thaJeztah): find a better way for this; this depends on knowledge of containerd's log package internals.
|
||||||
|
// Alternatively: try log.SetLevel(config.LogLevel), and restore the original level, but this also requires internal knowledge.
|
||||||
|
switch strings.ToLower(config.LogLevel) {
|
||||||
|
case "panic", "fatal", "error", "warn", "info", "debug", "trace":
|
||||||
|
// These are valid. See [log.SetLevel] for a list of accepted levels.
|
||||||
|
default:
|
||||||
return errors.Errorf("invalid logging level: %s", config.LogLevel)
|
return errors.Errorf("invalid logging level: %s", config.LogLevel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ func TestContainerWarningHostAndPublishPorts(t *testing.T) {
|
||||||
"8080": []nat.PortBinding{{HostPort: "8989"}},
|
"8080": []nat.PortBinding{{HostPort: "8989"}},
|
||||||
}, warnings: []string{"Published ports are discarded when using host network mode"}},
|
}, warnings: []string{"Published ports are discarded when using host network mode"}},
|
||||||
}
|
}
|
||||||
muteLogs()
|
muteLogs(t)
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
hostConfig := &containertypes.HostConfig{
|
hostConfig := &containertypes.HostConfig{
|
||||||
|
|
|
@ -17,8 +17,6 @@ import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
"github.com/containerd/containerd/defaults"
|
"github.com/containerd/containerd/defaults"
|
||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
|
@ -358,7 +356,7 @@ func (daemon *Daemon) restore(cfg *configStore) error {
|
||||||
|
|
||||||
daemon.setStateCounter(c)
|
daemon.setStateCounter(c)
|
||||||
|
|
||||||
logger := func(c *container.Container) *logrus.Entry {
|
logger := func(c *container.Container) *log.Entry {
|
||||||
return baseLogger.WithFields(log.Fields{
|
return baseLogger.WithFields(log.Fields{
|
||||||
"running": c.IsRunning(),
|
"running": c.IsRunning(),
|
||||||
"paused": c.IsPaused(),
|
"paused": c.IsPaused(),
|
||||||
|
|
|
@ -69,7 +69,7 @@ func TestAdjustCPUShares(t *testing.T) {
|
||||||
root: tmp,
|
root: tmp,
|
||||||
}
|
}
|
||||||
cfg := &config.Config{}
|
cfg := &config.Config{}
|
||||||
muteLogs()
|
muteLogs(t)
|
||||||
|
|
||||||
hostConfig := &containertypes.HostConfig{
|
hostConfig := &containertypes.HostConfig{
|
||||||
Resources: containertypes.Resources{CPUShares: linuxMinCPUShares - 1},
|
Resources: containertypes.Resources{CPUShares: linuxMinCPUShares - 1},
|
||||||
|
|
|
@ -11,12 +11,12 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/containerd/containerd/log"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GenerateID creates a new random string identifier with the given length
|
// GenerateID creates a new random string identifier with the given length
|
||||||
func GenerateID(l int, logger *logrus.Entry) string {
|
func GenerateID(l int, logger *log.Entry) string {
|
||||||
const (
|
const (
|
||||||
// ensures we backoff for less than 450ms total. Use the following to
|
// ensures we backoff for less than 450ms total. Use the following to
|
||||||
// select new value, in units of 10ms:
|
// select new value, in units of 10ms:
|
||||||
|
|
|
@ -78,7 +78,7 @@ func TestHealthStates(t *testing.T) {
|
||||||
EventsService: e,
|
EventsService: e,
|
||||||
containersReplica: store,
|
containersReplica: store,
|
||||||
}
|
}
|
||||||
muteLogs()
|
muteLogs(t)
|
||||||
|
|
||||||
c.Config.Healthcheck = &containertypes.HealthConfig{
|
c.Config.Healthcheck = &containertypes.HealthConfig{
|
||||||
Retries: 1,
|
Retries: 1,
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/docker/docker/daemon/logger"
|
"github.com/docker/docker/daemon/logger"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type follow struct {
|
type follow struct {
|
||||||
|
@ -18,7 +17,7 @@ type follow struct {
|
||||||
Decoder Decoder
|
Decoder Decoder
|
||||||
Forwarder *forwarder
|
Forwarder *forwarder
|
||||||
|
|
||||||
log *logrus.Entry
|
log *log.Entry
|
||||||
c chan logPos
|
c chan logPos
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,18 +5,22 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/docker/docker/daemon/config"
|
"github.com/docker/docker/daemon/config"
|
||||||
"github.com/docker/docker/daemon/images"
|
"github.com/docker/docker/daemon/images"
|
||||||
"github.com/docker/docker/libnetwork"
|
"github.com/docker/docker/libnetwork"
|
||||||
"github.com/docker/docker/registry"
|
"github.com/docker/docker/registry"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
is "gotest.tools/v3/assert/cmp"
|
is "gotest.tools/v3/assert/cmp"
|
||||||
)
|
)
|
||||||
|
|
||||||
// muteLogs suppresses logs that are generated during the test
|
// muteLogs suppresses logs that are generated during the test
|
||||||
func muteLogs() {
|
func muteLogs(t *testing.T) {
|
||||||
logrus.SetLevel(logrus.ErrorLevel)
|
t.Helper()
|
||||||
|
err := log.SetLevel("error")
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDaemonForReloadT(t *testing.T, cfg *config.Config) *Daemon {
|
func newDaemonForReloadT(t *testing.T, cfg *config.Config) *Daemon {
|
||||||
|
@ -37,7 +41,7 @@ func TestDaemonReloadLabels(t *testing.T) {
|
||||||
Labels: []string{"foo:bar"},
|
Labels: []string{"foo:bar"},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
muteLogs()
|
muteLogs(t)
|
||||||
|
|
||||||
valuesSets := make(map[string]interface{})
|
valuesSets := make(map[string]interface{})
|
||||||
valuesSets["labels"] = "foo:baz"
|
valuesSets["labels"] = "foo:baz"
|
||||||
|
@ -60,7 +64,7 @@ func TestDaemonReloadLabels(t *testing.T) {
|
||||||
|
|
||||||
func TestDaemonReloadAllowNondistributableArtifacts(t *testing.T) {
|
func TestDaemonReloadAllowNondistributableArtifacts(t *testing.T) {
|
||||||
daemon := newDaemonForReloadT(t, &config.Config{})
|
daemon := newDaemonForReloadT(t, &config.Config{})
|
||||||
muteLogs()
|
muteLogs(t)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
// Initialize daemon with some registries.
|
// Initialize daemon with some registries.
|
||||||
|
@ -116,7 +120,7 @@ func TestDaemonReloadMirrors(t *testing.T) {
|
||||||
daemon := &Daemon{
|
daemon := &Daemon{
|
||||||
imageService: images.NewImageService(images.ImageServiceConfig{}),
|
imageService: images.NewImageService(images.ImageServiceConfig{}),
|
||||||
}
|
}
|
||||||
muteLogs()
|
muteLogs(t)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
daemon.registryService, err = registry.NewService(registry.ServiceOptions{
|
daemon.registryService, err = registry.NewService(registry.ServiceOptions{
|
||||||
|
@ -215,7 +219,7 @@ func TestDaemonReloadInsecureRegistries(t *testing.T) {
|
||||||
daemon := &Daemon{
|
daemon := &Daemon{
|
||||||
imageService: images.NewImageService(images.ImageServiceConfig{}),
|
imageService: images.NewImageService(images.ImageServiceConfig{}),
|
||||||
}
|
}
|
||||||
muteLogs()
|
muteLogs(t)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
// initialize daemon with existing insecure registries: "127.0.0.0/8", "10.10.1.11:5000", "10.10.1.22:5000"
|
// initialize daemon with existing insecure registries: "127.0.0.0/8", "10.10.1.11:5000", "10.10.1.22:5000"
|
||||||
|
@ -316,7 +320,7 @@ func TestDaemonReloadNotAffectOthers(t *testing.T) {
|
||||||
Debug: true,
|
Debug: true,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
muteLogs()
|
muteLogs(t)
|
||||||
|
|
||||||
valuesSets := make(map[string]interface{})
|
valuesSets := make(map[string]interface{})
|
||||||
valuesSets["labels"] = "foo:baz"
|
valuesSets["labels"] = "foo:baz"
|
||||||
|
|
|
@ -15,8 +15,6 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
"github.com/Microsoft/hcsshim"
|
"github.com/Microsoft/hcsshim"
|
||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
"github.com/containerd/containerd/cio"
|
"github.com/containerd/containerd/cio"
|
||||||
|
@ -81,7 +79,7 @@ const defaultOwner = "docker"
|
||||||
type client struct {
|
type client struct {
|
||||||
stateDir string
|
stateDir string
|
||||||
backend libcontainerdtypes.Backend
|
backend libcontainerdtypes.Backend
|
||||||
logger *logrus.Entry
|
logger *log.Entry
|
||||||
eventQ queue.Queue
|
eventQ queue.Queue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,6 @@ import (
|
||||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
)
|
)
|
||||||
|
@ -44,7 +43,7 @@ const DockerContainerBundlePath = "com.docker/engine.bundle.path"
|
||||||
type client struct {
|
type client struct {
|
||||||
client *containerd.Client
|
client *containerd.Client
|
||||||
stateDir string
|
stateDir string
|
||||||
logger *logrus.Entry
|
logger *log.Entry
|
||||||
ns string
|
ns string
|
||||||
|
|
||||||
backend libcontainerdtypes.Backend
|
backend libcontainerdtypes.Backend
|
||||||
|
|
|
@ -14,7 +14,6 @@ import (
|
||||||
libcontainerdtypes "github.com/docker/docker/libcontainerd/types"
|
libcontainerdtypes "github.com/docker/docker/libcontainerd/types"
|
||||||
"github.com/docker/docker/pkg/idtools"
|
"github.com/docker/docker/pkg/idtools"
|
||||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func summaryFromInterface(i interface{}) (*libcontainerdtypes.Summary, error) {
|
func summaryFromInterface(i interface{}) (*libcontainerdtypes.Summary, error) {
|
||||||
|
@ -86,7 +85,7 @@ func WithBundle(bundleDir string, ociSpec *specs.Spec) containerd.NewContainerOp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func withLogLevel(_ logrus.Level) containerd.NewTaskOpts {
|
func withLogLevel(_ log.Level) containerd.NewTaskOpts {
|
||||||
panic("Not implemented")
|
panic("Not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,10 +10,10 @@ import (
|
||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
"github.com/containerd/containerd/cio"
|
"github.com/containerd/containerd/cio"
|
||||||
"github.com/containerd/containerd/containers"
|
"github.com/containerd/containerd/containers"
|
||||||
|
"github.com/containerd/containerd/log"
|
||||||
libcontainerdtypes "github.com/docker/docker/libcontainerd/types"
|
libcontainerdtypes "github.com/docker/docker/libcontainerd/types"
|
||||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func summaryFromInterface(i interface{}) (*libcontainerdtypes.Summary, error) {
|
func summaryFromInterface(i interface{}) (*libcontainerdtypes.Summary, error) {
|
||||||
|
@ -47,10 +47,10 @@ func WithBundle(bundleDir string, ociSpec *specs.Spec) containerd.NewContainerOp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func withLogLevel(level logrus.Level) containerd.NewTaskOpts {
|
func withLogLevel(level log.Level) containerd.NewTaskOpts {
|
||||||
// Make sure we set the runhcs options to debug if we are at debug level.
|
// Make sure we set the runhcs options to debug if we are at debug level.
|
||||||
return func(_ context.Context, _ *containerd.Client, info *containerd.TaskInfo) error {
|
return func(_ context.Context, _ *containerd.Client, info *containerd.TaskInfo) error {
|
||||||
if level == logrus.DebugLevel {
|
if level == log.DebugLevel {
|
||||||
info.Options = &options.Options{Debug: true}
|
info.Options = &options.Options{Debug: true}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -19,7 +19,6 @@ import (
|
||||||
"github.com/docker/docker/pkg/system"
|
"github.com/docker/docker/pkg/system"
|
||||||
"github.com/pelletier/go-toml"
|
"github.com/pelletier/go-toml"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/credentials/insecure"
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
|
@ -44,7 +43,7 @@ type remote struct {
|
||||||
|
|
||||||
daemonPid int
|
daemonPid int
|
||||||
pidFile string
|
pidFile string
|
||||||
logger *logrus.Entry
|
logger *log.Entry
|
||||||
|
|
||||||
daemonWaitCh chan struct{}
|
daemonWaitCh chan struct{}
|
||||||
daemonStartCh chan error
|
daemonStartCh chan error
|
||||||
|
|
|
@ -15,7 +15,6 @@ import (
|
||||||
libcontainerdtypes "github.com/docker/docker/libcontainerd/types"
|
libcontainerdtypes "github.com/docker/docker/libcontainerd/types"
|
||||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ExitHandler represents an object that is called when the exit event is received from containerd
|
// ExitHandler represents an object that is called when the exit event is received from containerd
|
||||||
|
@ -54,7 +53,7 @@ type Executor struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type c8dPlugin struct {
|
type c8dPlugin struct {
|
||||||
log *logrus.Entry
|
log *log.Entry
|
||||||
ctr libcontainerdtypes.Container
|
ctr libcontainerdtypes.Container
|
||||||
tsk libcontainerdtypes.Task
|
tsk libcontainerdtypes.Task
|
||||||
}
|
}
|
||||||
|
|
|
@ -307,11 +307,19 @@ func (pm *Manager) GC() {
|
||||||
|
|
||||||
type logHook struct{ id string }
|
type logHook struct{ id string }
|
||||||
|
|
||||||
func (logHook) Levels() []logrus.Level {
|
func (logHook) Levels() []log.Level {
|
||||||
return logrus.AllLevels
|
return []log.Level{
|
||||||
|
log.PanicLevel,
|
||||||
|
log.FatalLevel,
|
||||||
|
log.ErrorLevel,
|
||||||
|
log.WarnLevel,
|
||||||
|
log.InfoLevel,
|
||||||
|
log.DebugLevel,
|
||||||
|
log.TraceLevel,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l logHook) Fire(entry *logrus.Entry) error {
|
func (l logHook) Fire(entry *log.Entry) error {
|
||||||
entry.Data = log.Fields{"plugin": l.id}
|
entry.Data = log.Fields{"plugin": l.id}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -319,7 +327,7 @@ func (l logHook) Fire(entry *logrus.Entry) error {
|
||||||
func makeLoggerStreams(id string) (stdout, stderr io.WriteCloser) {
|
func makeLoggerStreams(id string) (stdout, stderr io.WriteCloser) {
|
||||||
logger := logrus.New()
|
logger := logrus.New()
|
||||||
logger.Hooks.Add(logHook{id})
|
logger.Hooks.Add(logHook{id})
|
||||||
return logger.WriterLevel(logrus.InfoLevel), logger.WriterLevel(logrus.ErrorLevel)
|
return logger.WriterLevel(log.InfoLevel), logger.WriterLevel(log.ErrorLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
func validatePrivileges(requiredPrivileges, privileges types.PluginPrivileges) error {
|
func validatePrivileges(requiredPrivileges, privileges types.PluginPrivileges) error {
|
||||||
|
|
Loading…
Reference in a new issue