mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #42618 from thaJeztah/remove_common_unix_config
daemon/config: remove commonUnixBridgeConfig and CommonUnixConfig
This commit is contained in:
commit
0c88b0dc82
8 changed files with 161 additions and 200 deletions
|
|
@ -282,10 +282,14 @@ func (conf *Config) IsValueSet(name string) bool {
|
|||
|
||||
// New returns a new fully initialized Config struct
|
||||
func New() *Config {
|
||||
config := Config{}
|
||||
config.LogConfig.Config = make(map[string]string)
|
||||
config.ClusterOpts = make(map[string]string)
|
||||
return &config
|
||||
return &Config{
|
||||
CommonConfig: CommonConfig{
|
||||
LogConfig: LogConfig{
|
||||
Config: make(map[string]string),
|
||||
},
|
||||
ClusterOpts: make(map[string]string),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// ParseClusterAdvertiseSettings parses the specified advertise settings
|
||||
|
|
|
|||
|
|
@ -1,77 +0,0 @@
|
|||
// +build linux freebsd
|
||||
|
||||
package config // import "github.com/docker/docker/daemon/config"
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"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"`
|
||||
}
|
||||
|
||||
type commonUnixBridgeConfig struct {
|
||||
DefaultIP net.IP `json:"ip,omitempty"`
|
||||
IP string `json:"bip,omitempty"`
|
||||
DefaultGatewayIPv4 net.IP `json:"default-gateway,omitempty"`
|
||||
DefaultGatewayIPv6 net.IP `json:"default-gateway-v6,omitempty"`
|
||||
InterContainerCommunication bool `json:"icc,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
|
||||
}
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
// +build !windows
|
||||
|
||||
package config // import "github.com/docker/docker/daemon/config"
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
)
|
||||
|
||||
func TestCommonUnixValidateConfigurationErrors(t *testing.T) {
|
||||
testCases := []struct {
|
||||
config *Config
|
||||
}{
|
||||
// Can't override the stock runtime
|
||||
{
|
||||
config: &Config{
|
||||
CommonUnixConfig: CommonUnixConfig{
|
||||
Runtimes: map[string]types.Runtime{
|
||||
StockRuntimeName: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
// Default runtime should be present in runtimes
|
||||
{
|
||||
config: &Config{
|
||||
CommonUnixConfig: CommonUnixConfig{
|
||||
Runtimes: map[string]types.Runtime{
|
||||
"foo": {},
|
||||
},
|
||||
DefaultRuntime: "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
err := Validate(tc.config)
|
||||
if err == nil {
|
||||
t.Fatalf("expected error, got nil for config %v", tc.config)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommonUnixGetInitPath(t *testing.T) {
|
||||
testCases := []struct {
|
||||
config *Config
|
||||
expectedInitPath string
|
||||
}{
|
||||
{
|
||||
config: &Config{
|
||||
InitPath: "some-init-path",
|
||||
},
|
||||
expectedInitPath: "some-init-path",
|
||||
},
|
||||
{
|
||||
config: &Config{
|
||||
CommonUnixConfig: CommonUnixConfig{
|
||||
DefaultInitBinary: "foo-init-bin",
|
||||
},
|
||||
},
|
||||
expectedInitPath: "foo-init-bin",
|
||||
},
|
||||
{
|
||||
config: &Config{
|
||||
InitPath: "init-path-A",
|
||||
CommonUnixConfig: CommonUnixConfig{
|
||||
DefaultInitBinary: "init-path-B",
|
||||
},
|
||||
},
|
||||
expectedInitPath: "init-path-A",
|
||||
},
|
||||
{
|
||||
config: &Config{},
|
||||
expectedInitPath: "docker-init",
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
initPath := tc.config.GetInitPath()
|
||||
if initPath != tc.expectedInitPath {
|
||||
t.Fatalf("expected initPath to be %v, got %v", tc.expectedInitPath, initPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
// +build linux freebsd
|
||||
|
||||
package config // import "github.com/docker/docker/daemon/config"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
containertypes "github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/opts"
|
||||
units "github.com/docker/go-units"
|
||||
|
|
@ -15,15 +15,38 @@ const (
|
|||
DefaultIpcMode = "private"
|
||||
)
|
||||
|
||||
// BridgeConfig stores all the bridge driver specific
|
||||
// configuration.
|
||||
type BridgeConfig struct {
|
||||
commonBridgeConfig
|
||||
|
||||
// Fields below here are platform specific.
|
||||
DefaultIP net.IP `json:"ip,omitempty"`
|
||||
IP string `json:"bip,omitempty"`
|
||||
DefaultGatewayIPv4 net.IP `json:"default-gateway,omitempty"`
|
||||
DefaultGatewayIPv6 net.IP `json:"default-gateway-v6,omitempty"`
|
||||
InterContainerCommunication bool `json:"icc,omitempty"`
|
||||
|
||||
EnableIPv6 bool `json:"ipv6,omitempty"`
|
||||
EnableIPTables bool `json:"iptables,omitempty"`
|
||||
EnableIP6Tables bool `json:"ip6tables,omitempty"`
|
||||
EnableIPForward bool `json:"ip-forward,omitempty"`
|
||||
EnableIPMasq bool `json:"ip-masq,omitempty"`
|
||||
EnableUserlandProxy bool `json:"userland-proxy,omitempty"`
|
||||
UserlandProxyPath string `json:"userland-proxy-path,omitempty"`
|
||||
FixedCIDRv6 string `json:"fixed-cidr-v6,omitempty"`
|
||||
}
|
||||
|
||||
// Config defines the configuration of a docker daemon.
|
||||
// It includes json tags to deserialize configuration from a file
|
||||
// using the same names that the flags in the command line uses.
|
||||
type Config struct {
|
||||
CommonConfig
|
||||
|
||||
// These fields are common to all unix platforms.
|
||||
CommonUnixConfig
|
||||
// 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"`
|
||||
EnableSelinuxSupport bool `json:"selinux-enabled,omitempty"`
|
||||
RemappedRoot string `json:"userns-remap,omitempty"`
|
||||
|
|
@ -43,23 +66,56 @@ type Config struct {
|
|||
Rootless bool `json:"rootless,omitempty"`
|
||||
}
|
||||
|
||||
// BridgeConfig stores all the bridge driver specific
|
||||
// configuration.
|
||||
type BridgeConfig struct {
|
||||
commonBridgeConfig
|
||||
// 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
|
||||
}
|
||||
|
||||
// These fields are common to all unix platforms.
|
||||
commonUnixBridgeConfig
|
||||
// GetDefaultRuntimeName returns the current default runtime
|
||||
func (conf *Config) GetDefaultRuntimeName() string {
|
||||
conf.Lock()
|
||||
rt := conf.DefaultRuntime
|
||||
conf.Unlock()
|
||||
|
||||
// Fields below here are platform specific.
|
||||
EnableIPv6 bool `json:"ipv6,omitempty"`
|
||||
EnableIPTables bool `json:"iptables,omitempty"`
|
||||
EnableIP6Tables bool `json:"ip6tables,omitempty"`
|
||||
EnableIPForward bool `json:"ip-forward,omitempty"`
|
||||
EnableIPMasq bool `json:"ip-masq,omitempty"`
|
||||
EnableUserlandProxy bool `json:"userland-proxy,omitempty"`
|
||||
UserlandProxyPath string `json:"userland-proxy-path,omitempty"`
|
||||
FixedCIDRv6 string `json:"fixed-cidr-v6,omitempty"`
|
||||
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
|
||||
|
|
@ -104,7 +160,7 @@ func (conf *Config) ValidatePlatformConfig() error {
|
|||
return verifyDefaultCgroupNsMode(conf.CgroupNamespaceMode)
|
||||
}
|
||||
|
||||
// IsRootless returns conf.Rootless
|
||||
// IsRootless returns conf.Rootless on Linux but false on Windows
|
||||
func (conf *Config) IsRootless() bool {
|
||||
return conf.Rootless
|
||||
}
|
||||
|
|
@ -1,10 +1,9 @@
|
|||
// +build !windows
|
||||
|
||||
package config // import "github.com/docker/docker/daemon/config"
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/opts"
|
||||
units "github.com/docker/go-units"
|
||||
"github.com/spf13/pflag"
|
||||
|
|
@ -132,3 +131,70 @@ func TestDaemonConfigurationMergeShmSize(t *testing.T) {
|
|||
expectedValue := 1 * 1024 * 1024 * 1024
|
||||
assert.Check(t, is.Equal(int64(expectedValue), cc.ShmSize.Value()))
|
||||
}
|
||||
|
||||
func TestUnixValidateConfigurationErrors(t *testing.T) {
|
||||
testCases := []struct {
|
||||
config *Config
|
||||
}{
|
||||
// Can't override the stock runtime
|
||||
{
|
||||
config: &Config{
|
||||
Runtimes: map[string]types.Runtime{
|
||||
StockRuntimeName: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
// Default runtime should be present in runtimes
|
||||
{
|
||||
config: &Config{
|
||||
Runtimes: map[string]types.Runtime{
|
||||
"foo": {},
|
||||
},
|
||||
DefaultRuntime: "bar",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
err := Validate(tc.config)
|
||||
if err == nil {
|
||||
t.Fatalf("expected error, got nil for config %v", tc.config)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnixGetInitPath(t *testing.T) {
|
||||
testCases := []struct {
|
||||
config *Config
|
||||
expectedInitPath string
|
||||
}{
|
||||
{
|
||||
config: &Config{
|
||||
InitPath: "some-init-path",
|
||||
},
|
||||
expectedInitPath: "some-init-path",
|
||||
},
|
||||
{
|
||||
config: &Config{
|
||||
DefaultInitBinary: "foo-init-bin",
|
||||
},
|
||||
expectedInitPath: "foo-init-bin",
|
||||
},
|
||||
{
|
||||
config: &Config{
|
||||
InitPath: "init-path-A",
|
||||
DefaultInitBinary: "init-path-B",
|
||||
},
|
||||
expectedInitPath: "init-path-A",
|
||||
},
|
||||
{
|
||||
config: &Config{},
|
||||
expectedInitPath: "docker-init",
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
initPath := tc.config.GetInitPath()
|
||||
if initPath != tc.expectedInitPath {
|
||||
t.Fatalf("expected initPath to be %v, got %v", tc.expectedInitPath, initPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -11,8 +11,8 @@ type BridgeConfig struct {
|
|||
}
|
||||
|
||||
// Config defines the configuration of a docker daemon.
|
||||
// These are the configuration settings that you pass
|
||||
// to the docker daemon when you launch it with say: `dockerd -e windows`
|
||||
// It includes json tags to deserialize configuration from a file
|
||||
// using the same names that the flags in the command line uses.
|
||||
type Config struct {
|
||||
CommonConfig
|
||||
|
||||
|
|
@ -26,11 +26,6 @@ func (conf *Config) GetRuntime(name string) *types.Runtime {
|
|||
return nil
|
||||
}
|
||||
|
||||
// GetInitPath returns the configure docker-init path
|
||||
func (conf *Config) GetInitPath() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// GetDefaultRuntimeName returns the current default runtime
|
||||
func (conf *Config) GetDefaultRuntimeName() string {
|
||||
return StockRuntimeName
|
||||
|
|
@ -46,6 +41,11 @@ func (conf *Config) GetExecRoot() string {
|
|||
return ""
|
||||
}
|
||||
|
||||
// GetInitPath returns the configured docker-init path
|
||||
func (conf *Config) GetInitPath() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// IsSwarmCompatible defines if swarm mode can be enabled in this config
|
||||
func (conf *Config) IsSwarmCompatible() error {
|
||||
return nil
|
||||
|
|
@ -56,7 +56,7 @@ func (conf *Config) ValidatePlatformConfig() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// IsRootless returns conf.Rootless on Unix but false on Windows
|
||||
// IsRootless returns conf.Rootless on Linux but false on Windows
|
||||
func (conf *Config) IsRootless() bool {
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
// +build windows
|
||||
|
||||
package config // import "github.com/docker/docker/daemon/config"
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -33,9 +33,7 @@ func TestContainerWarningHostAndPublishPorts(t *testing.T) {
|
|||
PortBindings: tc.ports,
|
||||
}
|
||||
cs := &config.Config{
|
||||
CommonUnixConfig: config.CommonUnixConfig{
|
||||
Runtimes: map[string]types.Runtime{"runc": {}},
|
||||
},
|
||||
Runtimes: map[string]types.Runtime{"runc": {}},
|
||||
}
|
||||
d := &Daemon{configStore: cs}
|
||||
wrns, err := d.verifyContainerSettings(hostConfig, &containertypes.Config{}, false)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue