From ac2726e12c1432b5bbb378b1a4738aa70acbfb9f Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Mon, 8 Mar 2021 17:44:56 +0900 Subject: [PATCH] cmd/containerd: deduplicate config*.go `config_linux.go` and `config_windows.go` are identical. `config_unsupported.go` is also almost identical but enables debug logs by default. Signed-off-by: Akihiro Suda --- cmd/containerd/command/config.go | 16 ++++++++++++++++ cmd/containerd/command/config_linux.go | 14 +------------- cmd/containerd/command/config_unsupported.go | 18 +++++------------- cmd/containerd/command/config_windows.go | 14 +------------- 4 files changed, 23 insertions(+), 39 deletions(-) diff --git a/cmd/containerd/command/config.go b/cmd/containerd/command/config.go index f1d590d9f..92b455fc7 100644 --- a/cmd/containerd/command/config.go +++ b/cmd/containerd/command/config.go @@ -22,6 +22,7 @@ import ( "os" "github.com/BurntSushi/toml" + "github.com/containerd/containerd/defaults" "github.com/containerd/containerd/pkg/timeout" "github.com/containerd/containerd/services/server" srvconfig "github.com/containerd/containerd/services/server/config" @@ -113,3 +114,18 @@ var configCommand = cli.Command{ }, }, } + +func platformAgnosticDefaultConfig() *srvconfig.Config { + return &srvconfig.Config{ + Version: 1, + Root: defaults.DefaultRootDir, + State: defaults.DefaultStateDir, + GRPC: srvconfig.GRPCConfig{ + Address: defaults.DefaultAddress, + MaxRecvMsgSize: defaults.DefaultMaxRecvMsgSize, + MaxSendMsgSize: defaults.DefaultMaxSendMsgSize, + }, + DisabledPlugins: []string{}, + RequiredPlugins: []string{}, + } +} diff --git a/cmd/containerd/command/config_linux.go b/cmd/containerd/command/config_linux.go index 9ed7368d7..df8e856cf 100644 --- a/cmd/containerd/command/config_linux.go +++ b/cmd/containerd/command/config_linux.go @@ -17,21 +17,9 @@ package command import ( - "github.com/containerd/containerd/defaults" srvconfig "github.com/containerd/containerd/services/server/config" ) func defaultConfig() *srvconfig.Config { - return &srvconfig.Config{ - Version: 1, - Root: defaults.DefaultRootDir, - State: defaults.DefaultStateDir, - GRPC: srvconfig.GRPCConfig{ - Address: defaults.DefaultAddress, - MaxRecvMsgSize: defaults.DefaultMaxRecvMsgSize, - MaxSendMsgSize: defaults.DefaultMaxSendMsgSize, - }, - DisabledPlugins: []string{}, - RequiredPlugins: []string{}, - } + return platformAgnosticDefaultConfig() } diff --git a/cmd/containerd/command/config_unsupported.go b/cmd/containerd/command/config_unsupported.go index 695a7b466..8dc92bc61 100644 --- a/cmd/containerd/command/config_unsupported.go +++ b/cmd/containerd/command/config_unsupported.go @@ -24,18 +24,10 @@ import ( ) func defaultConfig() *srvconfig.Config { - return &srvconfig.Config{ - Version: 1, - Root: defaults.DefaultRootDir, - State: defaults.DefaultStateDir, - GRPC: srvconfig.GRPCConfig{ - Address: defaults.DefaultAddress, - }, - Debug: srvconfig.Debug{ - Level: "info", - Address: defaults.DefaultDebugAddress, - }, - DisabledPlugins: []string{}, - RequiredPlugins: []string{}, + cfg := platformAgnosticDefaultConfig() + cfg.Debug = srvconfig.Debug{ + Level: "info", + Address: defaults.DefaultDebugAddress, } + return cfg } diff --git a/cmd/containerd/command/config_windows.go b/cmd/containerd/command/config_windows.go index 9ed7368d7..df8e856cf 100644 --- a/cmd/containerd/command/config_windows.go +++ b/cmd/containerd/command/config_windows.go @@ -17,21 +17,9 @@ package command import ( - "github.com/containerd/containerd/defaults" srvconfig "github.com/containerd/containerd/services/server/config" ) func defaultConfig() *srvconfig.Config { - return &srvconfig.Config{ - Version: 1, - Root: defaults.DefaultRootDir, - State: defaults.DefaultStateDir, - GRPC: srvconfig.GRPCConfig{ - Address: defaults.DefaultAddress, - MaxRecvMsgSize: defaults.DefaultMaxRecvMsgSize, - MaxSendMsgSize: defaults.DefaultMaxSendMsgSize, - }, - DisabledPlugins: []string{}, - RequiredPlugins: []string{}, - } + return platformAgnosticDefaultConfig() }