daemon/config: move daemon log-config to a separate struct

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-10-16 01:06:46 +02:00
parent c584855329
commit c73fe6d26e
5 changed files with 19 additions and 14 deletions

View File

@@ -758,10 +758,10 @@ func getContainerdDaemonOpts(cfg *config.Config) ([]supervisor.DaemonOpt, error)
if cfg.Debug {
opts = append(opts, supervisor.WithLogLevel("debug"))
} else {
opts = append(opts, supervisor.WithLogLevel(cfg.LogLevel))
opts = append(opts, supervisor.WithLogLevel(cfg.DaemonLogConfig.LogLevel))
}
if logFormat := cfg.LogFormat; logFormat != "" {
if logFormat := cfg.DaemonLogConfig.LogFormat; logFormat != "" {
opts = append(opts, supervisor.WithLogFormat(logFormat))
}

View File

@@ -157,7 +157,7 @@ func TestLoadDaemonCliConfigWithLogFormat(t *testing.T) {
loadedConfig, err := loadDaemonCliConfig(opts)
assert.NilError(t, err)
assert.Assert(t, loadedConfig != nil)
assert.Check(t, is.Equal(log.JSONFormat, loadedConfig.LogFormat))
assert.Check(t, is.Equal(log.JSONFormat, loadedConfig.DaemonLogConfig.LogFormat))
}
func TestLoadDaemonCliConfigWithInvalidLogFormat(t *testing.T) {

View File

@@ -17,7 +17,7 @@ func TestLoadDaemonCliConfigWithDaemonFlags(t *testing.T) {
opts := defaultOptions(t, tempFile.Path())
opts.Debug = true
opts.LogLevel = "info"
opts.daemonConfig.DaemonLogConfig.LogLevel = "info"
assert.Check(t, opts.flags.Set("selinux-enabled", "true"))
loadedConfig, err := loadDaemonCliConfig(opts)
@@ -25,7 +25,7 @@ func TestLoadDaemonCliConfigWithDaemonFlags(t *testing.T) {
assert.Assert(t, loadedConfig != nil)
assert.Check(t, loadedConfig.Debug)
assert.Check(t, is.Equal("info", loadedConfig.LogLevel))
assert.Check(t, is.Equal("info", loadedConfig.DaemonLogConfig.LogLevel))
assert.Check(t, loadedConfig.EnableSelinuxSupport)
assert.Check(t, is.Equal("json-file", loadedConfig.LogConfig.Type))
assert.Check(t, is.Equal("1k", loadedConfig.LogConfig.Config["max-size"]))

View File

@@ -189,7 +189,6 @@ type CommonConfig struct {
Labels []string `json:"labels,omitempty"`
NetworkDiagnosticPort int `json:"network-diagnostic-port,omitempty"`
Pidfile string `json:"pidfile,omitempty"`
RawLogs bool `json:"raw-logs,omitempty"`
Root string `json:"data-root,omitempty"`
ExecRoot string `json:"exec-root,omitempty"`
SocketGroup string `json:"group,omitempty"`
@@ -217,12 +216,10 @@ type CommonConfig struct {
// to stop when daemon is being shutdown
ShutdownTimeout int `json:"shutdown-timeout,omitempty"`
Debug bool `json:"debug,omitempty"`
Hosts []string `json:"hosts,omitempty"`
LogLevel string `json:"log-level,omitempty"`
LogFormat log.OutputFormat `json:"log-format,omitempty"`
TLS *bool `json:"tls,omitempty"`
TLSVerify *bool `json:"tlsverify,omitempty"`
Debug bool `json:"debug,omitempty"`
Hosts []string `json:"hosts,omitempty"`
TLS *bool `json:"tls,omitempty"`
TLSVerify *bool `json:"tlsverify,omitempty"`
// SwarmDefaultAdvertiseAddr is the default host/IP or network interface
// to use if a wildcard address is specified in the ListenAddr value
@@ -244,6 +241,7 @@ type CommonConfig struct {
// Embedded structs that allow config deserialization without the full struct.
DaemonLogConfig // DaemonLogConfig holds options for configuring the daemon's logging.
TLSOptions // TLSOptions defines TLS configuration for the API server.
DNSConfig // DNSConfig defines default DNS options for containers.
LogConfig // LogConfig defines default log configuration for containers.
@@ -296,6 +294,13 @@ type CommonConfig struct {
ValuesSet map[string]any `json:"-"`
}
// DaemonLogConfig holds options for configuring the daemon's logging.
type DaemonLogConfig struct {
LogLevel string `json:"log-level,omitempty"`
LogFormat log.OutputFormat `json:"log-format,omitempty"`
RawLogs bool `json:"raw-logs,omitempty"`
}
// Proxies holds the proxies that are configured for the daemon.
type Proxies struct {
HTTPProxy string `json:"http-proxy,omitempty"`

View File

@@ -367,7 +367,7 @@ func TestValidateConfigurationErrors(t *testing.T) {
name: "with invalid log-level",
config: &Config{
CommonConfig: CommonConfig{
LogLevel: "foobar",
DaemonLogConfig: DaemonLogConfig{LogLevel: "foobar"},
},
},
expectedErr: "invalid logging level: foobar",
@@ -575,7 +575,7 @@ func TestValidateConfiguration(t *testing.T) {
field: "LogLevel",
config: &Config{
CommonConfig: CommonConfig{
LogLevel: "warn",
DaemonLogConfig: DaemonLogConfig{LogLevel: "warn"},
},
},
},