Skip to content

Commit

Permalink
Merge pull request moby#48353 from thaJeztah/libcontainer_consolidate…
Browse files Browse the repository at this point in the history
…_defaults_step1

libcontainerd/supervisor: consolidate platform-specific defaults
  • Loading branch information
thaJeztah authored Aug 20, 2024
2 parents 22b5cb2 + 62bcc6e commit 7e864f1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
12 changes: 8 additions & 4 deletions libcontainerd/supervisor/remote_daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ type remote struct {
daemonStartCh chan error
daemonStopCh chan struct{}

stateDir string

// logLevel overrides the containerd logging-level through the --log-level
// command-line option.
logLevel string
Expand All @@ -67,11 +65,18 @@ type DaemonOpt func(c *remote) error
// Start starts a containerd daemon and monitors it
func Start(ctx context.Context, rootDir, stateDir string, opts ...DaemonOpt) (Daemon, error) {
r := &remote{
stateDir: stateDir,
Config: config.Config{
Version: 2,
Root: filepath.Join(rootDir, "daemon"),
State: filepath.Join(stateDir, "daemon"),
GRPC: config.GRPCConfig{
Address: defaultGRPCAddress(stateDir),
MaxRecvMsgSize: defaults.DefaultMaxRecvMsgSize,
MaxSendMsgSize: defaults.DefaultMaxSendMsgSize,
},
Debug: config.Debug{
Address: defaultDebugAddress(stateDir),
},
},
configFile: filepath.Join(stateDir, configFile),
daemonPid: -1,
Expand All @@ -86,7 +91,6 @@ func Start(ctx context.Context, rootDir, stateDir string, opts ...DaemonOpt) (Da
return nil, err
}
}
r.setDefaults()

if err := system.MkdirAll(stateDir, 0o700); err != nil {
return nil, err
Expand Down
20 changes: 6 additions & 14 deletions libcontainerd/supervisor/remote_daemon_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"syscall"
"time"

"github.com/containerd/containerd/defaults"
"github.com/docker/docker/pkg/process"
)

Expand All @@ -15,19 +14,12 @@ const (
debugSockFile = "containerd-debug.sock"
)

func (r *remote) setDefaults() {
if r.GRPC.Address == "" {
r.GRPC.Address = filepath.Join(r.stateDir, sockFile)
}
if r.GRPC.MaxRecvMsgSize == 0 {
r.GRPC.MaxRecvMsgSize = defaults.DefaultMaxRecvMsgSize
}
if r.GRPC.MaxSendMsgSize == 0 {
r.GRPC.MaxSendMsgSize = defaults.DefaultMaxSendMsgSize
}
if r.Debug.Address == "" {
r.Debug.Address = filepath.Join(r.stateDir, debugSockFile)
}
func defaultGRPCAddress(stateDir string) string {
return filepath.Join(stateDir, sockFile)
}

func defaultDebugAddress(stateDir string) string {
return filepath.Join(stateDir, debugSockFile)
}

func (r *remote) stopDaemon() {
Expand Down
13 changes: 6 additions & 7 deletions libcontainerd/supervisor/remote_daemon_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ const (
debugPipeName = `\\.\pipe\containerd-debug`
)

func (r *remote) setDefaults() {
if r.GRPC.Address == "" {
r.GRPC.Address = grpcPipeName
}
if r.Debug.Address == "" {
r.Debug.Address = debugPipeName
}
func defaultGRPCAddress(stateDir string) string {
return grpcPipeName
}

func defaultDebugAddress(stateDir string) string {
return debugPipeName
}

func (r *remote) stopDaemon() {
Expand Down

0 comments on commit 7e864f1

Please sign in to comment.