Browse Source

daemon/config: remove CommonUnixConfig type

This type was added to support Solaris (which didn't support these
options). Solaris support was removed, so we can integrate this type
back into the "unix" type.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 4 years ago
parent
commit
9d9679975f

+ 0 - 67
daemon/config/config_common_unix.go

@@ -1,67 +0,0 @@
-// +build linux freebsd
-
-package config // import "github.com/docker/docker/daemon/config"
-
-import (
-	"github.com/docker/docker/api/types"
-)
-
-// CommonUnixConfig defines configuration of a docker daemon that is
-// common across Unix platforms.
-type CommonUnixConfig struct {
-	Runtimes          map[string]types.Runtime `json:"runtimes,omitempty"`
-	DefaultRuntime    string                   `json:"default-runtime,omitempty"`
-	DefaultInitBinary string                   `json:"default-init,omitempty"`
-}
-
-// GetRuntime returns the runtime path and arguments for a given
-// runtime name
-func (conf *Config) GetRuntime(name string) *types.Runtime {
-	conf.Lock()
-	defer conf.Unlock()
-	if rt, ok := conf.Runtimes[name]; ok {
-		return &rt
-	}
-	return nil
-}
-
-// GetDefaultRuntimeName returns the current default runtime
-func (conf *Config) GetDefaultRuntimeName() string {
-	conf.Lock()
-	rt := conf.DefaultRuntime
-	conf.Unlock()
-
-	return rt
-}
-
-// GetAllRuntimes returns a copy of the runtimes map
-func (conf *Config) GetAllRuntimes() map[string]types.Runtime {
-	conf.Lock()
-	rts := conf.Runtimes
-	conf.Unlock()
-	return rts
-}
-
-// GetExecRoot returns the user configured Exec-root
-func (conf *Config) GetExecRoot() string {
-	return conf.ExecRoot
-}
-
-// GetInitPath returns the configured docker-init path
-func (conf *Config) GetInitPath() string {
-	conf.Lock()
-	defer conf.Unlock()
-	if conf.InitPath != "" {
-		return conf.InitPath
-	}
-	if conf.DefaultInitBinary != "" {
-		return conf.DefaultInitBinary
-	}
-	return DefaultInitBinary
-}
-
-// GetResolvConf returns the appropriate resolv.conf
-// Check setupResolvConf on how this is selected
-func (conf *Config) GetResolvConf() string {
-	return conf.ResolvConf
-}

+ 10 - 18
daemon/config/config_common_unix_test.go

@@ -8,29 +8,25 @@ import (
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/api/types"
 )
 )
 
 
-func TestCommonUnixValidateConfigurationErrors(t *testing.T) {
+func TestUnixValidateConfigurationErrors(t *testing.T) {
 	testCases := []struct {
 	testCases := []struct {
 		config *Config
 		config *Config
 	}{
 	}{
 		// Can't override the stock runtime
 		// Can't override the stock runtime
 		{
 		{
 			config: &Config{
 			config: &Config{
-				CommonUnixConfig: CommonUnixConfig{
-					Runtimes: map[string]types.Runtime{
-						StockRuntimeName: {},
-					},
+				Runtimes: map[string]types.Runtime{
+					StockRuntimeName: {},
 				},
 				},
 			},
 			},
 		},
 		},
 		// Default runtime should be present in runtimes
 		// Default runtime should be present in runtimes
 		{
 		{
 			config: &Config{
 			config: &Config{
-				CommonUnixConfig: CommonUnixConfig{
-					Runtimes: map[string]types.Runtime{
-						"foo": {},
-					},
-					DefaultRuntime: "bar",
+				Runtimes: map[string]types.Runtime{
+					"foo": {},
 				},
 				},
+				DefaultRuntime: "bar",
 			},
 			},
 		},
 		},
 	}
 	}
@@ -42,7 +38,7 @@ func TestCommonUnixValidateConfigurationErrors(t *testing.T) {
 	}
 	}
 }
 }
 
 
