Quellcode durchsuchen

libcontainerd/supervisor: don't write log-level to config file

the `--log-level` flag overrides whatever is in the containerd configuration file;
https://github.com/containerd/containerd/blob/f033f6ff85ce397202ee69de22b4e3a4bf4093f5/cmd/containerd/command/main.go#L339-L352

Given that we set that flag when we start the containerd binary, there is no need
to write it both to the generated config-file and pass it as flag.

This patch also slightly changes the behavior; as both dockerd and containerd use
"info" as default log-level, don't set the log-level if it's the default.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn vor 2 Jahren
Ursprung
Commit
b6b0b0a05f

+ 4 - 4
cmd/dockerd/daemon.go

@@ -589,13 +589,13 @@ func (cli *DaemonCli) getContainerdDaemonOpts() ([]supervisor.DaemonOpt, error)
 		return nil, err
 	}
 
-	if cli.Config.Debug {
+	if cli.Debug {
 		opts = append(opts, supervisor.WithLogLevel("debug"))
-	} else if cli.Config.LogLevel != "" {
-		opts = append(opts, supervisor.WithLogLevel(cli.Config.LogLevel))
+	} else {
+		opts = append(opts, supervisor.WithLogLevel(cli.LogLevel))
 	}
 
-	if !cli.Config.CriContainerd {
+	if !cli.CriContainerd {
 		// CRI support in the managed daemon is currently opt-in.
 		//
 		// It's disabled by default, originally because it was listening on

+ 6 - 2
libcontainerd/supervisor/remote_daemon.go

@@ -48,6 +48,10 @@ type remote struct {
 
 	// oomScore adjusts the OOM score for the containerd process.
 	oomScore int
+
+	// logLevel overrides the containerd logging-level through the --log-level
+	// command-line option.
+	logLevel string
 }
 
 // Daemon represents a running containerd daemon
@@ -180,8 +184,8 @@ func (r *remote) startContainerd() error {
 
 	args := []string{"--config", configFile}
 
-	if r.Debug.Level != "" {
-		args = append(args, "--log-level", r.Debug.Level)
+	if r.logLevel != "" {
+		args = append(args, "--log-level", r.logLevel)
 	}
 
 	cmd := exec.Command(binaryName, args...)

+ 7 - 3
libcontainerd/supervisor/remote_daemon_options.go

@@ -1,10 +1,14 @@
 package supervisor // import "github.com/docker/docker/libcontainerd/supervisor"
 
-// WithLogLevel defines which log level to starts containerd with.
-// This only makes sense if WithStartDaemon() was set to true.
+// WithLogLevel defines which log level to start containerd with.
 func WithLogLevel(lvl string) DaemonOpt {
 	return func(r *remote) error {
-		r.Debug.Level = lvl
+		if lvl == "info" {
+			// both dockerd and containerd default log-level is "info",
+			// so don't pass the default.
+			lvl = ""
+		}
+		r.logLevel = lvl
 		return nil
 	}
 }