Skip to content

Commit

Permalink
libcontainerd/supervisor: consolidate platform-specific defaults
Browse files Browse the repository at this point in the history
Commit a000934 updated the default
MaxRecvMsgSize and MaxSendMsgSize for Linux, but did not modify the
defaults for Windows. Those options should not be platform-specific,
which means that the only difference between the Linux and Windows
config are the addresses for GRPC and Debug (Windows defaulting
to a named pipe, whereas Linux sockets within exec-root).

This patch

- implements functions to return the default addresses for each platform
- moves the defaults into `supervisor.Start()`
- removes the now redundant `remote.setDefaults()` method

It's worth noting that prior to this path, `remove.setDefaults()` would
be applied _after_ any (custom) `DaemonOpt` was applied. However, none of
the existing `DaemonOpt` options currently mutates these options. `remote`
is also a non-exported type, so no external implementations can currently
be created. It is therefore safe to set these defaults before options are
applied.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
  • Loading branch information
thaJeztah committed Aug 19, 2024
1 parent 5efbb60 commit 62bcc6e
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 62bcc6e

Please sign in to comment.