-func TestCommonUnixGetInitPath(t *testing.T) {
+func TestUnixGetInitPath(t *testing.T) {
 	testCases := []struct {
 	testCases := []struct {
 		config           *Config
 		config           *Config
 		expectedInitPath string
 		expectedInitPath string
@@ -55,18 +51,14 @@ func TestCommonUnixGetInitPath(t *testing.T) {
 		},
 		},
 		{
 		{
 			config: &Config{
 			config: &Config{
-				CommonUnixConfig: CommonUnixConfig{
-					DefaultInitBinary: "foo-init-bin",
-				},
+				DefaultInitBinary: "foo-init-bin",
 			},
 			},
 			expectedInitPath: "foo-init-bin",
 			expectedInitPath: "foo-init-bin",
 		},
 		},
 		{
 		{
 			config: &Config{
 			config: &Config{
-				InitPath: "init-path-A",
-				CommonUnixConfig: CommonUnixConfig{
-					DefaultInitBinary: "init-path-B",
-				},
+				InitPath:          "init-path-A",
+				DefaultInitBinary: "init-path-B",
 			},
 			},
 			expectedInitPath: "init-path-A",
 			expectedInitPath: "init-path-A",
 		},
 		},

+ 56 - 2
daemon/config/config_unix.go

@@ -6,6 +6,7 @@ import (
 	"fmt"
 	"fmt"
 	"net"
 	"net"
 
 
+	"github.com/docker/docker/api/types"
 	containertypes "github.com/docker/docker/api/types/container"
 	containertypes "github.com/docker/docker/api/types/container"
 	"github.com/docker/docker/opts"
 	"github.com/docker/docker/opts"
 	units "github.com/docker/go-units"
 	units "github.com/docker/go-units"
@@ -44,9 +45,10 @@ type BridgeConfig struct {
 type Config struct {
 type Config struct {
 	CommonConfig
 	CommonConfig
 
 
-	// These fields are common to all unix platforms.
-	CommonUnixConfig
 	// Fields below here are platform specific.
 	// Fields below here are platform specific.
+	Runtimes             map[string]types.Runtime `json:"runtimes,omitempty"`
+	DefaultRuntime       string                   `json:"default-runtime,omitempty"`
+	DefaultInitBinary    string                   `json:"default-init,omitempty"`
 	CgroupParent         string                   `json:"cgroup-parent,omitempty"`
 	CgroupParent         string                   `json:"cgroup-parent,omitempty"`
 	EnableSelinuxSupport bool                     `json:"selinux-enabled,omitempty"`
 	EnableSelinuxSupport bool                     `json:"selinux-enabled,omitempty"`
 	RemappedRoot         string                   `json:"userns-remap,omitempty"`
 	RemappedRoot         string                   `json:"userns-remap,omitempty"`
@@ -66,6 +68,58 @@ type Config struct {
 	Rootless   bool   `json:"rootless,omitempty"`
 	Rootless   bool   `json:"rootless,omitempty"`
 }
 }
 
 
+// GetRuntime returns the runtime path and arguments for a given
+// runtime name
+func (conf *Config) GetRuntime(name string) *types.Runtime {
+	conf.Lock()
+	defer conf.Unlock()
+	if rt, ok := conf.Runtimes[name]; ok {
+		return &rt
+	}
+	return nil
+}
+
+// GetDefaultRuntimeName returns the current default runtime
+func (conf *Config) GetDefaultRuntimeName() string {
+	conf.Lock()
+	rt := conf.DefaultRuntime
+	conf.Unlock()
+
+	return rt
+}
+
+// GetAllRuntimes returns a copy of the runtimes map
+func (conf *Config) GetAllRuntimes() map[string]types.Runtime {
+	conf.Lock()
+	rts := conf.Runtimes
+	conf.Unlock()
+	return rts
+}
+
+// GetExecRoot returns the user configured Exec-root
+func (conf *Config) GetExecRoot() string {
+	return conf.ExecRoot
+}
+
+// GetInitPath returns the configured docker-init path
+func (conf *Config) GetInitPath() string {
+	conf.Lock()
+	defer conf.Unlock()
+	if conf.InitPath != "" {
+		return conf.InitPath
+	}
+	if conf.DefaultInitBinary != "" {
+		return conf.DefaultInitBinary
+	}
+	return DefaultInitBinary
+}
+
+// GetResolvConf returns the appropriate resolv.conf
+// Check setupResolvConf on how this is selected
+func (conf *Config) GetResolvConf() string {
+	return conf.ResolvConf
+}
+
 // IsSwarmCompatible defines if swarm mode can be enabled in this config
 // IsSwarmCompatible defines if swarm mode can be enabled in this config
 func (conf *Config) IsSwarmCompatible() error {
 func (conf *Config) IsSwarmCompatible() error {
 	if conf.ClusterStore != "" || conf.ClusterAdvertise != "" {
 	if conf.ClusterStore != "" || conf.ClusterAdvertise != "" {

+ 1 - 3
daemon/container_unix_test.go

@@ -33,9 +33,7 @@ func TestContainerWarningHostAndPublishPorts(t *testing.T) {
 			PortBindings: tc.ports,
 			PortBindings: tc.ports,
 		}
 		}
 		cs := &config.Config{
 		cs := &config.Config{
-			CommonUnixConfig: config.CommonUnixConfig{
-				Runtimes: map[string]types.Runtime{"runc": {}},
-			},
+			Runtimes: map[string]types.Runtime{"runc": {}},
 		}
 		}
 		d := &Daemon{configStore: cs}
 		d := &Daemon{configStore: cs}
 		wrns, err := d.verifyContainerSettings("", hostConfig, &containertypes.Config{}, false)
 		wrns, err := d.verifyContainerSettings("", hostConfig, &containertypes.Config{}, false)