Browse code

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>

Madhu Venugopal authored on 2015/09/25 12:00:05
Showing 2 changed files
... ...
@@ -813,25 +813,6 @@ func createNetwork(controller libnetwork.NetworkController, dnet string, driver
813 813
 	return controller.NewNetwork(driver, dnet, createOptions...)
814 814
 }
815 815
 
816
-func (container *Container) secondaryNetworkRequired(ctx context.Context, primaryNetworkType string) bool {
817
-	switch primaryNetworkType {
818
-	case "bridge", "none", "host", "container":
819
-		return false
820
-	}
821
-
822
-	if container.daemon.configStore.DisableBridge {
823
-		return false
824
-	}
825
-
826
-	if container.Config.ExposedPorts != nil && len(container.Config.ExposedPorts) > 0 {
827
-		return true
828
-	}
829
-	if container.hostConfig.PortBindings != nil && len(container.hostConfig.PortBindings) > 0 {
830
-		return true
831
-	}
832
-	return false
833
-}
834
-
835 816
 func (container *Container) allocateNetwork(ctx context.Context) error {
836 817
 	mode := container.hostConfig.NetworkMode
837 818
 	controller := container.daemon.netController
... ...
@@ -866,13 +847,6 @@ func (container *Container) allocateNetwork(ctx context.Context) error {
866 866
 		service = strings.Replace(service, "/", "", -1)
867 867
 	}
868 868
 
869
-	if container.secondaryNetworkRequired(ctx, networkDriver) {
870
-		// Configure Bridge as secondary network for port binding purposes
871
-		if err := container.configureNetwork(ctx, "bridge", service, "bridge", false); err != nil {
872
-			return err
873
-		}
874
-	}
875
-
876 869
 	if err := container.configureNetwork(ctx, networkName, service, networkDriver, mode.IsDefault()); err != nil {
877 870
 		return err
878 871
 	}
... ...
@@ -313,15 +313,16 @@ func networkOptions(dconfig *Config) ([]nwconfig.Option, error) {
313 313
 	}
314 314
 
315 315
 	if strings.TrimSpace(dconfig.NetworkKVStore) != "" {
316
-		kv := strings.Split(dconfig.NetworkKVStore, ":")
316
+		kv := strings.Split(dconfig.NetworkKVStore, "://")
317 317
 		if len(kv) < 2 {
318
-			return nil, fmt.Errorf("kv store daemon config must be of the form KV-PROVIDER:KV-URL")
318
+			return nil, fmt.Errorf("kv store daemon config must be of the form KV-PROVIDER://KV-URL")
319 319
 		}
320 320
 		options = append(options, nwconfig.OptionKVProvider(kv[0]))
321
-		options = append(options, nwconfig.OptionKVProviderURL(strings.Join(kv[1:], ":")))
321
+		options = append(options, nwconfig.OptionKVProviderURL(strings.Join(kv[1:], "://")))
322 322
 	}
323 323
 
324 324
 	options = append(options, nwconfig.OptionLabels(dconfig.Labels))
325
+	options = append(options, driverOptions(dconfig)...)
325 326
 	return options, nil
326 327
 }
327 328
 
... ...
@@ -336,24 +337,13 @@ func initNetworkController(config *Config) (libnetwork.NetworkController, error)
336 336
 		return nil, fmt.Errorf("error obtaining controller instance: %v", err)
337 337
 	}
338 338
 
339
-	// Initialize default driver "null"
340
-
341
-	if err := controller.ConfigureNetworkDriver("null", options.Generic{}); err != nil {
342
-		return nil, fmt.Errorf("Error initializing null driver: %v", err)
343
-	}
344
-
345 339
 	// Initialize default network on "null"
346
-	if _, err := controller.NewNetwork("null", "none"); err != nil {
340
+	if _, err := controller.NewNetwork("null", "none", libnetwork.NetworkOptionPersist(false)); err != nil {
347 341
 		return nil, fmt.Errorf("Error creating default \"null\" network: %v", err)
348 342
 	}
349 343
 
350
-	// Initialize default driver "host"
351
-	if err := controller.ConfigureNetworkDriver("host", options.Generic{}); err != nil {
352
-		return nil, fmt.Errorf("Error initializing host driver: %v", err)
353
-	}
354
-
355 344
 	// Initialize default network on "host"
356
-	if _, err := controller.NewNetwork("host", "host"); err != nil {
345
+	if _, err := controller.NewNetwork("host", "host", libnetwork.NetworkOptionPersist(false)); err != nil {
357 346
 		return nil, fmt.Errorf("Error creating default \"host\" network: %v", err)
358 347
 	}
359 348
 
... ...
@@ -367,18 +357,22 @@ func initNetworkController(config *Config) (libnetwork.NetworkController, error)
367 367
 	return controller, nil
368 368
 }
369 369
 
370
-func initBridgeDriver(controller libnetwork.NetworkController, config *Config) error {
371
-	option := options.Generic{
370
+func driverOptions(config *Config) []nwconfig.Option {
371
+	bridgeConfig := options.Generic{
372 372
 		"EnableIPForwarding":  config.Bridge.EnableIPForward,
373 373
 		"EnableIPTables":      config.Bridge.EnableIPTables,
374 374
 		"EnableUserlandProxy": config.Bridge.EnableUserlandProxy}
375
+	bridgeOption := options.Generic{netlabel.GenericData: bridgeConfig}
375 376
 
376
-	if err := controller.ConfigureNetworkDriver("bridge", options.Generic{netlabel.GenericData: option}); err != nil {
377
-		return fmt.Errorf("Error initializing bridge driver: %v", err)
378
-	}
377
+	dOptions := []nwconfig.Option{}
378
+	dOptions = append(dOptions, nwconfig.OptionDriverConfig("bridge", bridgeOption))
379
+	return dOptions
380
+}
379 381
 
382
+func initBridgeDriver(controller libnetwork.NetworkController, config *Config) error {
380 383
 	netOption := options.Generic{
381 384
 		"BridgeName":         config.Bridge.Iface,
385
+		"DefaultBridge":      true,
382 386
 		"Mtu":                config.Mtu,
383 387
 		"EnableIPMasquerade": config.Bridge.EnableIPMasq,
384 388
 		"EnableICC":          config.Bridge.InterContainerCommunication,
... ...
@@ -430,7 +424,8 @@ func initBridgeDriver(controller libnetwork.NetworkController, config *Config) e
430 430
 		libnetwork.NetworkOptionGeneric(options.Generic{
431 431
 			netlabel.GenericData: netOption,
432 432
 			netlabel.EnableIPv6:  config.Bridge.EnableIPv6,
433
-		}))
433
+		}),
434
+		libnetwork.NetworkOptionPersist(false))
434 435
 	if err != nil {
435 436
 		return fmt.Errorf("Error creating default \"bridge\" network: %v", err)
436 437
 	}