mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
daemon: daemon.networkOptions(): don't pass Config as argument
This is a method on the daemon, which itself holds the Config, so there's no need to pass the same configuration as an argument. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
e78f6f9c68
commit
3b56c0663d
4 changed files with 43 additions and 47 deletions
|
@ -471,7 +471,7 @@ func (daemon *Daemon) restore() error {
|
|||
}
|
||||
group.Wait()
|
||||
|
||||
daemon.netController, err = daemon.initNetworkController(daemon.configStore, activeSandboxes)
|
||||
daemon.netController, err = daemon.initNetworkController(activeSandboxes)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error initializing network controller: %v", err)
|
||||
}
|
||||
|
@ -1345,37 +1345,35 @@ func isBridgeNetworkDisabled(conf *config.Config) bool {
|
|||
return conf.BridgeConfig.Iface == config.DisableNetworkBridge
|
||||
}
|
||||
|
||||
func (daemon *Daemon) networkOptions(dconfig *config.Config, pg plugingetter.PluginGetter, activeSandboxes map[string]interface{}) ([]nwconfig.Option, error) {
|
||||
func (daemon *Daemon) networkOptions(pg plugingetter.PluginGetter, activeSandboxes map[string]interface{}) ([]nwconfig.Option, error) {
|
||||
options := []nwconfig.Option{}
|
||||
if dconfig == nil {
|
||||
if daemon.configStore == nil {
|
||||
return options, nil
|
||||
}
|
||||
|
||||
options = append(options, nwconfig.OptionExperimental(dconfig.Experimental))
|
||||
options = append(options, nwconfig.OptionDataDir(dconfig.Root))
|
||||
options = append(options, nwconfig.OptionExecRoot(dconfig.GetExecRoot()))
|
||||
|
||||
conf := daemon.configStore
|
||||
dd := runconfig.DefaultDaemonNetworkMode()
|
||||
dn := runconfig.DefaultDaemonNetworkMode().NetworkName()
|
||||
options = append(options, nwconfig.OptionDefaultDriver(string(dd)))
|
||||
options = append(options, nwconfig.OptionDefaultNetwork(dn))
|
||||
options = append(options, nwconfig.OptionLabels(dconfig.Labels))
|
||||
options = append(options, driverOptions(dconfig))
|
||||
|
||||
if len(dconfig.NetworkConfig.DefaultAddressPools.Value()) > 0 {
|
||||
options = append(options, nwconfig.OptionDefaultAddressPoolConfig(dconfig.NetworkConfig.DefaultAddressPools.Value()))
|
||||
options = []nwconfig.Option{
|
||||
nwconfig.OptionExperimental(conf.Experimental),
|
||||
nwconfig.OptionDataDir(conf.Root),
|
||||
nwconfig.OptionExecRoot(conf.GetExecRoot()),
|
||||
nwconfig.OptionDefaultDriver(string(dd)),
|
||||
nwconfig.OptionDefaultNetwork(dd.NetworkName()),
|
||||
nwconfig.OptionLabels(conf.Labels),
|
||||
nwconfig.OptionNetworkControlPlaneMTU(conf.NetworkControlPlaneMTU),
|
||||
driverOptions(conf),
|
||||
}
|
||||
|
||||
if daemon.configStore != nil && daemon.configStore.LiveRestoreEnabled && len(activeSandboxes) != 0 {
|
||||
if len(conf.NetworkConfig.DefaultAddressPools.Value()) > 0 {
|
||||
options = append(options, nwconfig.OptionDefaultAddressPoolConfig(conf.NetworkConfig.DefaultAddressPools.Value()))
|
||||
}
|
||||
if conf.LiveRestoreEnabled && len(activeSandboxes) != 0 {
|
||||
options = append(options, nwconfig.OptionActiveSandboxes(activeSandboxes))
|
||||
}
|
||||
|
||||
if pg != nil {
|
||||
options = append(options, nwconfig.OptionPluginGetter(pg))
|
||||
}
|
||||
|
||||
options = append(options, nwconfig.OptionNetworkControlPlaneMTU(dconfig.NetworkControlPlaneMTU))
|
||||
|
||||
return options, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -836,8 +836,8 @@ func configureKernelSecuritySupport(config *config.Config, driverName string) er
|
|||
return nil
|
||||
}
|
||||
|
||||
func (daemon *Daemon) initNetworkController(config *config.Config, activeSandboxes map[string]interface{}) (libnetwork.NetworkController, error) {
|
||||
netOptions, err := daemon.networkOptions(config, daemon.PluginStore, activeSandboxes)
|
||||
func (daemon *Daemon) initNetworkController(activeSandboxes map[string]interface{}) (libnetwork.NetworkController, error) {
|
||||
netOptions, err := daemon.networkOptions(daemon.PluginStore, activeSandboxes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -847,9 +847,10 @@ func (daemon *Daemon) initNetworkController(config *config.Config, activeSandbox
|
|||
return nil, fmt.Errorf("error obtaining controller instance: %v", err)
|
||||
}
|
||||
|
||||
conf := daemon.configStore
|
||||
if len(activeSandboxes) > 0 {
|
||||
logrus.Info("There are old running containers, the network config will not take affect")
|
||||
setHostGatewayIP(daemon.configStore, controller)
|
||||
setHostGatewayIP(conf, controller)
|
||||
return controller, nil
|
||||
}
|
||||
|
||||
|
@ -872,14 +873,14 @@ func (daemon *Daemon) initNetworkController(config *config.Config, activeSandbox
|
|||
if err = n.Delete(); err != nil {
|
||||
return nil, fmt.Errorf("could not delete the default bridge network: %v", err)
|
||||
}
|
||||
if len(config.NetworkConfig.DefaultAddressPools.Value()) > 0 && !daemon.configStore.LiveRestoreEnabled {
|
||||
if len(conf.NetworkConfig.DefaultAddressPools.Value()) > 0 && !conf.LiveRestoreEnabled {
|
||||
removeDefaultBridgeInterface()
|
||||
}
|
||||
}
|
||||
|
||||
if !config.DisableBridge {
|
||||
if !conf.DisableBridge {
|
||||
// Initialize default driver "bridge"
|
||||
if err := initBridgeDriver(controller, config); err != nil {
|
||||
if err := initBridgeDriver(controller, conf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
|
@ -887,7 +888,7 @@ func (daemon *Daemon) initNetworkController(config *config.Config, activeSandbox
|
|||
}
|
||||
|
||||
// Set HostGatewayIP to the default bridge's IP if it is empty
|
||||
setHostGatewayIP(daemon.configStore, controller)
|
||||
setHostGatewayIP(conf, controller)
|
||||
|
||||
return controller, nil
|
||||
}
|
||||
|
|
|
@ -236,8 +236,8 @@ func configureMaxThreads(config *config.Config) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (daemon *Daemon) initNetworkController(config *config.Config, activeSandboxes map[string]interface{}) (libnetwork.NetworkController, error) {
|
||||
netOptions, err := daemon.networkOptions(config, nil, nil)
|
||||
func (daemon *Daemon) initNetworkController(activeSandboxes map[string]interface{}) (libnetwork.NetworkController, error) {
|
||||
netOptions, err := daemon.networkOptions(nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -253,8 +253,7 @@ func (daemon *Daemon) initNetworkController(config *config.Config, activeSandbox
|
|||
|
||||
// Remove networks not present in HNS
|
||||
for _, v := range controller.Networks() {
|
||||
options := v.Info().DriverOptions()
|
||||
hnsid := options[winlibnetwork.HNSID]
|
||||
hnsid := v.Info().DriverOptions()[winlibnetwork.HNSID]
|
||||
found := false
|
||||
|
||||
for _, v := range hnsresponse {
|
||||
|
@ -283,9 +282,9 @@ func (daemon *Daemon) initNetworkController(config *config.Config, activeSandbox
|
|||
defaultNetworkExists := false
|
||||
|
||||
if network, err := controller.NetworkByName(runconfig.DefaultDaemonNetworkMode().NetworkName()); err == nil {
|
||||
options := network.Info().DriverOptions()
|
||||
hnsid := network.Info().DriverOptions()[winlibnetwork.HNSID]
|
||||
for _, v := range hnsresponse {
|
||||
if options[winlibnetwork.HNSID] == v.Id {
|
||||
if hnsid == v.Id {
|
||||
defaultNetworkExists = true
|
||||
break
|
||||
}
|
||||
|
@ -301,8 +300,8 @@ func (daemon *Daemon) initNetworkController(config *config.Config, activeSandbox
|
|||
}
|
||||
var n libnetwork.Network
|
||||
s := func(current libnetwork.Network) bool {
|
||||
options := current.Info().DriverOptions()
|
||||
if options[winlibnetwork.HNSID] == v.Id {
|
||||
hnsid := current.Info().DriverOptions()[winlibnetwork.HNSID]
|
||||
if hnsid == v.Id {
|
||||
n = current
|
||||
return true
|
||||
}
|
||||
|
@ -372,9 +371,10 @@ func (daemon *Daemon) initNetworkController(config *config.Config, activeSandbox
|
|||
}
|
||||
}
|
||||
|
||||
if !config.DisableBridge {
|
||||
conf := daemon.configStore
|
||||
if !conf.DisableBridge {
|
||||
// Initialize default driver "bridge"
|
||||
if err := initBridgeDriver(controller, config); err != nil {
|
||||
if err := initBridgeDriver(controller, conf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -343,22 +343,19 @@ func TestDaemonReloadNetworkDiagnosticPort(t *testing.T) {
|
|||
}
|
||||
daemon := &Daemon{
|
||||
imageService: images.NewImageService(images.ImageServiceConfig{}),
|
||||
configStore: &config.Config{},
|
||||
}
|
||||
daemon.configStore = &config.Config{}
|
||||
|
||||
valuesSet := make(map[string]interface{})
|
||||
valuesSet["network-diagnostic-port"] = 2000
|
||||
enableConfig := &config.Config{
|
||||
CommonConfig: config.CommonConfig{
|
||||
NetworkDiagnosticPort: 2000,
|
||||
ValuesSet: valuesSet,
|
||||
ValuesSet: map[string]interface{}{
|
||||
"network-diagnostic-port": 2000,
|
||||
},
|
||||
},
|
||||
}
|
||||
disableConfig := &config.Config{
|
||||
CommonConfig: config.CommonConfig{},
|
||||
}
|
||||
|
||||
netOptions, err := daemon.networkOptions(enableConfig, nil, nil)
|
||||
netOptions, err := daemon.networkOptions(nil, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -376,16 +373,16 @@ func TestDaemonReloadNetworkDiagnosticPort(t *testing.T) {
|
|||
}
|
||||
// Check that the diagnostic is enabled
|
||||
if !daemon.netController.IsDiagnosticEnabled() {
|
||||
t.Fatalf("diagnostic should be enable")
|
||||
t.Fatalf("diagnostic should be enabled")
|
||||
}
|
||||
|
||||
// Reload
|
||||
if err := daemon.Reload(disableConfig); err != nil {
|
||||
if err := daemon.Reload(&config.Config{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Check that the diagnostic is disabled
|
||||
if daemon.netController.IsDiagnosticEnabled() {
|
||||
t.Fatalf("diagnostic should be disable")
|
||||
t.Fatalf("diagnostic should be disabled")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue