瀏覽代碼

daemon: NewDaemon(): check system requirements early

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 2 年之前
父節點
當前提交
17fb29c9e8
共有 4 個文件被更改,包括 11 次插入15 次删除
  1. 4 8
      daemon/daemon.go
  2. 0 1
      daemon/daemon_unix.go
  3. 7 5
      daemon/daemon_unsupported.go
  4. 0 1
      daemon/daemon_windows.go

+ 4 - 8
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

+ 0 - 1
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

+ 7 - 5
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()
 }

+ 0 - 1
daemon/daemon_windows.go

@@ -38,7 +38,6 @@ import (
 
 const (
 	isWindows            = true
-	platformSupported    = true
 	windowsMinCPUShares  = 1
 	windowsMaxCPUShares  = 10000
 	windowsMinCPUPercent = 1