Browse code

libnet/d/bridge: trace createNetwork

Plumb context from the API down to libnet driver method `CreateNetwork`,
and add an OTel span to the bridge driver's `createNetwork` method.
Include a few attributes describing the network configuration (e.g.
IPv4/IPv6, ICC, internal and MTU).

A new util function, `RecordStatus`, is added to the `otelutil` package
to easily record any error, and update the span status accordingly.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>

Albin Kerouanton authored on 2025/04/08 02:27:21
Showing 39 changed files
... ...
@@ -12,7 +12,7 @@ import (
12 12
 // to provide network specific functionality.
13 13
 type Backend interface {
14 14
 	GetNetworks(filters.Args, backend.NetworkListConfig) ([]network.Inspect, error)
15
-	CreateNetwork(nc network.CreateRequest) (*network.CreateResponse, error)
15
+	CreateNetwork(ctx context.Context, nc network.CreateRequest) (*network.CreateResponse, error)
16 16
 	ConnectContainerToNetwork(ctx context.Context, containerName, networkName string, endpointConfig *network.EndpointSettings) error
17 17
 	DisconnectContainerFromNetwork(containerName string, networkName string, force bool) error
18 18
 	DeleteNetwork(networkID string) error
... ...
@@ -223,7 +223,7 @@ func (n *networkRouter) postNetworkCreate(ctx context.Context, w http.ResponseWr
223 223
 	// validate the configuration. The network will not be created but, if the
224 224
 	// configuration is valid, ManagerRedirectError will be returned and handled
225 225
 	// below.
226
-	nw, err := n.backend.CreateNetwork(create)
226
+	nw, err := n.backend.CreateNetwork(ctx, create)
227 227
 	if err != nil {
228 228
 		if _, ok := err.(libnetwork.ManagerRedirectError); !ok {
229 229
 			return err
... ...
@@ -868,14 +868,14 @@ func (daemon *Daemon) initNetworkController(cfg *config.Config, activeSandboxes
868 868
 func configureNetworking(controller *libnetwork.Controller, conf *config.Config) error {
869 869
 	// Create predefined network "none"
870 870
 	if n, _ := controller.NetworkByName(network.NetworkNone); n == nil {
871
-		if _, err := controller.NewNetwork("null", network.NetworkNone, "", libnetwork.NetworkOptionPersist(true)); err != nil {
871
+		if _, err := controller.NewNetwork(context.TODO(), "null", network.NetworkNone, "", libnetwork.NetworkOptionPersist(true)); err != nil {
872 872
 			return errors.Wrapf(err, `error creating default %q network`, network.NetworkNone)
873 873
 		}
874 874
 	}
875 875
 
876 876
 	// Create predefined network "host"
877 877
 	if n, _ := controller.NetworkByName(network.NetworkHost); n == nil {
878
-		if _, err := controller.NewNetwork("host", network.NetworkHost, "", libnetwork.NetworkOptionPersist(true)); err != nil {
878
+		if _, err := controller.NewNetwork(context.TODO(), "host", network.NetworkHost, "", libnetwork.NetworkOptionPersist(true)); err != nil {
879 879
 			return errors.Wrapf(err, `error creating default %q network`, network.NetworkHost)
880 880
 		}
881 881
 	}
... ...
@@ -1009,7 +1009,7 @@ func initBridgeDriver(controller *libnetwork.Controller, cfg config.BridgeConfig
1009 1009
 	}
1010 1010
 
1011 1011
 	// Initialize default network on "bridge" with the same name
1012
-	_, err = controller.NewNetwork("bridge", network.NetworkBridge, "",
1012
+	_, err = controller.NewNetwork(context.TODO(), "bridge", network.NetworkBridge, "",
1013 1013
 		libnetwork.NetworkOptionEnableIPv4(true),
1014 1014
 		libnetwork.NetworkOptionEnableIPv6(cfg.EnableIPv6),
1015 1015
 		libnetwork.NetworkOptionDriverOpts(netOption),
... ...
@@ -279,7 +279,7 @@ func (daemon *Daemon) initNetworkController(daemonCfg *config.Config, activeSand
279 279
 					log.G(context.TODO()).Errorf("Error occurred when removing network %v", err)
280 280
 				}
281 281
 
282
-				_, err := daemon.netController.NewNetwork("nat", name, id,
282
+				_, err := daemon.netController.NewNetwork(context.TODO(), "nat", name, id,
283 283
 					libnetwork.NetworkOptionGeneric(options.Generic{
284 284
 						netlabel.GenericData: netOption,
285 285
 					}),
... ...
@@ -301,7 +301,7 @@ func (daemon *Daemon) initNetworkController(daemonCfg *config.Config, activeSand
301 301
 		}
302 302
 	}
303 303
 
304
-	_, err = daemon.netController.NewNetwork("null", "none", "", libnetwork.NetworkOptionPersist(false))
304
+	_, err = daemon.netController.NewNetwork(context.TODO(), "null", "none", "", libnetwork.NetworkOptionPersist(false))
305 305
 	if err != nil {
306 306
 		return err
307 307
 	}
... ...
@@ -384,7 +384,7 @@ func (daemon *Daemon) initNetworkController(daemonCfg *config.Config, activeSand
384 384
 		}
385 385
 
386 386
 		v6Conf := []*libnetwork.IpamConf{}
387
-		_, err := daemon.netController.NewNetwork(strings.ToLower(v.Type), name, nid,
387
+		_, err := daemon.netController.NewNetwork(context.TODO(), strings.ToLower(v.Type), name, nid,
388 388
 			libnetwork.NetworkOptionGeneric(options.Generic{
389 389
 				netlabel.GenericData: netOption,
390 390
 				netlabel.EnableIPv4:  true,
... ...
@@ -430,7 +430,7 @@ func initBridgeDriver(controller *libnetwork.Controller, config config.BridgeCon
430 430
 		ipamOption = libnetwork.NetworkOptionIpam("default", "", v4Conf, v6Conf, nil)
431 431
 	}
432 432
 
433
-	_, err := controller.NewNetwork(network.DefaultNetwork, network.DefaultNetwork, "",
433
+	_, err := controller.NewNetwork(context.TODO(), network.DefaultNetwork, network.DefaultNetwork, "",
434 434
 		libnetwork.NetworkOptionGeneric(options.Generic{
435 435
 			netlabel.GenericData: netOption,
436 436
 			netlabel.EnableIPv4:  true,
... ...
@@ -203,7 +203,7 @@ func (daemon *Daemon) setupIngress(cfg *config.Config, create *clustertypes.Netw
203 203
 		daemon.releaseIngress(staleID)
204 204
 	}
205 205
 
206
-	if _, err := daemon.createNetwork(cfg, create.CreateRequest, create.ID, true); err != nil {
206
+	if _, err := daemon.createNetwork(context.TODO(), cfg, create.CreateRequest, create.ID, true); err != nil {
207 207
 		// If it is any other error other than already
208 208
 		// exists error log error and return.
209 209
 		if _, ok := err.(libnetwork.NetworkNameError); !ok {
... ...
@@ -273,16 +273,16 @@ func (daemon *Daemon) WaitForDetachment(ctx context.Context, networkName, networ
273 273
 
274 274
 // CreateManagedNetwork creates an agent network.
275 275
 func (daemon *Daemon) CreateManagedNetwork(create clustertypes.NetworkCreateRequest) error {
276
-	_, err := daemon.createNetwork(&daemon.config().Config, create.CreateRequest, create.ID, true)
276
+	_, err := daemon.createNetwork(context.TODO(), &daemon.config().Config, create.CreateRequest, create.ID, true)
277 277
 	return err
278 278
 }
279 279
 
280 280
 // CreateNetwork creates a network with the given name, driver and other optional parameters
281
-func (daemon *Daemon) CreateNetwork(create networktypes.CreateRequest) (*networktypes.CreateResponse, error) {
282
-	return daemon.createNetwork(&daemon.config().Config, create, "", false)
281
+func (daemon *Daemon) CreateNetwork(ctx context.Context, create networktypes.CreateRequest) (*networktypes.CreateResponse, error) {
282
+	return daemon.createNetwork(ctx, &daemon.config().Config, create, "", false)
283 283
 }
284 284
 
285
-func (daemon *Daemon) createNetwork(cfg *config.Config, create networktypes.CreateRequest, id string, agent bool) (*networktypes.CreateResponse, error) {
285
+func (daemon *Daemon) createNetwork(ctx context.Context, cfg *config.Config, create networktypes.CreateRequest, id string, agent bool) (*networktypes.CreateResponse, error) {
286 286
 	if network.IsPredefined(create.Name) {
287 287
 		return nil, PredefinedNetworkError(create.Name)
288 288
 	}
... ...
@@ -304,7 +304,7 @@ func (daemon *Daemon) createNetwork(cfg *config.Config, create networktypes.Crea
304 304
 	if defaultOpts, ok := cfg.DefaultNetworkOpts[driver]; create.ConfigFrom == nil && ok {
305 305
 		for k, v := range defaultOpts {
306 306
 			if _, ok := networkOptions[k]; !ok {
307
-				log.G(context.TODO()).WithFields(log.Fields{"driver": driver, "network": id, k: v}).Debug("Applying network default option")
307
+				log.G(ctx).WithFields(log.Fields{"driver": driver, "network": id, k: v}).Debug("Applying network default option")
308 308
 				networkOptions[k] = v
309 309
 			}
310 310
 		}
... ...
@@ -359,7 +359,7 @@ func (daemon *Daemon) createNetwork(cfg *config.Config, create networktypes.Crea
359 359
 			// By dropping errors for agent networks, existing swarm-scoped networks also
360 360
 			// continue to behave as they did before upgrade - but new networks are still
361 361
 			// validated.
362
-			log.G(context.TODO()).WithFields(log.Fields{
362
+			log.G(ctx).WithFields(log.Fields{
363 363
 				"error":   err,
364 364
 				"network": create.Name,
365 365
 			}).Warn("Continuing with validation errors in agent IPAM")
... ...
@@ -398,7 +398,7 @@ func (daemon *Daemon) createNetwork(cfg *config.Config, create networktypes.Crea
398 398
 		nwOptions = append(nwOptions, libnetwork.NetworkOptionLBEndpoint(nodeIP))
399 399
 	}
400 400
 
401
-	n, err := c.NewNetwork(driver, create.Name, id, nwOptions...)
401
+	n, err := c.NewNetwork(ctx, driver, create.Name, id, nwOptions...)
402 402
 	if err != nil {
403 403
 		return nil, err
404 404
 	}
405 405
new file mode 100644
... ...
@@ -0,0 +1,17 @@
0
+package otelutil
1
+
2
+import (
3
+	"go.opentelemetry.io/otel/codes"
4
+	"go.opentelemetry.io/otel/trace"
5
+)
6
+
7
+// RecordStatus records the status of a span based on the error provided.
8
+//
9
+// If err is nil, the span status is unmodified. If err is not nil, the span
10
+// takes status Error, and the error message is recorded.
11
+func RecordStatus(span trace.Span, err error) {
12
+	if err != nil {
13
+		span.RecordError(err)
14
+		span.SetStatus(codes.Error, err.Error())
15
+	}
16
+}
... ...
@@ -28,7 +28,7 @@ func (d *manager) NetworkFree(id string) error {
28 28
 	return types.NotImplementedErrorf("not implemented")
29 29
 }
30 30
 
31
-func (d *manager) CreateNetwork(id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
31
+func (d *manager) CreateNetwork(ctx context.Context, id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
32 32
 	return types.NotImplementedErrorf("not implemented")
33 33
 }
34 34
 
... ...
@@ -179,7 +179,7 @@ func New(cfgOptions ...config.Option) (*Controller, error) {
179 179
 
180 180
 	c.WalkNetworks(func(nw *Network) bool {
181 181
 		if n := nw; n.hasSpecialDriver() && !n.ConfigOnly() {
182
-			if err := n.getController().addNetwork(n); err != nil {
182
+			if err := n.getController().addNetwork(context.TODO(), n); err != nil {
183 183
 				log.G(context.TODO()).Warnf("Failed to populate network %q with driver %q", nw.Name(), nw.Type())
184 184
 			}
185 185
 		}
... ...
@@ -499,7 +499,7 @@ const overlayDSROptionString = "dsr"
499 499
 
500 500
 // NewNetwork creates a new network of the specified network type. The options
501 501
 // are network specific and modeled in a generic way.
502
-func (c *Controller) NewNetwork(networkType, name string, id string, options ...NetworkOption) (_ *Network, retErr error) {
502
+func (c *Controller) NewNetwork(ctx context.Context, networkType, name string, id string, options ...NetworkOption) (_ *Network, retErr error) {
503 503
 	if id != "" {
504 504
 		c.networkLocker.Lock(id)
505 505
 		defer c.networkLocker.Unlock(id) //nolint:errcheck
... ...
@@ -652,7 +652,7 @@ func (c *Controller) NewNetwork(networkType, name string, id string, options ...
652 652
 	// - and updated in 87b082f3659f9ec245ab15d781e6bfffced0af83 to don't use string-matching
653 653
 	//
654 654
 	// To cut a long story short: if this broke anything, you know who to blame :)
655
-	if err := c.addNetwork(nw); err != nil {
655
+	if err := c.addNetwork(ctx, nw); err != nil {
656 656
 		if _, ok := err.(types.MaskableError); !ok { //nolint:gosimple
657 657
 			return nil, err
658 658
 		}
... ...
@@ -660,7 +660,7 @@ func (c *Controller) NewNetwork(networkType, name string, id string, options ...
660 660
 	defer func() {
661 661
 		if retErr != nil {
662 662
 			if err := nw.deleteNetwork(); err != nil {
663
-				log.G(context.TODO()).Warnf("couldn't roll back driver network on network %s creation failure: %v", nw.name, retErr)
663
+				log.G(ctx).Warnf("couldn't roll back driver network on network %s creation failure: %v", nw.name, retErr)
664 664
 			}
665 665
 		}
666 666
 	}()
... ...
@@ -681,13 +681,13 @@ func (c *Controller) NewNetwork(networkType, name string, id string, options ...
681 681
 	}
682 682
 
683 683
 addToStore:
684
-	if err := c.storeNetwork(context.TODO(), nw); err != nil {
684
+	if err := c.storeNetwork(ctx, nw); err != nil {
685 685
 		return nil, err
686 686
 	}
687 687
 	defer func() {
688 688
 		if retErr != nil {
689 689
 			if err := c.deleteStoredNetwork(nw); err != nil {
690
-				log.G(context.TODO()).Warnf("could not rollback from store, network %v on failure (%v): %v", nw, retErr, err)
690
+				log.G(ctx).Warnf("could not rollback from store, network %v on failure (%v): %v", nw, retErr, err)
691 691
 			}
692 692
 		}
693 693
 	}()
... ...
@@ -701,7 +701,7 @@ addToStore:
701 701
 		if retErr != nil {
702 702
 			nw.cancelDriverWatches()
703 703
 			if err := nw.leaveCluster(); err != nil {
704
-				log.G(context.TODO()).Warnf("Failed to leave agent cluster on network %s on failure (%v): %v", nw.name, retErr, err)
704
+				log.G(ctx).Warnf("Failed to leave agent cluster on network %s on failure (%v): %v", nw.name, retErr, err)
705 705
 			}
706 706
 		}
707 707
 	}()
... ...
@@ -801,14 +801,14 @@ func doReplayPoolReserve(n *Network) bool {
801 801
 	return caps.RequiresRequestReplay
802 802
 }
803 803
 
804
-func (c *Controller) addNetwork(n *Network) error {
804
+func (c *Controller) addNetwork(ctx context.Context, n *Network) error {
805 805
 	d, err := n.driver(true)
806 806
 	if err != nil {
807 807
 		return err
808 808
 	}
809 809
 
810 810
 	// Create the network
811
-	if err := d.CreateNetwork(n.id, n.generic, n, n.getIPData(4), n.getIPData(6)); err != nil {
811
+	if err := d.CreateNetwork(ctx, n.id, n.generic, n, n.getIPData(4), n.getIPData(6)); err != nil {
812 812
 		return err
813 813
 	}
814 814
 
... ...
@@ -1,6 +1,7 @@
1 1
 package libnetwork
2 2
 
3 3
 import (
4
+	"context"
4 5
 	"fmt"
5 6
 	"strconv"
6 7
 
... ...
@@ -14,7 +15,7 @@ func getPlatformOption() EndpointOption {
14 14
 }
15 15
 
16 16
 func (c *Controller) createGWNetwork() (*Network, error) {
17
-	n, err := c.NewNetwork("bridge", libnGWNetwork, "",
17
+	n, err := c.NewNetwork(context.TODO(), "bridge", libnGWNetwork, "",
18 18
 		NetworkOptionDriverOpts(map[string]string{
19 19
 			bridge.BridgeName:         libnGWNetwork,
20 20
 			bridge.EnableICC:          strconv.FormatBool(false),
... ...
@@ -30,7 +30,7 @@ type Driver interface {
30 30
 	// notification when a CRUD operation is performed on any
31 31
 	// entry in that table. This will be ignored for local scope
32 32
 	// drivers.
33
-	CreateNetwork(nid string, options map[string]interface{}, nInfo NetworkInfo, ipV4Data, ipV6Data []IPAMData) error
33
+	CreateNetwork(ctx context.Context, nid string, options map[string]interface{}, nInfo NetworkInfo, ipV4Data, ipV6Data []IPAMData) error
34 34
 
35 35
 	// DeleteNetwork invokes the driver method to delete network passing
36 36
 	// the network id.
... ...
@@ -14,6 +14,7 @@ import (
14 14
 	"github.com/docker/docker/errdefs"
15 15
 	"github.com/docker/docker/internal/modprobe"
16 16
 	"github.com/docker/docker/internal/nlwrap"
17
+	"github.com/docker/docker/internal/otelutil"
17 18
 	"github.com/docker/docker/libnetwork/datastore"
18 19
 	"github.com/docker/docker/libnetwork/driverapi"
19 20
 	"github.com/docker/docker/libnetwork/drivers/bridge/internal/rlkclient"
... ...
@@ -741,7 +742,7 @@ func (d *driver) GetSkipGwAlloc(opts options.Generic) (ipv4, ipv6 bool, _ error)
741 741
 }
742 742
 
743 743
 // CreateNetwork creates a new network using the bridge driver.
744
-func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
744
+func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
745 745
 	// Sanity checks
746 746
 	d.Lock()
747 747
 	if _, ok := d.networks[id]; ok {
... ...
@@ -787,11 +788,11 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
787 787
 	}
788 788
 
789 789
 	// there is no conflict, now create the network
790
-	if err = d.createNetwork(config); err != nil {
790
+	if err = d.createNetwork(ctx, config); err != nil {
791 791
 		return err
792 792
 	}
793 793
 
794
-	return d.storeUpdate(context.TODO(), config)
794
+	return d.storeUpdate(ctx, config)
795 795
 }
796 796
 
797 797
 func (d *driver) checkConflict(config *networkConfiguration) error {
... ...
@@ -808,7 +809,18 @@ func (d *driver) checkConflict(config *networkConfiguration) error {
808 808
 	return nil
809 809
 }
810 810
 
811
-func (d *driver) createNetwork(config *networkConfiguration) (err error) {
811
+func (d *driver) createNetwork(ctx context.Context, config *networkConfiguration) (err error) {
812
+	ctx, span := otel.Tracer("").Start(ctx, "libnetwork.drivers.bridge.createNetwork", trace.WithAttributes(
813
+		attribute.Bool("bridge.enable_ipv4", config.EnableIPv4),
814
+		attribute.Bool("bridge.enable_ipv6", config.EnableIPv6),
815
+		attribute.Bool("bridge.icc", config.EnableICC),
816
+		attribute.Int("bridge.mtu", config.Mtu),
817
+		attribute.Bool("bridge.internal", config.Internal)))
818
+	defer func() {
819
+		otelutil.RecordStatus(span, err)
820
+		span.End()
821
+	}()
822
+
812 823
 	// Create or retrieve the bridge L3 interface
813 824
 	bridgeIface, err := newInterface(d.nlh, config)
814 825
 	if err != nil {
... ...
@@ -280,7 +280,7 @@ func TestCreateFullOptions(t *testing.T) {
280 280
 			AuxAddresses: map[string]*net.IPNet{DefaultGatewayV4AuxKey: defgw},
281 281
 		},
282 282
 	}
283
-	err := d.CreateNetwork("dummy", netOption, nil, ipdList, getIPv6Data(t))
283
+	err := d.CreateNetwork(context.Background(), "dummy", netOption, nil, ipdList, getIPv6Data(t))
284 284
 	if err != nil {
285 285
 		t.Fatalf("Failed to create bridge: %v", err)
286 286
 	}
... ...
@@ -306,7 +306,7 @@ func TestCreateNoConfig(t *testing.T) {
306 306
 	genericOption := make(map[string]interface{})
307 307
 	genericOption[netlabel.GenericData] = netconfig
308 308
 
309
-	if err := d.CreateNetwork("dummy", genericOption, nil, getIPv4Data(t), nil); err != nil {
309
+	if err := d.CreateNetwork(context.Background(), "dummy", genericOption, nil, getIPv4Data(t), nil); err != nil {
310 310
 		t.Fatalf("Failed to create bridge: %v", err)
311 311
 	}
312 312
 }
... ...
@@ -356,7 +356,7 @@ func TestCreateFullOptionsLabels(t *testing.T) {
356 356
 		},
357 357
 	}
358 358
 
359
-	err := d.CreateNetwork("dummy", netOption, nil, ipdList, ipd6List)
359
+	err := d.CreateNetwork(context.Background(), "dummy", netOption, nil, ipdList, ipd6List)
360 360
 	if err != nil {
361 361
 		t.Fatalf("Failed to create bridge: %v", err)
362 362
 	}
... ...
@@ -510,11 +510,11 @@ func TestCreate(t *testing.T) {
510 510
 	genericOption := make(map[string]interface{})
511 511
 	genericOption[netlabel.GenericData] = netconfig
512 512
 
513
-	if err := d.CreateNetwork("dummy", genericOption, nil, getIPv4Data(t), nil); err != nil {
513
+	if err := d.CreateNetwork(context.Background(), "dummy", genericOption, nil, getIPv4Data(t), nil); err != nil {
514 514
 		t.Fatalf("Failed to create bridge: %v", err)
515 515
 	}
516 516
 
517
-	err := d.CreateNetwork("dummy", genericOption, nil, getIPv4Data(t), nil)
517
+	err := d.CreateNetwork(context.Background(), "dummy", genericOption, nil, getIPv4Data(t), nil)
518 518
 	if err == nil {
519 519
 		t.Fatal("Expected bridge driver to refuse creation of second network with default name")
520 520
 	}
... ...
@@ -536,7 +536,7 @@ func TestCreateFail(t *testing.T) {
536 536
 	genericOption := make(map[string]interface{})
537 537
 	genericOption[netlabel.GenericData] = netconfig
538 538
 
539
-	if err := d.CreateNetwork("dummy", genericOption, nil, getIPv4Data(t), nil); err == nil {
539
+	if err := d.CreateNetwork(context.Background(), "dummy", genericOption, nil, getIPv4Data(t), nil); err == nil {
540 540
 		t.Fatal("Bridge creation was expected to fail")
541 541
 	}
542 542
 }
... ...
@@ -559,7 +559,7 @@ func TestCreateMultipleNetworks(t *testing.T) {
559 559
 	config1 := &networkConfiguration{BridgeName: "net_test_1", EnableIPv4: true}
560 560
 	genericOption = make(map[string]interface{})
561 561
 	genericOption[netlabel.GenericData] = config1
562
-	if err := d.CreateNetwork("1", genericOption, nil, getIPv4Data(t), nil); err != nil {
562
+	if err := d.CreateNetwork(context.Background(), "1", genericOption, nil, getIPv4Data(t), nil); err != nil {
563 563
 		t.Fatalf("Failed to create bridge: %v", err)
564 564
 	}
565 565
 
... ...
@@ -567,7 +567,7 @@ func TestCreateMultipleNetworks(t *testing.T) {
567 567
 
568 568
 	config2 := &networkConfiguration{BridgeName: "net_test_2", EnableIPv4: true}
569 569
 	genericOption[netlabel.GenericData] = config2
570
-	if err := d.CreateNetwork("2", genericOption, nil, getIPv4Data(t), nil); err != nil {
570
+	if err := d.CreateNetwork(context.Background(), "2", genericOption, nil, getIPv4Data(t), nil); err != nil {
571 571
 		t.Fatalf("Failed to create bridge: %v", err)
572 572
 	}
573 573
 
... ...
@@ -575,7 +575,7 @@ func TestCreateMultipleNetworks(t *testing.T) {
575 575
 
576 576
 	config3 := &networkConfiguration{BridgeName: "net_test_3", EnableIPv4: true}
577 577
 	genericOption[netlabel.GenericData] = config3
578
-	if err := d.CreateNetwork("3", genericOption, nil, getIPv4Data(t), nil); err != nil {
578
+	if err := d.CreateNetwork(context.Background(), "3", genericOption, nil, getIPv4Data(t), nil); err != nil {
579 579
 		t.Fatalf("Failed to create bridge: %v", err)
580 580
 	}
581 581
 
... ...
@@ -583,7 +583,7 @@ func TestCreateMultipleNetworks(t *testing.T) {
583 583
 
584 584
 	config4 := &networkConfiguration{BridgeName: "net_test_4", EnableIPv4: true}
585 585
 	genericOption[netlabel.GenericData] = config4
586
-	if err := d.CreateNetwork("4", genericOption, nil, getIPv4Data(t), nil); err != nil {
586
+	if err := d.CreateNetwork(context.Background(), "4", genericOption, nil, getIPv4Data(t), nil); err != nil {
587 587
 		t.Fatalf("Failed to create bridge: %v", err)
588 588
 	}
589 589
 
... ...
@@ -805,7 +805,7 @@ func testQueryEndpointInfo(t *testing.T, ulPxyEnabled bool) {
805 805
 	genericOption[netlabel.GenericData] = netconfig
806 806
 
807 807
 	ipdList := getIPv4Data(t)
808
-	err = d.CreateNetwork("net1", genericOption, nil, ipdList, nil)
808
+	err = d.CreateNetwork(context.Background(), "net1", genericOption, nil, ipdList, nil)
809 809
 	if err != nil {
810 810
 		t.Fatalf("Failed to create bridge: %v", err)
811 811
 	}
... ...
@@ -908,7 +908,7 @@ func TestLinkContainers(t *testing.T) {
908 908
 	genericOption[netlabel.GenericData] = netconfig
909 909
 
910 910
 	ipdList := getIPv4Data(t)
911
-	err := d.CreateNetwork("net1", genericOption, nil, ipdList, nil)
911
+	err := d.CreateNetwork(context.Background(), "net1", genericOption, nil, ipdList, nil)
912 912
 	if err != nil {
913 913
 		t.Fatalf("Failed to create bridge: %v", err)
914 914
 	}
... ...
@@ -1218,7 +1218,7 @@ func TestSetDefaultGw(t *testing.T) {
1218 1218
 		},
1219 1219
 	}
1220 1220
 
1221
-	err := d.CreateNetwork("dummy", option, nil, ipam4, ipam6)
1221
+	err := d.CreateNetwork(context.Background(), "dummy", option, nil, ipam4, ipam6)
1222 1222
 	if err != nil {
1223 1223
 		t.Fatalf("Failed to create bridge: %v", err)
1224 1224
 	}
... ...
@@ -1341,7 +1341,7 @@ func TestCreateWithExistingBridge(t *testing.T) {
1341 1341
 	// Set network gateway to X.X.X.1
1342 1342
 	ipv4Data[0].Gateway.IP[len(ipv4Data[0].Gateway.IP)-1] = 1
1343 1343
 
1344
-	if err := d.CreateNetwork(brName, genericOption, nil, ipv4Data, nil); err != nil {
1344
+	if err := d.CreateNetwork(context.Background(), brName, genericOption, nil, ipv4Data, nil); err != nil {
1345 1345
 		t.Fatalf("Failed to create bridge network: %v", err)
1346 1346
 	}
1347 1347
 
... ...
@@ -1388,11 +1388,11 @@ func TestCreateParallel(t *testing.T) {
1388 1388
 			config := &networkConfiguration{BridgeName: name, EnableIPv4: true}
1389 1389
 			genericOption := make(map[string]interface{})
1390 1390
 			genericOption[netlabel.GenericData] = config
1391
-			if err := d.CreateNetwork(name, genericOption, nil, ipV4Data, nil); err != nil {
1391
+			if err := d.CreateNetwork(context.Background(), name, genericOption, nil, ipV4Data, nil); err != nil {
1392 1392
 				ch <- fmt.Errorf("failed to create %s", name)
1393 1393
 				return
1394 1394
 			}
1395
-			if err := d.CreateNetwork(name, genericOption, nil, ipV4Data, nil); err == nil {
1395
+			if err := d.CreateNetwork(context.Background(), name, genericOption, nil, ipV4Data, nil); err == nil {
1396 1396
 				ch <- fmt.Errorf("failed was able to create overlap %s", name)
1397 1397
 				return
1398 1398
 			}
... ...
@@ -51,7 +51,7 @@ func (d *driver) populateNetworks() error {
51 51
 
52 52
 	for _, kvo := range kvol {
53 53
 		ncfg := kvo.(*networkConfiguration)
54
-		if err = d.createNetwork(ncfg); err != nil {
54
+		if err = d.createNetwork(context.TODO(), ncfg); err != nil {
55 55
 			log.G(context.TODO()).Warnf("could not create bridge network for id %s bridge name %s while booting up from persistent state: %v", ncfg.ID, ncfg.BridgeName, err)
56 56
 		}
57 57
 		log.G(context.TODO()).Debugf("Network (%.7s) restored", ncfg.ID)
... ...
@@ -28,7 +28,7 @@ func (d *driver) NetworkFree(id string) error {
28 28
 	return types.NotImplementedErrorf("not implemented")
29 29
 }
30 30
 
31
-func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
31
+func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
32 32
 	return types.NotImplementedErrorf("not implemented")
33 33
 }
34 34
 
... ...
@@ -31,7 +31,7 @@ func TestLinkCreate(t *testing.T) {
31 31
 
32 32
 	ipdList := getIPv4Data(t)
33 33
 	ipd6List := getIPv6Data(t)
34
-	err = d.CreateNetwork("dummy", option, nil, ipdList, ipd6List)
34
+	err = d.CreateNetwork(context.Background(), "dummy", option, nil, ipdList, ipd6List)
35 35
 	assert.NilError(t, err, "Failed to create bridge")
36 36
 
37 37
 	te := newTestEndpoint46(ipdList[0].Pool, ipd6List[0].Pool, 10)
... ...
@@ -91,7 +91,7 @@ func TestLinkCreateTwo(t *testing.T) {
91 91
 	}
92 92
 
93 93
 	ipdList := getIPv4Data(t)
94
-	err = d.CreateNetwork("dummy", option, nil, ipdList, getIPv6Data(t))
94
+	err = d.CreateNetwork(context.Background(), "dummy", option, nil, ipdList, getIPv6Data(t))
95 95
 	assert.NilError(t, err, "Failed to create bridge")
96 96
 
97 97
 	te1 := newTestEndpoint(ipdList[0].Pool, 11)
... ...
@@ -118,7 +118,7 @@ func TestLinkCreateNoEnableIPv6(t *testing.T) {
118 118
 	}
119 119
 
120 120
 	ipdList := getIPv4Data(t)
121
-	err = d.CreateNetwork("dummy", option, nil, ipdList, getIPv6Data(t))
121
+	err = d.CreateNetwork(context.Background(), "dummy", option, nil, ipdList, getIPv6Data(t))
122 122
 	assert.NilError(t, err, "Failed to create bridge")
123 123
 
124 124
 	te := newTestEndpoint(ipdList[0].Pool, 30)
... ...
@@ -144,7 +144,7 @@ func TestLinkDelete(t *testing.T) {
144 144
 	}
145 145
 
146 146
 	ipdList := getIPv4Data(t)
147
-	err = d.CreateNetwork("dummy", option, nil, ipdList, getIPv6Data(t))
147
+	err = d.CreateNetwork(context.Background(), "dummy", option, nil, ipdList, getIPv6Data(t))
148 148
 	assert.NilError(t, err, "Failed to create bridge")
149 149
 
150 150
 	te := newTestEndpoint(ipdList[0].Pool, 30)
... ...
@@ -56,7 +56,7 @@ func TestPortMappingConfig(t *testing.T) {
56 56
 	}
57 57
 
58 58
 	ipdList4 := getIPv4Data(t)
59
-	err := d.CreateNetwork("dummy", netOptions, nil, ipdList4, getIPv6Data(t))
59
+	err := d.CreateNetwork(context.Background(), "dummy", netOptions, nil, ipdList4, getIPv6Data(t))
60 60
 	if err != nil {
61 61
 		t.Fatalf("Failed to create bridge: %v", err)
62 62
 	}
... ...
@@ -142,7 +142,7 @@ func TestPortMappingV6Config(t *testing.T) {
142 142
 
143 143
 	ipdList4 := getIPv4Data(t)
144 144
 	ipdList6 := getIPv6Data(t)
145
-	err := d.CreateNetwork("dummy", netOptions, nil, ipdList4, ipdList6)
145
+	err := d.CreateNetwork(context.Background(), "dummy", netOptions, nil, ipdList4, ipdList6)
146 146
 	if err != nil {
147 147
 		t.Fatalf("Failed to create bridge: %v", err)
148 148
 	}
... ...
@@ -381,7 +381,7 @@ func TestOutgoingNATRules(t *testing.T) {
381 381
 				nc.AddressIPv6 = nil
382 382
 				ipv6Data = nil
383 383
 			}
384
-			if err := r.d.CreateNetwork("nattest", map[string]interface{}{netlabel.GenericData: nc}, nil, ipv4Data, ipv6Data); err != nil {
384
+			if err := r.d.CreateNetwork(context.Background(), "nattest", map[string]interface{}{netlabel.GenericData: nc}, nil, ipv4Data, ipv6Data); err != nil {
385 385
 				t.Fatal(err)
386 386
 			}
387 387
 			defer func() {
... ...
@@ -38,7 +38,7 @@ func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (s
38 38
 	return "", nil
39 39
 }
40 40
 
41
-func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
41
+func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
42 42
 	d.Lock()
43 43
 	defer d.Unlock()
44 44
 
... ...
@@ -1,6 +1,7 @@
1 1
 package host
2 2
 
3 3
 import (
4
+	"context"
4 5
 	"testing"
5 6
 
6 7
 	"github.com/docker/docker/libnetwork/types"
... ...
@@ -13,7 +14,7 @@ func TestDriver(t *testing.T) {
13 13
 		t.Fatal("Unexpected network type returned by driver")
14 14
 	}
15 15
 
16
-	err := d.CreateNetwork("first", nil, nil, nil, nil)
16
+	err := d.CreateNetwork(context.Background(), "first", nil, nil, nil, nil)
17 17
 	if err != nil {
18 18
 		t.Fatal(err)
19 19
 	}
... ...
@@ -22,7 +23,7 @@ func TestDriver(t *testing.T) {
22 22
 		t.Fatal("Unexpected network id stored")
23 23
 	}
24 24
 
25
-	err = d.CreateNetwork("second", nil, nil, nil, nil)
25
+	err = d.CreateNetwork(context.Background(), "second", nil, nil, nil, nil)
26 26
 	if err == nil {
27 27
 		t.Fatal("Second network creation should fail on this driver")
28 28
 	}
... ...
@@ -17,7 +17,7 @@ import (
17 17
 )
18 18
 
19 19
 // CreateNetwork the network for the specified driver type
20
-func (d *driver) CreateNetwork(nid string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
20
+func (d *driver) CreateNetwork(ctx context.Context, nid string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
21 21
 	kv, err := kernel.GetKernelVersion()
22 22
 	if err != nil {
23 23
 		return fmt.Errorf("failed to check kernel version for ipvlan driver support: %v", err)
... ...
@@ -28,7 +28,7 @@ func (d *driver) NetworkFree(id string) error {
28 28
 	return types.NotImplementedErrorf("not implemented")
29 29
 }
30 30
 
31
-func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
31
+func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
32 32
 	return types.NotImplementedErrorf("not implemented")
33 33
 }
34 34
 
... ...
@@ -16,7 +16,7 @@ import (
16 16
 )
17 17
 
18 18
 // CreateNetwork the network for the specified driver type
19
-func (d *driver) CreateNetwork(nid string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
19
+func (d *driver) CreateNetwork(ctx context.Context, nid string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
20 20
 	// reject a null v4 network if ipv4 is required
21 21
 	if v, ok := option[netlabel.EnableIPv4]; ok && v.(bool) {
22 22
 		if len(ipV4Data) == 0 || ipV4Data[0].Pool.String() == "0.0.0.0/0" {
... ...
@@ -28,7 +28,7 @@ func (d *driver) NetworkFree(id string) error {
28 28
 	return types.NotImplementedErrorf("not implemented")
29 29
 }
30 30
 
31
-func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
31
+func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
32 32
 	return types.NotImplementedErrorf("not implemented")
33 33
 }
34 34
 
... ...
@@ -38,7 +38,7 @@ func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (s
38 38
 	return "", nil
39 39
 }
40 40
 
41
-func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
41
+func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
42 42
 	d.Lock()
43 43
 	defer d.Unlock()
44 44
 
... ...
@@ -1,6 +1,7 @@
1 1
 package null
2 2
 
3 3
 import (
4
+	"context"
4 5
 	"testing"
5 6
 
6 7
 	"github.com/docker/docker/libnetwork/types"
... ...
@@ -13,7 +14,7 @@ func TestDriver(t *testing.T) {
13 13
 		t.Fatalf("Unexpected network type returned by driver")
14 14
 	}
15 15
 
16
-	err := d.CreateNetwork("first", nil, nil, nil, nil)
16
+	err := d.CreateNetwork(context.Background(), "first", nil, nil, nil, nil)
17 17
 	if err != nil {
18 18
 		t.Fatal(err)
19 19
 	}
... ...
@@ -22,7 +23,7 @@ func TestDriver(t *testing.T) {
22 22
 		t.Fatalf("Unexpected network id stored")
23 23
 	}
24 24
 
25
-	err = d.CreateNetwork("second", nil, nil, nil, nil)
25
+	err = d.CreateNetwork(context.Background(), "second", nil, nil, nil, nil)
26 26
 	if err == nil {
27 27
 		t.Fatalf("Second network creation should fail on this driver")
28 28
 	}
... ...
@@ -79,7 +79,7 @@ func (d *driver) NetworkFree(id string) error {
79 79
 	return types.NotImplementedErrorf("not implemented")
80 80
 }
81 81
 
82
-func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
82
+func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
83 83
 	if id == "" {
84 84
 		return fmt.Errorf("invalid network id")
85 85
 	}
... ...
@@ -162,7 +162,7 @@ func (n *network) releaseVxlanID() {
162 162
 	}
163 163
 }
164 164
 
165
-func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
165
+func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
166 166
 	return types.NotImplementedErrorf("not implemented")
167 167
 }
168 168
 
... ...
@@ -162,7 +162,7 @@ func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (s
162 162
 	return "", nil
163 163
 }
164 164
 
165
-func (d *driver) CreateNetwork(id string, options map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
165
+func (d *driver) CreateNetwork(ctx context.Context, id string, options map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
166 166
 	create := &api.CreateNetworkRequest{
167 167
 		NetworkID: id,
168 168
 		Options:   options,
... ...
@@ -459,7 +459,7 @@ func TestRemoteDriver(t *testing.T) {
459 459
 	}
460 460
 
461 461
 	netID := "dummy-network"
462
-	err = d.CreateNetwork(netID, map[string]interface{}{}, nil, nil, nil)
462
+	err = d.CreateNetwork(context.Background(), netID, map[string]interface{}{}, nil, nil, nil)
463 463
 	if err != nil {
464 464
 		t.Fatal(err)
465 465
 	}
... ...
@@ -60,7 +60,7 @@ func (d *driver) NetworkFree(id string) error {
60 60
 	return types.NotImplementedErrorf("not implemented")
61 61
 }
62 62
 
63
-func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
63
+func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
64 64
 	var (
65 65
 		networkName   string
66 66
 		interfaceName string
... ...
@@ -84,10 +84,10 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
84 84
 
85 85
 	existingNetwork := d.network(id)
86 86
 	if existingNetwork != nil {
87
-		log.G(context.TODO()).Debugf("Network preexists. Deleting %s", id)
87
+		log.G(ctx).Debugf("Network preexists. Deleting %s", id)
88 88
 		err := d.DeleteNetwork(id)
89 89
 		if err != nil {
90
-			log.G(context.TODO()).Errorf("Error deleting stale network %s", err.Error())
90
+			log.G(ctx).Errorf("Error deleting stale network %s", err.Error())
91 91
 		}
92 92
 	}
93 93
 
... ...
@@ -281,7 +281,7 @@ func (d *driver) createNetwork(config *networkConfiguration) *hnsNetwork {
281 281
 }
282 282
 
283 283
 // Create a new network
284
-func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
284
+func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
285 285
 	if _, err := d.getNetwork(id); err == nil {
286 286
 		return types.ForbiddenErrorf("network %s exists", id)
287 287
 	}
... ...
@@ -371,7 +371,7 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
371 371
 		}
372 372
 
373 373
 		configuration := string(configurationb)
374
-		log.G(context.TODO()).Debugf("HNSNetwork Request =%v Address Space=%v", configuration, subnets)
374
+		log.G(ctx).Debugf("HNSNetwork Request =%v Address Space=%v", configuration, subnets)
375 375
 
376 376
 		hnsresponse, err := hcsshim.HNSNetworkRequest("POST", "", configuration)
377 377
 		if err != nil {
... ...
@@ -416,15 +416,15 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
416 416
 		if endpoints, err := hcsshim.HNSListEndpointRequest(); err == nil {
417 417
 			for _, ep := range endpoints {
418 418
 				if ep.VirtualNetwork == config.HnsID {
419
-					log.G(context.TODO()).Infof("Removing stale HNS endpoint %s", ep.Id)
419
+					log.G(ctx).Infof("Removing stale HNS endpoint %s", ep.Id)
420 420
 					_, err = hcsshim.HNSEndpointRequest("DELETE", ep.Id, "")
421 421
 					if err != nil {
422
-						log.G(context.TODO()).Warnf("Error removing HNS endpoint %s", ep.Id)
422
+						log.G(ctx).Warnf("Error removing HNS endpoint %s", ep.Id)
423 423
 					}
424 424
 				}
425 425
 			}
426 426
 		} else {
427
-			log.G(context.TODO()).Warnf("Error listing HNS endpoints for network %s", config.HnsID)
427
+			log.G(ctx).Warnf("Error listing HNS endpoints for network %s", config.HnsID)
428 428
 		}
429 429
 
430 430
 		n.created = true
... ...
@@ -33,7 +33,7 @@ func testNetwork(networkType string, t *testing.T) {
33 33
 		},
34 34
 	}
35 35
 
36
-	err = d.CreateNetwork("dummy", netOption, nil, ipdList, nil)
36
+	err = d.CreateNetwork(context.Background(), "dummy", netOption, nil, ipdList, nil)
37 37
 	if err != nil {
38 38
 		t.Fatalf("Failed to create bridge: %v", err)
39 39
 	}
... ...
@@ -416,7 +416,7 @@ func TestUpdateSvcRecord(t *testing.T) {
416 416
 				assert.NilError(t, err)
417 417
 				ipam6 = []*IpamConf{{PreferredPool: net6.String()}}
418 418
 			}
419
-			n, err := ctrlr.NewNetwork("bridge", "net1", "", nil,
419
+			n, err := ctrlr.NewNetwork(context.Background(), "bridge", "net1", "", nil,
420 420
 				NetworkOptionEnableIPv4(tc.addr4 != ""),
421 421
 				NetworkOptionEnableIPv6(tc.addr6 != ""),
422 422
 				NetworkOptionIpam(defaultipam.DriverName, "", ipam4, ipam6, nil),
... ...
@@ -484,7 +484,7 @@ func TestSRVServiceQuery(t *testing.T) {
484 484
 	}
485 485
 	defer c.Stop()
486 486
 
487
-	n, err := c.NewNetwork("bridge", "net1", "",
487
+	n, err := c.NewNetwork(context.Background(), "bridge", "net1", "",
488 488
 		NetworkOptionEnableIPv4(true),
489 489
 	)
490 490
 	if err != nil {
... ...
@@ -585,7 +585,7 @@ func TestServiceVIPReuse(t *testing.T) {
585 585
 	}
586 586
 	defer c.Stop()
587 587
 
588
-	n, err := c.NewNetwork("bridge", "net1", "", nil,
588
+	n, err := c.NewNetwork(context.Background(), "bridge", "net1", "", nil,
589 589
 		NetworkOptionEnableIPv4(true),
590 590
 	)
591 591
 	if err != nil {
... ...
@@ -712,10 +712,10 @@ func TestIpamReleaseOnNetDriverFailures(t *testing.T) {
712 712
 	// Test whether ipam state release is invoked  on network create failure from net driver
713 713
 	// by checking whether subsequent network creation requesting same gateway IP succeeds
714 714
 	ipamOpt := NetworkOptionIpam(defaultipam.DriverName, "", []*IpamConf{{PreferredPool: "10.34.0.0/16", Gateway: "10.34.255.254"}}, nil, nil)
715
-	_, err = c.NewNetwork(badDriverName, "badnet1", "", ipamOpt)
715
+	_, err = c.NewNetwork(context.Background(), badDriverName, "badnet1", "", ipamOpt)
716 716
 	assert.Check(t, is.ErrorContains(err, "I will not create any network"))
717 717
 
718
-	gnw, err := c.NewNetwork("bridge", "goodnet1", "",
718
+	gnw, err := c.NewNetwork(context.Background(), "bridge", "goodnet1", "",
719 719
 		NetworkOptionEnableIPv4(true),
720 720
 		ipamOpt,
721 721
 	)
... ...
@@ -728,7 +728,7 @@ func TestIpamReleaseOnNetDriverFailures(t *testing.T) {
728 728
 
729 729
 	// Now check whether ipam release works on endpoint creation failure
730 730
 	bd.failNetworkCreation = false
731
-	bnw, err := c.NewNetwork(badDriverName, "badnet2", "",
731
+	bnw, err := c.NewNetwork(context.Background(), badDriverName, "badnet2", "",
732 732
 		NetworkOptionEnableIPv4(true),
733 733
 		ipamOpt,
734 734
 	)
... ...
@@ -747,7 +747,7 @@ func TestIpamReleaseOnNetDriverFailures(t *testing.T) {
747 747
 
748 748
 	// Now create good bridge network with different gateway
749 749
 	ipamOpt2 := NetworkOptionIpam(defaultipam.DriverName, "", []*IpamConf{{PreferredPool: "10.35.0.0/16", Gateway: "10.35.255.253"}}, nil, nil)
750
-	gnw, err = c.NewNetwork("bridge", "goodnet2", "",
750
+	gnw, err = c.NewNetwork(context.Background(), "bridge", "goodnet2", "",
751 751
 		NetworkOptionEnableIPv4(true),
752 752
 		ipamOpt2,
753 753
 	)
... ...
@@ -784,7 +784,7 @@ func badDriverRegister(reg driverapi.Registerer) error {
784 784
 	return reg.RegisterDriver(badDriverName, &bd, driverapi.Capability{DataScope: scope.Local})
785 785
 }
786 786
 
787
-func (b *badDriver) CreateNetwork(nid string, options map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
787
+func (b *badDriver) CreateNetwork(ctx context.Context, nid string, options map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
788 788
 	if b.failNetworkCreation {
789 789
 		return fmt.Errorf("I will not create any network")
790 790
 	}
... ...
@@ -60,7 +60,7 @@ func newController(t *testing.T) *libnetwork.Controller {
60 60
 }
61 61
 
62 62
 func createTestNetwork(c *libnetwork.Controller, networkType, networkName string, netOption options.Generic, ipamV4Configs, ipamV6Configs []*libnetwork.IpamConf) (*libnetwork.Network, error) {
63
-	return c.NewNetwork(networkType, networkName, "",
63
+	return c.NewNetwork(context.Background(), networkType, networkName, "",
64 64
 		libnetwork.NetworkOptionGeneric(netOption),
65 65
 		libnetwork.NetworkOptionIpam(defaultipam.DriverName, "", ipamV4Configs, ipamV6Configs, nil))
66 66
 }
... ...
@@ -130,7 +130,7 @@ func TestNilRemoteDriver(t *testing.T) {
130 130
 	defer netnsutils.SetupTestOSContext(t)()
131 131
 	controller := newController(t)
132 132
 
133
-	_, err := controller.NewNetwork("framerelay", "dummy", "",
133
+	_, err := controller.NewNetwork(context.Background(), "framerelay", "dummy", "",
134 134
 		libnetwork.NetworkOptionGeneric(getEmptyGenericOption()))
135 135
 
136 136
 	// TODO(thaJeztah): should attempting to use a non-existing plugin/driver return an [errdefs.InvalidParameter] ?
... ...
@@ -239,7 +239,7 @@ func TestNetworkConfig(t *testing.T) {
239 239
 	controller := newController(t)
240 240
 
241 241
 	// Verify config network cannot inherit another config network
242
-	_, err := controller.NewNetwork("bridge", "config_network0", "",
242
+	_, err := controller.NewNetwork(context.Background(), "bridge", "config_network0", "",
243 243
 		libnetwork.NetworkOptionConfigOnly(),
244 244
 		libnetwork.NetworkOptionConfigFrom("anotherConfigNw"),
245 245
 	)
... ...
@@ -265,7 +265,7 @@ func TestNetworkConfig(t *testing.T) {
265 265
 		libnetwork.NetworkOptionIpam("default", "", ipamV4ConfList, ipamV6ConfList, nil),
266 266
 	}
267 267
 
268
-	configNetwork, err := controller.NewNetwork(bridgeNetType, "config_network0", "", netOptions...)
268
+	configNetwork, err := controller.NewNetwork(context.Background(), bridgeNetType, "config_network0", "", netOptions...)
269 269
 	assert.NilError(t, err)
270 270
 
271 271
 	// Verify a config-only network cannot be created with network operator configurations
... ...
@@ -275,7 +275,7 @@ func TestNetworkConfig(t *testing.T) {
275 275
 		libnetwork.NetworkOptionIngress(true),
276 276
 	} {
277 277
 		t.Run(fmt.Sprintf("config-only-%d", i), func(t *testing.T) {
278
-			_, err = controller.NewNetwork(bridgeNetType, "testBR", "",
278
+			_, err = controller.NewNetwork(context.Background(), bridgeNetType, "testBR", "",
279 279
 				libnetwork.NetworkOptionConfigOnly(), opt)
280 280
 
281 281
 			// TODO(thaJeztah): should this be [errdefs.ErrInvalidParameter]?
... ...
@@ -295,7 +295,7 @@ func TestNetworkConfig(t *testing.T) {
295 295
 		libnetwork.NetworkOptionDriverOpts(map[string]string{"com.docker.network.driver.mtu": "1600"}),
296 296
 	} {
297 297
 		t.Run(fmt.Sprintf("config-from-%d", i), func(t *testing.T) {
298
-			_, err = controller.NewNetwork(bridgeNetType, "testBR", "",
298
+			_, err = controller.NewNetwork(context.Background(), bridgeNetType, "testBR", "",
299 299
 				libnetwork.NetworkOptionConfigFrom("config_network0"), opt)
300 300
 
301 301
 			// TODO(thaJeztah): should this be [errdefs.ErrInvalidParameter]?
... ...
@@ -313,7 +313,7 @@ func TestNetworkConfig(t *testing.T) {
313 313
 	}
314 314
 
315 315
 	// Create a valid network
316
-	network, err := controller.NewNetwork(bridgeNetType, "testBR", "",
316
+	network, err := controller.NewNetwork(context.Background(), bridgeNetType, "testBR", "",
317 317
 		libnetwork.NetworkOptionConfigFrom("config_network0"))
318 318
 	assert.NilError(t, err)
319 319
 
... ...
@@ -892,7 +892,7 @@ func TestInvalidRemoteDriver(t *testing.T) {
892 892
 	assert.NilError(t, err)
893 893
 	defer ctrlr.Stop()
894 894
 
895
-	_, err = ctrlr.NewNetwork("invalid-network-driver", "dummy", "",
895
+	_, err = ctrlr.NewNetwork(context.Background(), "invalid-network-driver", "dummy", "",
896 896
 		libnetwork.NetworkOptionGeneric(getEmptyGenericOption()))
897 897
 	assert.Check(t, is.ErrorIs(err, plugins.ErrNotImplements))
898 898
 }
... ...
@@ -929,7 +929,7 @@ func TestValidRemoteDriver(t *testing.T) {
929 929
 	assert.NilError(t, err)
930 930
 
931 931
 	controller := newController(t)
932
-	n, err := controller.NewNetwork("valid-network-driver", "dummy", "",
932
+	n, err := controller.NewNetwork(context.Background(), "valid-network-driver", "dummy", "",
933 933
 		libnetwork.NetworkOptionGeneric(getEmptyGenericOption()))
934 934
 	if err != nil {
935 935
 		// Only fail if we could not find the plugin driver
... ...
@@ -1077,7 +1077,7 @@ func TestEndpointJoin(t *testing.T) {
1077 1077
 		},
1078 1078
 	}
1079 1079
 	ipamV6ConfList := []*libnetwork.IpamConf{{PreferredPool: "fe90::/64", Gateway: "fe90::22"}}
1080
-	n1, err := controller.NewNetwork(bridgeNetType, "testnetwork1", "",
1080
+	n1, err := controller.NewNetwork(context.Background(), bridgeNetType, "testnetwork1", "",
1081 1081
 		libnetwork.NetworkOptionGeneric(netOption),
1082 1082
 		libnetwork.NetworkOptionEnableIPv4(true),
1083 1083
 		libnetwork.NetworkOptionEnableIPv6(true),
... ...
@@ -1585,7 +1585,7 @@ func TestBridgeRequiresIPAM(t *testing.T) {
1585 1585
 	defer netnsutils.SetupTestOSContext(t)()
1586 1586
 	controller := newController(t)
1587 1587
 
1588
-	_, err := controller.NewNetwork(bridgeNetType, "testnetwork", "",
1588
+	_, err := controller.NewNetwork(context.Background(), bridgeNetType, "testnetwork", "",
1589 1589
 		libnetwork.NetworkOptionIpam(null.DriverName, "", nil, nil, nil),
1590 1590
 	)
1591 1591
 	assert.Check(t, is.ErrorContains(err, "IPv4 or IPv6 must be enabled"))
... ...
@@ -1605,13 +1605,13 @@ func TestNullIpam(t *testing.T) {
1605 1605
 
1606 1606
 	for _, tc := range tests {
1607 1607
 		t.Run(tc.networkType, func(t *testing.T) {
1608
-			_, err := controller.NewNetwork(tc.networkType, "tnet1-"+tc.networkType, "",
1608
+			_, err := controller.NewNetwork(context.Background(), tc.networkType, "tnet1-"+tc.networkType, "",
1609 1609
 				libnetwork.NetworkOptionEnableIPv4(true),
1610 1610
 				libnetwork.NetworkOptionIpam(null.DriverName, "", nil, nil, nil),
1611 1611
 			)
1612 1612
 			assert.Check(t, is.ErrorContains(err, "ipv4 pool is empty"))
1613 1613
 
1614
-			_, err = controller.NewNetwork(tc.networkType, "tnet2-"+tc.networkType, "",
1614
+			_, err = controller.NewNetwork(context.Background(), tc.networkType, "tnet2-"+tc.networkType, "",
1615 1615
 				libnetwork.NetworkOptionEnableIPv6(true),
1616 1616
 				libnetwork.NetworkOptionIpam(null.DriverName, "", nil, nil, nil),
1617 1617
 			)
... ...
@@ -23,7 +23,7 @@ func TestDNSIPQuery(t *testing.T) {
23 23
 	}
24 24
 	defer c.Stop()
25 25
 
26
-	n, err := c.NewNetwork("bridge", "dtnet1", "", NetworkOptionEnableIPv4(true))
26
+	n, err := c.NewNetwork(context.Background(), "bridge", "dtnet1", "", NetworkOptionEnableIPv4(true))
27 27
 	if err != nil {
28 28
 		t.Fatal(err)
29 29
 	}
... ...
@@ -121,7 +121,7 @@ func TestDNSProxyServFail(t *testing.T) {
121 121
 	}
122 122
 	defer c.Stop()
123 123
 
124
-	n, err := c.NewNetwork("bridge", "dtnet2", "", NetworkOptionEnableIPv4(true))
124
+	n, err := c.NewNetwork(context.Background(), "bridge", "dtnet2", "", NetworkOptionEnableIPv4(true))
125 125
 	if err != nil {
126 126
 		t.Fatal(err)
127 127
 	}
... ...
@@ -48,7 +48,7 @@ func getTestEnv(t *testing.T, opts ...[]NetworkOption) (*Controller, []*Network)
48 48
 			}),
49 49
 		}
50 50
 		newOptions = append(newOptions, opt...)
51
-		n, err := c.NewNetwork(netType, name, "", newOptions...)
51
+		n, err := c.NewNetwork(context.Background(), netType, name, "", newOptions...)
52 52
 		if err != nil {
53 53
 			t.Fatal(err)
54 54
 		}
... ...
@@ -3,6 +3,7 @@
3 3
 package libnetwork
4 4
 
5 5
 import (
6
+	"context"
6 7
 	"net"
7 8
 	"testing"
8 9
 
... ...
@@ -24,11 +25,11 @@ func TestCleanupServiceDiscovery(t *testing.T) {
24 24
 			t.Error(err)
25 25
 		}
26 26
 	}
27
-	n1, err := c.NewNetwork("bridge", "net1", "", NetworkOptionEnableIPv4(true))
27
+	n1, err := c.NewNetwork(context.Background(), "bridge", "net1", "", NetworkOptionEnableIPv4(true))
28 28
 	assert.NilError(t, err)
29 29
 	defer cleanup(n1)
30 30
 
31
-	n2, err := c.NewNetwork("bridge", "net2", "", NetworkOptionEnableIPv4(true))
31
+	n2, err := c.NewNetwork(context.Background(), "bridge", "net2", "", NetworkOptionEnableIPv4(true))
32 32
 	assert.NilError(t, err)
33 33
 	defer cleanup(n2)
34 34
 
... ...
@@ -22,7 +22,7 @@ func TestNoPersist(t *testing.T) {
22 22
 		t.Fatalf("Error creating new controller: %v", err)
23 23
 	}
24 24
 	defer testController.Stop()
25
-	nw, err := testController.NewNetwork("host", "host", "", NetworkOptionPersist(false))
25
+	nw, err := testController.NewNetwork(context.Background(), "host", "host", "", NetworkOptionPersist(false))
26 26
 	if err != nil {
27 27
 		t.Fatalf(`Error creating default "host" network: %v`, err)
28 28
 	}
... ...
@@ -23,7 +23,7 @@ func testLocalBackend(t *testing.T, path, bucket string) {
23 23
 		t.Fatalf("Error new controller: %v", err)
24 24
 	}
25 25
 	defer testController.Stop()
26
-	nw, err := testController.NewNetwork("host", "host", "")
26
+	nw, err := testController.NewNetwork(context.Background(), "host", "host", "")
27 27
 	if err != nil {
28 28
 		t.Fatalf(`Error creating default "host" network: %v`, err)
29 29
 	}