зеркало из https://github.com/microsoft/docker.git
Docker daemon changes to use default gateway service
* Thanks to the Default gateway service in libnetwork, we dont have to add containers explicitly to secondary public network. This is handled automatically regardless of the primary network driver. * Fixed the URL convention for kv-store to be aligned with the upcoming changes to discovery URL * Also, in order to bring consistency between external and internal network drivers, we moved the driver configs via controller Init. Signed-off-by: Madhu Venugopal <madhu@docker.com>
This commit is contained in:
Родитель
59a000ec7f
Коммит
6db1592066
|
@ -813,25 +813,6 @@ func createNetwork(controller libnetwork.NetworkController, dnet string, driver
|
||||||
return controller.NewNetwork(driver, dnet, createOptions...)
|
return controller.NewNetwork(driver, dnet, createOptions...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) secondaryNetworkRequired(ctx context.Context, primaryNetworkType string) bool {
|
|
||||||
switch primaryNetworkType {
|
|
||||||
case "bridge", "none", "host", "container":
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if container.daemon.configStore.DisableBridge {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if container.Config.ExposedPorts != nil && len(container.Config.ExposedPorts) > 0 {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
if container.hostConfig.PortBindings != nil && len(container.hostConfig.PortBindings) > 0 {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (container *Container) allocateNetwork(ctx context.Context) error {
|
func (container *Container) allocateNetwork(ctx context.Context) error {
|
||||||
mode := container.hostConfig.NetworkMode
|
mode := container.hostConfig.NetworkMode
|
||||||
controller := container.daemon.netController
|
controller := container.daemon.netController
|
||||||
|
@ -866,13 +847,6 @@ func (container *Container) allocateNetwork(ctx context.Context) error {
|
||||||
service = strings.Replace(service, "/", "", -1)
|
service = strings.Replace(service, "/", "", -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if container.secondaryNetworkRequired(ctx, networkDriver) {
|
|
||||||
// Configure Bridge as secondary network for port binding purposes
|
|
||||||
if err := container.configureNetwork(ctx, "bridge", service, "bridge", false); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := container.configureNetwork(ctx, networkName, service, networkDriver, mode.IsDefault()); err != nil {
|
if err := container.configureNetwork(ctx, networkName, service, networkDriver, mode.IsDefault()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -313,15 +313,16 @@ func networkOptions(dconfig *Config) ([]nwconfig.Option, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.TrimSpace(dconfig.NetworkKVStore) != "" {
|
if strings.TrimSpace(dconfig.NetworkKVStore) != "" {
|
||||||
kv := strings.Split(dconfig.NetworkKVStore, ":")
|
kv := strings.Split(dconfig.NetworkKVStore, "://")
|
||||||
if len(kv) < 2 {
|
if len(kv) < 2 {
|
||||||
return nil, fmt.Errorf("kv store daemon config must be of the form KV-PROVIDER:KV-URL")
|
return nil, fmt.Errorf("kv store daemon config must be of the form KV-PROVIDER://KV-URL")
|
||||||
}
|
}
|
||||||
options = append(options, nwconfig.OptionKVProvider(kv[0]))
|
options = append(options, nwconfig.OptionKVProvider(kv[0]))
|
||||||
options = append(options, nwconfig.OptionKVProviderURL(strings.Join(kv[1:], ":")))
|
options = append(options, nwconfig.OptionKVProviderURL(strings.Join(kv[1:], "://")))
|
||||||
}
|
}
|
||||||
|
|
||||||
options = append(options, nwconfig.OptionLabels(dconfig.Labels))
|
options = append(options, nwconfig.OptionLabels(dconfig.Labels))
|
||||||
|
options = append(options, driverOptions(dconfig)...)
|
||||||
return options, nil
|
return options, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,24 +337,13 @@ func initNetworkController(config *Config) (libnetwork.NetworkController, error)
|
||||||
return nil, fmt.Errorf("error obtaining controller instance: %v", err)
|
return nil, fmt.Errorf("error obtaining controller instance: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize default driver "null"
|
|
||||||
|
|
||||||
if err := controller.ConfigureNetworkDriver("null", options.Generic{}); err != nil {
|
|
||||||
return nil, fmt.Errorf("Error initializing null driver: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize default network on "null"
|
// Initialize default network on "null"
|
||||||
if _, err := controller.NewNetwork("null", "none"); err != nil {
|
if _, err := controller.NewNetwork("null", "none", libnetwork.NetworkOptionPersist(false)); err != nil {
|
||||||
return nil, fmt.Errorf("Error creating default \"null\" network: %v", err)
|
return nil, fmt.Errorf("Error creating default \"null\" network: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize default driver "host"
|
|
||||||
if err := controller.ConfigureNetworkDriver("host", options.Generic{}); err != nil {
|
|
||||||
return nil, fmt.Errorf("Error initializing host driver: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize default network on "host"
|
// Initialize default network on "host"
|
||||||
if _, err := controller.NewNetwork("host", "host"); err != nil {
|
if _, err := controller.NewNetwork("host", "host", libnetwork.NetworkOptionPersist(false)); err != nil {
|
||||||
return nil, fmt.Errorf("Error creating default \"host\" network: %v", err)
|
return nil, fmt.Errorf("Error creating default \"host\" network: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,18 +357,22 @@ func initNetworkController(config *Config) (libnetwork.NetworkController, error)
|
||||||
return controller, nil
|
return controller, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func initBridgeDriver(controller libnetwork.NetworkController, config *Config) error {
|
func driverOptions(config *Config) []nwconfig.Option {
|
||||||
option := options.Generic{
|
bridgeConfig := options.Generic{
|
||||||
"EnableIPForwarding": config.Bridge.EnableIPForward,
|
"EnableIPForwarding": config.Bridge.EnableIPForward,
|
||||||
"EnableIPTables": config.Bridge.EnableIPTables,
|
"EnableIPTables": config.Bridge.EnableIPTables,
|
||||||
"EnableUserlandProxy": config.Bridge.EnableUserlandProxy}
|
"EnableUserlandProxy": config.Bridge.EnableUserlandProxy}
|
||||||
|
bridgeOption := options.Generic{netlabel.GenericData: bridgeConfig}
|
||||||
|
|
||||||
if err := controller.ConfigureNetworkDriver("bridge", options.Generic{netlabel.GenericData: option}); err != nil {
|
dOptions := []nwconfig.Option{}
|
||||||
return fmt.Errorf("Error initializing bridge driver: %v", err)
|
dOptions = append(dOptions, nwconfig.OptionDriverConfig("bridge", bridgeOption))
|
||||||
}
|
return dOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
func initBridgeDriver(controller libnetwork.NetworkController, config *Config) error {
|
||||||
netOption := options.Generic{
|
netOption := options.Generic{
|
||||||
"BridgeName": config.Bridge.Iface,
|
"BridgeName": config.Bridge.Iface,
|
||||||
|
"DefaultBridge": true,
|
||||||
"Mtu": config.Mtu,
|
"Mtu": config.Mtu,
|
||||||
"EnableIPMasquerade": config.Bridge.EnableIPMasq,
|
"EnableIPMasquerade": config.Bridge.EnableIPMasq,
|
||||||
"EnableICC": config.Bridge.InterContainerCommunication,
|
"EnableICC": config.Bridge.InterContainerCommunication,
|
||||||
|
@ -430,7 +424,8 @@ func initBridgeDriver(controller libnetwork.NetworkController, config *Config) e
|
||||||
libnetwork.NetworkOptionGeneric(options.Generic{
|
libnetwork.NetworkOptionGeneric(options.Generic{
|
||||||
netlabel.GenericData: netOption,
|
netlabel.GenericData: netOption,
|
||||||
netlabel.EnableIPv6: config.Bridge.EnableIPv6,
|
netlabel.EnableIPv6: config.Bridge.EnableIPv6,
|
||||||
}))
|
}),
|
||||||
|
libnetwork.NetworkOptionPersist(false))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error creating default \"bridge\" network: %v", err)
|
return fmt.Errorf("Error creating default \"bridge\" network: %v", err)
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче