2015-05-23 00:52:02 -04:00
|
|
|
package config
|
|
|
|
|
2015-06-11 09:52:46 -04:00
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2021-04-05 20:24:47 -04:00
|
|
|
"github.com/docker/docker/libnetwork/cluster"
|
|
|
|
"github.com/docker/docker/libnetwork/datastore"
|
|
|
|
"github.com/docker/docker/libnetwork/ipamutils"
|
|
|
|
"github.com/docker/docker/libnetwork/netlabel"
|
|
|
|
"github.com/docker/docker/libnetwork/osl"
|
2021-05-27 20:15:56 -04:00
|
|
|
"github.com/docker/docker/pkg/plugingetter"
|
|
|
|
"github.com/docker/libkv/store"
|
2017-07-26 17:18:31 -04:00
|
|
|
"github.com/sirupsen/logrus"
|
2015-06-11 09:52:46 -04:00
|
|
|
)
|
2015-05-23 00:52:02 -04:00
|
|
|
|
2017-08-05 14:41:35 -04:00
|
|
|
const (
|
|
|
|
warningThNetworkControlPlaneMTU = 1500
|
|
|
|
minimumNetworkControlPlaneMTU = 500
|
|
|
|
)
|
|
|
|
|
2015-05-23 00:52:02 -04:00
|
|
|
// Config encapsulates configurations of various Libnetwork components
|
|
|
|
type Config struct {
|
2017-07-10 15:05:58 -04:00
|
|
|
DataDir string
|
allow propagating custom exec-root (e.g. "/run/docker") to libnetwork-setkey
The docker daemon needs to be modified as follows:
diff --git a/daemon/oci_linux.go b/daemon/oci_linux.go
index 00ace320df..ea7daa72df 100644
--- a/daemon/oci_linux.go
+++ b/daemon/oci_linux.go
@@ -809,7 +809,7 @@ func (daemon *Daemon) createSpec(c *container.Container) (retSpec *specs.Spec, e
s.Hooks = &specs.Hooks{
Prestart: []specs.Hook{{
Path: target,
- Args: []string{"libnetwork-setkey", c.ID, daemon.netController.ID()},
+ Args: []string{"libnetwork-setkey", c.ID, daemon.netController.ID(), "-exec-root="+daemon.configStore.GetExecRoot()},
}},
}
}
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2018-08-11 08:26:40 -04:00
|
|
|
ExecRoot string
|
2017-07-10 15:05:58 -04:00
|
|
|
DefaultNetwork string
|
|
|
|
DefaultDriver string
|
|
|
|
Labels []string
|
|
|
|
DriverCfg map[string]interface{}
|
|
|
|
ClusterProvider cluster.Provider
|
|
|
|
NetworkControlPlaneMTU int
|
2018-01-18 17:30:51 -05:00
|
|
|
DefaultAddressPool []*ipamutils.NetworkToSplit
|
2022-09-23 13:40:11 -04:00
|
|
|
Scopes map[string]*datastore.ScopeCfg
|
|
|
|
ActiveSandboxes map[string]interface{}
|
|
|
|
PluginGetter plugingetter.PluginGetter
|
2015-05-23 00:52:02 -04:00
|
|
|
}
|
|
|
|
|
2022-09-26 13:20:55 -04:00
|
|
|
// New creates a new Config and initializes it with the given Options.
|
|
|
|
func New(opts ...Option) *Config {
|
2016-02-16 18:19:18 -05:00
|
|
|
cfg := &Config{
|
2022-09-23 13:40:11 -04:00
|
|
|
DriverCfg: make(map[string]interface{}),
|
|
|
|
Scopes: make(map[string]*datastore.ScopeCfg),
|
2016-02-16 18:19:18 -05:00
|
|
|
}
|
2022-09-23 13:58:21 -04:00
|
|
|
|
2022-09-23 13:22:56 -04:00
|
|
|
for _, opt := range opts {
|
|
|
|
if opt != nil {
|
|
|
|
opt(cfg)
|
|
|
|
}
|
|
|
|
}
|
2016-02-16 18:19:18 -05:00
|
|
|
|
2022-09-23 13:58:21 -04:00
|
|
|
// load default scope configs which don't have explicit user specified configs.
|
|
|
|
for k, v := range datastore.DefaultScopes(cfg.DataDir) {
|
|
|
|
if _, ok := cfg.Scopes[k]; !ok {
|
|
|
|
cfg.Scopes[k] = v
|
|
|
|
}
|
|
|
|
}
|
2016-02-16 18:19:18 -05:00
|
|
|
return cfg
|
|
|
|
}
|
|
|
|
|
2016-01-11 05:15:20 -05:00
|
|
|
// Option is an option setter function type used to pass various configurations
|
2015-06-11 09:52:46 -04:00
|
|
|
// to the controller
|
|
|
|
type Option func(c *Config)
|
|
|
|
|
|
|
|
// OptionDefaultNetwork function returns an option setter for a default network
|
|
|
|
func OptionDefaultNetwork(dn string) Option {
|
|
|
|
return func(c *Config) {
|
2016-11-01 00:26:14 -04:00
|
|
|
logrus.Debugf("Option DefaultNetwork: %s", dn)
|
2022-09-23 13:40:11 -04:00
|
|
|
c.DefaultNetwork = strings.TrimSpace(dn)
|
2015-06-11 09:52:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// OptionDefaultDriver function returns an option setter for default driver
|
|
|
|
func OptionDefaultDriver(dd string) Option {
|
|
|
|
return func(c *Config) {
|
2016-11-01 00:26:14 -04:00
|
|
|
logrus.Debugf("Option DefaultDriver: %s", dd)
|
2022-09-23 13:40:11 -04:00
|
|
|
c.DefaultDriver = strings.TrimSpace(dd)
|
2015-06-11 09:52:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-18 17:30:51 -05:00
|
|
|
// OptionDefaultAddressPoolConfig function returns an option setter for default address pool
|
|
|
|
func OptionDefaultAddressPoolConfig(addressPool []*ipamutils.NetworkToSplit) Option {
|
|
|
|
return func(c *Config) {
|
2022-09-23 13:40:11 -04:00
|
|
|
c.DefaultAddressPool = addressPool
|
2018-01-18 17:30:51 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-18 17:00:36 -04:00
|
|
|
// OptionDriverConfig returns an option setter for driver configuration.
|
|
|
|
func OptionDriverConfig(networkType string, config map[string]interface{}) Option {
|
|
|
|
return func(c *Config) {
|
2022-09-23 13:40:11 -04:00
|
|
|
c.DriverCfg[networkType] = config
|
2015-09-18 17:00:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-14 12:03:42 -04:00
|
|
|
// OptionLabels function returns an option setter for labels
|
|
|
|
func OptionLabels(labels []string) Option {
|
|
|
|
return func(c *Config) {
|
|
|
|
for _, label := range labels {
|
|
|
|
if strings.HasPrefix(label, netlabel.Prefix) {
|
2022-09-23 13:40:11 -04:00
|
|
|
c.Labels = append(c.Labels, label)
|
2015-06-14 12:03:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-05 07:21:15 -04:00
|
|
|
// OptionDataDir function returns an option setter for data folder
|
|
|
|
func OptionDataDir(dataDir string) Option {
|
|
|
|
return func(c *Config) {
|
2022-09-23 13:40:11 -04:00
|
|
|
c.DataDir = dataDir
|
2015-10-05 07:21:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-15 00:25:52 -04:00
|
|
|
// OptionExecRoot function returns an option setter for exec root folder
|
|
|
|
func OptionExecRoot(execRoot string) Option {
|
|
|
|
return func(c *Config) {
|
2022-09-23 13:40:11 -04:00
|
|
|
c.ExecRoot = execRoot
|
2016-07-15 00:25:52 -04:00
|
|
|
osl.SetBasePath(execRoot)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-27 16:54:25 -04:00
|
|
|
// OptionPluginGetter returns a plugingetter for remote drivers.
|
2016-10-07 14:58:10 -04:00
|
|
|
func OptionPluginGetter(pg plugingetter.PluginGetter) Option {
|
2016-09-27 16:54:25 -04:00
|
|
|
return func(c *Config) {
|
|
|
|
c.PluginGetter = pg
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-10 15:05:58 -04:00
|
|
|
// OptionNetworkControlPlaneMTU function returns an option setter for control plane MTU
|
|
|
|
func OptionNetworkControlPlaneMTU(exp int) Option {
|
|
|
|
return func(c *Config) {
|
|
|
|
logrus.Debugf("Network Control Plane MTU: %d", exp)
|
2017-08-05 14:41:35 -04:00
|
|
|
if exp < warningThNetworkControlPlaneMTU {
|
|
|
|
logrus.Warnf("Received a MTU of %d, this value is very low, the network control plane can misbehave,"+
|
|
|
|
" defaulting to minimum value (%d)", exp, minimumNetworkControlPlaneMTU)
|
|
|
|
if exp < minimumNetworkControlPlaneMTU {
|
|
|
|
exp = minimumNetworkControlPlaneMTU
|
|
|
|
}
|
2017-07-10 15:05:58 -04:00
|
|
|
}
|
2022-09-23 13:40:11 -04:00
|
|
|
c.NetworkControlPlaneMTU = exp
|
2017-07-10 15:05:58 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-01 21:17:29 -05:00
|
|
|
// IsValidName validates configuration objects supported by libnetwork
|
|
|
|
func IsValidName(name string) bool {
|
2017-07-10 15:05:58 -04:00
|
|
|
return strings.TrimSpace(name) != ""
|
2015-06-14 12:00:27 -04:00
|
|
|
}
|
2015-09-16 07:39:46 -04:00
|
|
|
|
|
|
|
// OptionLocalKVProvider function returns an option setter for kvstore provider
|
|
|
|
func OptionLocalKVProvider(provider string) Option {
|
|
|
|
return func(c *Config) {
|
2016-11-01 00:26:14 -04:00
|
|
|
logrus.Debugf("Option OptionLocalKVProvider: %s", provider)
|
2015-10-05 07:21:15 -04:00
|
|
|
if _, ok := c.Scopes[datastore.LocalScope]; !ok {
|
|
|
|
c.Scopes[datastore.LocalScope] = &datastore.ScopeCfg{}
|
|
|
|
}
|
|
|
|
c.Scopes[datastore.LocalScope].Client.Provider = strings.TrimSpace(provider)
|
2015-09-16 07:39:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// OptionLocalKVProviderURL function returns an option setter for kvstore url
|
|
|
|
func OptionLocalKVProviderURL(url string) Option {
|
|
|
|
return func(c *Config) {
|
2016-11-01 00:26:14 -04:00
|
|
|
logrus.Debugf("Option OptionLocalKVProviderURL: %s", url)
|
2015-10-05 07:21:15 -04:00
|
|
|
if _, ok := c.Scopes[datastore.LocalScope]; !ok {
|
|
|
|
c.Scopes[datastore.LocalScope] = &datastore.ScopeCfg{}
|
|
|
|
}
|
|
|
|
c.Scopes[datastore.LocalScope].Client.Address = strings.TrimSpace(url)
|
2015-09-16 07:39:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// OptionLocalKVProviderConfig function returns an option setter for kvstore config
|
|
|
|
func OptionLocalKVProviderConfig(config *store.Config) Option {
|
|
|
|
return func(c *Config) {
|
2016-11-01 00:26:14 -04:00
|
|
|
logrus.Debugf("Option OptionLocalKVProviderConfig: %v", config)
|
2015-10-05 07:21:15 -04:00
|
|
|
if _, ok := c.Scopes[datastore.LocalScope]; !ok {
|
|
|
|
c.Scopes[datastore.LocalScope] = &datastore.ScopeCfg{}
|
|
|
|
}
|
|
|
|
c.Scopes[datastore.LocalScope].Client.Config = config
|
2015-09-16 07:39:46 -04:00
|
|
|
}
|
|
|
|
}
|
2016-06-10 20:32:19 -04:00
|
|
|
|
|
|
|
// OptionActiveSandboxes function returns an option setter for passing the sandboxes
|
|
|
|
// which were active during previous daemon life
|
|
|
|
func OptionActiveSandboxes(sandboxes map[string]interface{}) Option {
|
|
|
|
return func(c *Config) {
|
|
|
|
c.ActiveSandboxes = sandboxes
|
|
|
|
}
|
|
|
|
}
|