From 17fb29c9e82771304531c071bce16bb8c431a110 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 17 Oct 2022 12:47:25 +0200 Subject: [PATCH] daemon: NewDaemon(): check system requirements early Signed-off-by: Sebastiaan van Stijn --- daemon/daemon.go | 12 ++++-------- daemon/daemon_unix.go | 1 - daemon/daemon_unsupported.go | 12 +++++++----- daemon/daemon_windows.go | 1 - 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/daemon/daemon.go b/daemon/daemon.go index 272ab6bc5c..313845395b 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -706,9 +706,10 @@ func (daemon *Daemon) IsSwarmCompatible() error { // NewDaemon sets up everything for the daemon to be able to service // requests from the webserver. func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.Store) (daemon *Daemon, err error) { - // Verify the platform is supported as a daemon - if !platformSupported { - return nil, errors.New("the Docker daemon is not supported on this platform") + // Verify platform-specific requirements. + // TODO(thaJeztah): this should be called before we try to create the daemon; perhaps together with the config validation. + if err := checkSystem(); err != nil { + return nil, err } registryService, err := registry.NewService(config.ServiceOptions) @@ -732,11 +733,6 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S // Setup the resolv.conf setupResolvConf(config) - // Validate platform-specific requirements - if err := checkSystem(); err != nil { - return nil, err - } - idMapping, err := setupRemappedRoot(config) if err != nil { return nil, err diff --git a/daemon/daemon_unix.go b/daemon/daemon_unix.go index 20b08e75e2..20c6c03e14 100644 --- a/daemon/daemon_unix.go +++ b/daemon/daemon_unix.go @@ -60,7 +60,6 @@ const ( // See https://git.kernel.org/cgit/linux/kernel/git/tip/tip.git/tree/kernel/sched/sched.h?id=8cd9234c64c584432f6992fe944ca9e46ca8ea76#n269 linuxMinCPUShares = 2 linuxMaxCPUShares = 262144 - platformSupported = true // It's not kernel limit, we want this 6M limit to account for overhead during startup, and to supply a reasonable functional container linuxMinMemory = 6291456 // constants for remapped root settings diff --git a/daemon/daemon_unsupported.go b/daemon/daemon_unsupported.go index b154c6c8f5..f66713dbb4 100644 --- a/daemon/daemon_unsupported.go +++ b/daemon/daemon_unsupported.go @@ -4,15 +4,17 @@ package daemon // import "github.com/docker/docker/daemon" import ( - "github.com/docker/docker/daemon/config" + "errors" + "github.com/docker/docker/pkg/sysinfo" ) -const platformSupported = false - -func setupResolvConf(config *config.Config) { +func checkSystem() error { + return errors.New("the Docker daemon is not supported on this platform") } -func getSysInfo(daemon *Daemon) *sysinfo.SysInfo { +func setupResolvConf(_ *interface{}) {} + +func getSysInfo(_ *Daemon) *sysinfo.SysInfo { return sysinfo.New() } diff --git a/daemon/daemon_windows.go b/daemon/daemon_windows.go index c64e4570ba..eb37f275f0 100644 --- a/daemon/daemon_windows.go +++ b/daemon/daemon_windows.go @@ -38,7 +38,6 @@ import ( const ( isWindows = true - platformSupported = true windowsMinCPUShares = 1 windowsMaxCPUShares = 10000 windowsMinCPUPercent = 1