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

the `--log-level` flag overrides whatever is in the containerd configuration file;
f033f6ff85/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>
This commit is contained in:
Sebastiaan van Stijn 2022-08-10 18:27:07 +02:00
parent bff3e85625
commit b6b0b0a05f
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
3 changed files with 17 additions and 9 deletions

View File

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

View File

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

View File

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