Browse code

libnetwork: return concrete-typed *Controller

libnetwork.NetworkController is an interface with a single
implementation.

https://github.com/golang/go/wiki/CodeReviewComments#interfaces

Signed-off-by: Cory Snider <csnider@mirantis.com>

Cory Snider authored on 2023/01/12 07:43:32
Showing 33 changed files
... ...
@@ -69,7 +69,7 @@ type Opt struct {
69 69
 	SessionManager      *session.Manager
70 70
 	Root                string
71 71
 	Dist                images.DistributionServices
72
-	NetworkController   libnetwork.NetworkController
72
+	NetworkController   *libnetwork.Controller
73 73
 	DefaultCgroupParent string
74 74
 	RegistryHosts       docker.RegistryHosts
75 75
 	BuilderConfig       config.BuilderConfig
... ...
@@ -25,10 +25,10 @@ import (
25 25
 
26 26
 const networkName = "bridge"
27 27
 
28
-func newExecutor(root, cgroupParent string, net libnetwork.NetworkController, dnsConfig *oci.DNSConfig, rootless bool, idmap idtools.IdentityMapping, apparmorProfile string) (executor.Executor, error) {
28
+func newExecutor(root, cgroupParent string, net *libnetwork.Controller, dnsConfig *oci.DNSConfig, rootless bool, idmap idtools.IdentityMapping, apparmorProfile string) (executor.Executor, error) {
29 29
 	netRoot := filepath.Join(root, "net")
30 30
 	networkProviders := map[pb.NetMode]network.Provider{
31
-		pb.NetMode_UNSET: &bridgeProvider{NetworkController: net, Root: netRoot},
31
+		pb.NetMode_UNSET: &bridgeProvider{Controller: net, Root: netRoot},
32 32
 		pb.NetMode_HOST:  network.NewHostProvider(),
33 33
 		pb.NetMode_NONE:  network.NewNoneProvider(),
34 34
 	}
... ...
@@ -64,7 +64,7 @@ func newExecutor(root, cgroupParent string, net libnetwork.NetworkController, dn
64 64
 }
65 65
 
66 66
 type bridgeProvider struct {
67
-	libnetwork.NetworkController
67
+	*libnetwork.Controller
68 68
 	Root string
69 69
 }
70 70
 
... ...
@@ -76,7 +76,7 @@ func (p *bridgeProvider) New() (network.Namespace, error) {
76 76
 
77 77
 	iface := &lnInterface{ready: make(chan struct{}), provider: p}
78 78
 	iface.Once.Do(func() {
79
-		go iface.init(p.NetworkController, n)
79
+		go iface.init(p.Controller, n)
80 80
 	})
81 81
 
82 82
 	return iface, nil
... ...
@@ -91,7 +91,7 @@ type lnInterface struct {
91 91
 	provider *bridgeProvider
92 92
 }
93 93
 
94
-func (iface *lnInterface) init(c libnetwork.NetworkController, n libnetwork.Network) {
94
+func (iface *lnInterface) init(c *libnetwork.Controller, n libnetwork.Network) {
95 95
 	defer close(iface.ready)
96 96
 	id := identity.NewID()
97 97
 
... ...
@@ -123,7 +123,7 @@ func (iface *lnInterface) Set(s *specs.Spec) error {
123 123
 		logrus.WithError(iface.err).Error("failed to set networking spec")
124 124
 		return iface.err
125 125
 	}
126
-	shortNetCtlrID := stringid.TruncateID(iface.provider.NetworkController.ID())
126
+	shortNetCtlrID := stringid.TruncateID(iface.provider.Controller.ID())
127 127
 	// attach netns to bridge within the container namespace, using reexec in a prestart hook
128 128
 	s.Hooks = &specs.Hooks{
129 129
 		Prestart: []specs.Hook{{
... ...
@@ -11,7 +11,7 @@ import (
11 11
 	"github.com/moby/buildkit/executor/oci"
12 12
 )
13 13
 
14
-func newExecutor(_, _ string, _ libnetwork.NetworkController, _ *oci.DNSConfig, _ bool, _ idtools.IdentityMapping, _ string) (executor.Executor, error) {
14
+func newExecutor(_, _ string, _ *libnetwork.Controller, _ *oci.DNSConfig, _ bool, _ idtools.IdentityMapping, _ string) (executor.Executor, error) {
15 15
 	return &winExecutor{}, nil
16 16
 }
17 17
 
... ...
@@ -83,7 +83,7 @@ type Daemon struct {
83 83
 	defaultLogConfig      containertypes.LogConfig
84 84
 	registryService       registry.Service
85 85
 	EventsService         *events.Events
86
-	netController         libnetwork.NetworkController
86
+	netController         *libnetwork.Controller
87 87
 	volumes               *volumesservice.VolumesService
88 88
 	root                  string
89 89
 	sysInfoOnce           sync.Once
... ...
@@ -864,7 +864,7 @@ func (daemon *Daemon) initNetworkController(activeSandboxes map[string]interface
864 864
 	return nil
865 865
 }
866 866
 
867
-func configureNetworking(controller libnetwork.NetworkController, conf *config.Config) error {
867
+func configureNetworking(controller *libnetwork.Controller, conf *config.Config) error {
868 868
 	// Initialize default network on "null"
869 869
 	if n, _ := controller.NetworkByName("none"); n == nil {
870 870
 		if _, err := controller.NewNetwork("null", "none", "", libnetwork.NetworkOptionPersist(true)); err != nil {
... ...
@@ -902,7 +902,7 @@ func configureNetworking(controller libnetwork.NetworkController, conf *config.C
902 902
 }
903 903
 
904 904
 // setHostGatewayIP sets cfg.HostGatewayIP to the default bridge's IP if it is empty.
905
-func setHostGatewayIP(controller libnetwork.NetworkController, config *config.Config) {
905
+func setHostGatewayIP(controller *libnetwork.Controller, config *config.Config) {
906 906
 	if config.HostGatewayIP != nil {
907 907
 		return
908 908
 	}
... ...
@@ -930,7 +930,7 @@ func driverOptions(config *config.Config) nwconfig.Option {
930 930
 	})
931 931
 }
932 932
 
933
-func initBridgeDriver(controller libnetwork.NetworkController, config *config.Config) error {
933
+func initBridgeDriver(controller *libnetwork.Controller, config *config.Config) error {
934 934
 	bridgeName := bridge.DefaultBridgeName
935 935
 	if config.BridgeConfig.Iface != "" {
936 936
 		bridgeName = config.BridgeConfig.Iface
... ...
@@ -409,7 +409,7 @@ func (daemon *Daemon) initNetworkController(activeSandboxes map[string]interface
409 409
 	return nil
410 410
 }
411 411
 
412
-func initBridgeDriver(controller libnetwork.NetworkController, config *config.Config) error {
412
+func initBridgeDriver(controller *libnetwork.Controller, config *config.Config) error {
413 413
 	if _, err := controller.NetworkByName(runconfig.DefaultDaemonNetworkMode().NetworkName()); err == nil {
414 414
 		return nil
415 415
 	}
... ...
@@ -50,7 +50,7 @@ func (daemon *Daemon) NetworkControllerEnabled() bool {
50 50
 }
51 51
 
52 52
 // NetworkController returns the network controller created by the daemon.
53
-func (daemon *Daemon) NetworkController() libnetwork.NetworkController {
53
+func (daemon *Daemon) NetworkController() *libnetwork.Controller {
54 54
 	return daemon.netController
55 55
 }
56 56
 
... ...
@@ -97,7 +97,7 @@ func resolveAddr(addrOrInterface string) (string, error) {
97 97
 	return addr.String(), nil
98 98
 }
99 99
 
100
-func (c *controller) handleKeyChange(keys []*types.EncryptionKey) error {
100
+func (c *Controller) handleKeyChange(keys []*types.EncryptionKey) error {
101 101
 	drvEnc := discoverapi.DriverEncryptionUpdate{}
102 102
 
103 103
 	a := c.getAgent()
... ...
@@ -201,7 +201,7 @@ func (c *controller) handleKeyChange(keys []*types.EncryptionKey) error {
201 201
 	return nil
202 202
 }
203 203
 
204
-func (c *controller) agentSetup(clusterProvider cluster.Provider) error {
204
+func (c *Controller) agentSetup(clusterProvider cluster.Provider) error {
205 205
 	agent := c.getAgent()
206 206
 
207 207
 	// If the agent is already present there is no need to try to initialize it again
... ...
@@ -248,7 +248,7 @@ func (c *controller) agentSetup(clusterProvider cluster.Provider) error {
248 248
 
249 249
 // For a given subsystem getKeys sorts the keys by lamport time and returns
250 250
 // slice of keys and lamport time which can used as a unique tag for the keys
251
-func (c *controller) getKeys(subsys string) ([][]byte, []uint64) {
251
+func (c *Controller) getKeys(subsys string) ([][]byte, []uint64) {
252 252
 	c.mu.Lock()
253 253
 	defer c.mu.Unlock()
254 254
 
... ...
@@ -270,7 +270,7 @@ func (c *controller) getKeys(subsys string) ([][]byte, []uint64) {
270 270
 
271 271
 // getPrimaryKeyTag returns the primary key for a given subsystem from the
272 272
 // list of sorted key and the associated tag
273
-func (c *controller) getPrimaryKeyTag(subsys string) ([]byte, uint64, error) {
273
+func (c *Controller) getPrimaryKeyTag(subsys string) ([]byte, uint64, error) {
274 274
 	c.mu.Lock()
275 275
 	defer c.mu.Unlock()
276 276
 	sort.Sort(ByTime(c.keys))
... ...
@@ -283,7 +283,7 @@ func (c *controller) getPrimaryKeyTag(subsys string) ([]byte, uint64, error) {
283 283
 	return keys[1].Key, keys[1].LamportTime, nil
284 284
 }
285 285
 
286
-func (c *controller) agentInit(listenAddr, bindAddrOrInterface, advertiseAddr, dataPathAddr string) error {
286
+func (c *Controller) agentInit(listenAddr, bindAddrOrInterface, advertiseAddr, dataPathAddr string) error {
287 287
 	bindAddr, err := resolveAddr(bindAddrOrInterface)
288 288
 	if err != nil {
289 289
 		return err
... ...
@@ -348,7 +348,7 @@ func (c *controller) agentInit(listenAddr, bindAddrOrInterface, advertiseAddr, d
348 348
 	return nil
349 349
 }
350 350
 
351
-func (c *controller) agentJoin(remoteAddrList []string) error {
351
+func (c *Controller) agentJoin(remoteAddrList []string) error {
352 352
 	agent := c.getAgent()
353 353
 	if agent == nil {
354 354
 		return nil
... ...
@@ -356,7 +356,7 @@ func (c *controller) agentJoin(remoteAddrList []string) error {
356 356
 	return agent.networkDB.Join(remoteAddrList)
357 357
 }
358 358
 
359
-func (c *controller) agentDriverNotify(d driverapi.Driver) {
359
+func (c *Controller) agentDriverNotify(d driverapi.Driver) {
360 360
 	agent := c.getAgent()
361 361
 	if agent == nil {
362 362
 		return
... ...
@@ -380,7 +380,7 @@ func (c *controller) agentDriverNotify(d driverapi.Driver) {
380 380
 	}
381 381
 }
382 382
 
383
-func (c *controller) agentClose() {
383
+func (c *Controller) agentClose() {
384 384
 	// Acquire current agent instance and reset its pointer
385 385
 	// then run closing functions
386 386
 	c.mu.Lock()
... ...
@@ -827,7 +827,7 @@ func (n *network) cancelDriverWatches() {
827 827
 	}
828 828
 }
829 829
 
830
-func (c *controller) handleTableEvents(ch *events.Channel, fn func(events.Event)) {
830
+func (c *Controller) handleTableEvents(ch *events.Channel, fn func(events.Event)) {
831 831
 	for {
832 832
 		select {
833 833
 		case ev := <-ch.C:
... ...
@@ -873,7 +873,7 @@ func (n *network) handleDriverTableEvent(ev events.Event) {
873 873
 	d.EventNotify(etype, n.ID(), tname, key, value)
874 874
 }
875 875
 
876
-func (c *controller) handleNodeTableEvent(ev events.Event) {
876
+func (c *Controller) handleNodeTableEvent(ev events.Event) {
877 877
 	var (
878 878
 		value    []byte
879 879
 		isAdd    bool
... ...
@@ -897,7 +897,7 @@ func (c *controller) handleNodeTableEvent(ev events.Event) {
897 897
 	c.processNodeDiscovery([]net.IP{nodeAddr.Addr}, isAdd)
898 898
 }
899 899
 
900
-func (c *controller) handleEpTableEvent(ev events.Event) {
900
+func (c *Controller) handleEpTableEvent(ev events.Event) {
901 901
 	var (
902 902
 		nid   string
903 903
 		eid   string
... ...
@@ -72,77 +72,6 @@ import (
72 72
 	"github.com/sirupsen/logrus"
73 73
 )
74 74
 
75
-// NetworkController provides the interface for controller instance which manages
76
-// networks.
77
-type NetworkController interface {
78
-	// ID provides a unique identity for the controller
79
-	ID() string
80
-
81
-	// BuiltinDrivers returns list of builtin drivers
82
-	BuiltinDrivers() []string
83
-
84
-	// BuiltinIPAMDrivers returns list of builtin ipam drivers
85
-	BuiltinIPAMDrivers() []string
86
-
87
-	// Config method returns the bootup configuration for the controller
88
-	Config() config.Config
89
-
90
-	// Create a new network. The options parameter carries network specific options.
91
-	NewNetwork(networkType, name string, id string, options ...NetworkOption) (Network, error)
92
-
93
-	// Networks returns the list of Network(s) managed by this controller.
94
-	Networks() []Network
95
-
96
-	// WalkNetworks uses the provided function to walk the Network(s) managed by this controller.
97
-	WalkNetworks(walker NetworkWalker)
98
-
99
-	// NetworkByName returns the Network which has the passed name. If not found, the error ErrNoSuchNetwork is returned.
100
-	NetworkByName(name string) (Network, error)
101
-
102
-	// NetworkByID returns the Network which has the passed id. If not found, the error ErrNoSuchNetwork is returned.
103
-	NetworkByID(id string) (Network, error)
104
-
105
-	// NewSandbox creates a new network sandbox for the passed container id
106
-	NewSandbox(containerID string, options ...SandboxOption) (Sandbox, error)
107
-
108
-	// Sandboxes returns the list of Sandbox(s) managed by this controller.
109
-	Sandboxes() []Sandbox
110
-
111
-	// WalkSandboxes uses the provided function to walk the Sandbox(s) managed by this controller.
112
-	WalkSandboxes(walker SandboxWalker)
113
-
114
-	// SandboxByID returns the Sandbox which has the passed id. If not found, a types.NotFoundError is returned.
115
-	SandboxByID(id string) (Sandbox, error)
116
-
117
-	// SandboxDestroy destroys a sandbox given a container ID
118
-	SandboxDestroy(id string) error
119
-
120
-	// Stop network controller
121
-	Stop()
122
-
123
-	// ReloadConfiguration updates the controller configuration
124
-	ReloadConfiguration(cfgOptions ...config.Option) error
125
-
126
-	// SetClusterProvider sets cluster provider
127
-	SetClusterProvider(provider cluster.Provider)
128
-
129
-	// Wait for agent initialization complete in libnetwork controller
130
-	AgentInitWait()
131
-
132
-	// Wait for agent to stop if running
133
-	AgentStopWait()
134
-
135
-	// SetKeys configures the encryption key for gossip and overlay data path
136
-	SetKeys(keys []*types.EncryptionKey) error
137
-
138
-	// StartDiagnostic start the network diagnostic mode
139
-	StartDiagnostic(port int)
140
-	// StopDiagnostic start the network diagnostic mode
141
-	StopDiagnostic()
142
-	// IsDiagnosticEnabled returns true if the diagnostic is enabled
143
-	IsDiagnosticEnabled() bool
144
-}
145
-
146 75
 // NetworkWalker is a client provided function which will be used to walk the Networks.
147 76
 // When the function returns true, the walk will stop.
148 77
 type NetworkWalker func(nw Network) bool
... ...
@@ -153,7 +82,8 @@ type SandboxWalker func(sb Sandbox) bool
153 153
 
154 154
 type sandboxTable map[string]*sandbox
155 155
 
156
-type controller struct {
156
+// Controller manages networks.
157
+type Controller struct {
157 158
 	id               string
158 159
 	drvRegistry      *drvregistry.DrvRegistry
159 160
 	sandboxes        sandboxTable
... ...
@@ -183,8 +113,8 @@ type initializer struct {
183 183
 }
184 184
 
185 185
 // New creates a new instance of network controller.
186
-func New(cfgOptions ...config.Option) (NetworkController, error) {
187
-	c := &controller{
186
+func New(cfgOptions ...config.Option) (*Controller, error) {
187
+	c := &Controller{
188 188
 		id:               stringid.GenerateRandomID(),
189 189
 		cfg:              config.New(cfgOptions...),
190 190
 		sandboxes:        sandboxTable{},
... ...
@@ -245,7 +175,8 @@ func New(cfgOptions ...config.Option) (NetworkController, error) {
245 245
 	return c, nil
246 246
 }
247 247
 
248
-func (c *controller) SetClusterProvider(provider cluster.Provider) {
248
+// SetClusterProvider sets the cluster provider.
249
+func (c *Controller) SetClusterProvider(provider cluster.Provider) {
249 250
 	var sameProvider bool
250 251
 	c.mu.Lock()
251 252
 	// Avoids to spawn multiple goroutine for the same cluster provider
... ...
@@ -266,9 +197,10 @@ func (c *controller) SetClusterProvider(provider cluster.Provider) {
266 266
 	go c.clusterAgentInit()
267 267
 }
268 268
 
269
-// libnetwork side of agent depends on the keys. On the first receipt of
270
-// keys setup the agent. For subsequent key set handle the key change
271
-func (c *controller) SetKeys(keys []*types.EncryptionKey) error {
269
+// SetKeys configures the encryption key for gossip and overlay data path.
270
+func (c *Controller) SetKeys(keys []*types.EncryptionKey) error {
271
+	// libnetwork side of agent depends on the keys. On the first receipt of
272
+	// keys setup the agent. For subsequent key set handle the key change
272 273
 	subsysKeys := make(map[string]int)
273 274
 	for _, key := range keys {
274 275
 		if key.Subsystem != subsysGossip &&
... ...
@@ -292,13 +224,13 @@ func (c *controller) SetKeys(keys []*types.EncryptionKey) error {
292 292
 	return c.handleKeyChange(keys)
293 293
 }
294 294
 
295
-func (c *controller) getAgent() *agent {
295
+func (c *Controller) getAgent() *agent {
296 296
 	c.mu.Lock()
297 297
 	defer c.mu.Unlock()
298 298
 	return c.agent
299 299
 }
300 300
 
301
-func (c *controller) clusterAgentInit() {
301
+func (c *Controller) clusterAgentInit() {
302 302
 	clusterProvider := c.cfg.ClusterProvider
303 303
 	var keysAvailable bool
304 304
 	for {
... ...
@@ -347,7 +279,7 @@ func (c *controller) clusterAgentInit() {
347 347
 }
348 348
 
349 349
 // AgentInitWait waits for agent initialization to be completed in the controller.
350
-func (c *controller) AgentInitWait() {
350
+func (c *Controller) AgentInitWait() {
351 351
 	c.mu.Lock()
352 352
 	agentInitDone := c.agentInitDone
353 353
 	c.mu.Unlock()
... ...
@@ -357,8 +289,8 @@ func (c *controller) AgentInitWait() {
357 357
 	}
358 358
 }
359 359
 
360
-// AgentStopWait waits for the Agent stop to be completed in the controller
361
-func (c *controller) AgentStopWait() {
360
+// AgentStopWait waits for the Agent stop to be completed in the controller.
361
+func (c *Controller) AgentStopWait() {
362 362
 	c.mu.Lock()
363 363
 	agentStopDone := c.agentStopDone
364 364
 	c.mu.Unlock()
... ...
@@ -368,7 +300,7 @@ func (c *controller) AgentStopWait() {
368 368
 }
369 369
 
370 370
 // agentOperationStart marks the start of an Agent Init or Agent Stop
371
-func (c *controller) agentOperationStart() {
371
+func (c *Controller) agentOperationStart() {
372 372
 	c.mu.Lock()
373 373
 	if c.agentInitDone == nil {
374 374
 		c.agentInitDone = make(chan struct{})
... ...
@@ -380,7 +312,7 @@ func (c *controller) agentOperationStart() {
380 380
 }
381 381
 
382 382
 // agentInitComplete notifies the successful completion of the Agent initialization
383
-func (c *controller) agentInitComplete() {
383
+func (c *Controller) agentInitComplete() {
384 384
 	c.mu.Lock()
385 385
 	if c.agentInitDone != nil {
386 386
 		close(c.agentInitDone)
... ...
@@ -390,7 +322,7 @@ func (c *controller) agentInitComplete() {
390 390
 }
391 391
 
392 392
 // agentStopComplete notifies the successful completion of the Agent stop
393
-func (c *controller) agentStopComplete() {
393
+func (c *Controller) agentStopComplete() {
394 394
 	c.mu.Lock()
395 395
 	if c.agentStopDone != nil {
396 396
 		close(c.agentStopDone)
... ...
@@ -399,7 +331,7 @@ func (c *controller) agentStopComplete() {
399 399
 	c.mu.Unlock()
400 400
 }
401 401
 
402
-func (c *controller) makeDriverConfig(ntype string) map[string]interface{} {
402
+func (c *Controller) makeDriverConfig(ntype string) map[string]interface{} {
403 403
 	if c.cfg == nil {
404 404
 		return nil
405 405
 	}
... ...
@@ -438,7 +370,8 @@ func (c *controller) makeDriverConfig(ntype string) map[string]interface{} {
438 438
 
439 439
 var procReloadConfig = make(chan (bool), 1)
440 440
 
441
-func (c *controller) ReloadConfiguration(cfgOptions ...config.Option) error {
441
+// ReloadConfiguration updates the controller configuration.
442
+func (c *Controller) ReloadConfiguration(cfgOptions ...config.Option) error {
442 443
 	procReloadConfig <- true
443 444
 	defer func() { <-procReloadConfig }()
444 445
 
... ...
@@ -508,11 +441,13 @@ func (c *controller) ReloadConfiguration(cfgOptions ...config.Option) error {
508 508
 	return nil
509 509
 }
510 510
 
511
-func (c *controller) ID() string {
511
+// ID returns the controller's unique identity.
512
+func (c *Controller) ID() string {
512 513
 	return c.id
513 514
 }
514 515
 
515
-func (c *controller) BuiltinDrivers() []string {
516
+// BuiltinDrivers returns the list of builtin network drivers.
517
+func (c *Controller) BuiltinDrivers() []string {
516 518
 	drivers := []string{}
517 519
 	c.drvRegistry.WalkDrivers(func(name string, driver driverapi.Driver, capability driverapi.Capability) bool {
518 520
 		if driver.IsBuiltIn() {
... ...
@@ -523,7 +458,8 @@ func (c *controller) BuiltinDrivers() []string {
523 523
 	return drivers
524 524
 }
525 525
 
526
-func (c *controller) BuiltinIPAMDrivers() []string {
526
+// BuiltinIPAMDrivers returns the list of builtin ipam drivers.
527
+func (c *Controller) BuiltinIPAMDrivers() []string {
527 528
 	drivers := []string{}
528 529
 	c.drvRegistry.WalkIPAMs(func(name string, driver ipamapi.Ipam, cap *ipamapi.Capability) bool {
529 530
 		if driver.IsBuiltIn() {
... ...
@@ -534,14 +470,14 @@ func (c *controller) BuiltinIPAMDrivers() []string {
534 534
 	return drivers
535 535
 }
536 536
 
537
-func (c *controller) processNodeDiscovery(nodes []net.IP, add bool) {
537
+func (c *Controller) processNodeDiscovery(nodes []net.IP, add bool) {
538 538
 	c.drvRegistry.WalkDrivers(func(name string, driver driverapi.Driver, capability driverapi.Capability) bool {
539 539
 		c.pushNodeDiscovery(driver, capability, nodes, add)
540 540
 		return false
541 541
 	})
542 542
 }
543 543
 
544
-func (c *controller) pushNodeDiscovery(d driverapi.Driver, cap driverapi.Capability, nodes []net.IP, add bool) {
544
+func (c *Controller) pushNodeDiscovery(d driverapi.Driver, cap driverapi.Capability, nodes []net.IP, add bool) {
545 545
 	var self net.IP
546 546
 	// try swarm-mode config
547 547
 	if agent := c.getAgent(); agent != nil {
... ...
@@ -566,7 +502,8 @@ func (c *controller) pushNodeDiscovery(d driverapi.Driver, cap driverapi.Capabil
566 566
 	}
567 567
 }
568 568
 
569
-func (c *controller) Config() config.Config {
569
+// Config returns the bootup configuration for the controller.
570
+func (c *Controller) Config() config.Config {
570 571
 	c.mu.Lock()
571 572
 	defer c.mu.Unlock()
572 573
 	if c.cfg == nil {
... ...
@@ -575,7 +512,7 @@ func (c *controller) Config() config.Config {
575 575
 	return *c.cfg
576 576
 }
577 577
 
578
-func (c *controller) isManager() bool {
578
+func (c *Controller) isManager() bool {
579 579
 	c.mu.Lock()
580 580
 	defer c.mu.Unlock()
581 581
 	if c.cfg == nil || c.cfg.ClusterProvider == nil {
... ...
@@ -584,7 +521,7 @@ func (c *controller) isManager() bool {
584 584
 	return c.cfg.ClusterProvider.IsManager()
585 585
 }
586 586
 
587
-func (c *controller) isAgent() bool {
587
+func (c *Controller) isAgent() bool {
588 588
 	c.mu.Lock()
589 589
 	defer c.mu.Unlock()
590 590
 	if c.cfg == nil || c.cfg.ClusterProvider == nil {
... ...
@@ -593,15 +530,15 @@ func (c *controller) isAgent() bool {
593 593
 	return c.cfg.ClusterProvider.IsAgent()
594 594
 }
595 595
 
596
-func (c *controller) isDistributedControl() bool {
596
+func (c *Controller) isDistributedControl() bool {
597 597
 	return !c.isManager() && !c.isAgent()
598 598
 }
599 599
 
600
-func (c *controller) GetPluginGetter() plugingetter.PluginGetter {
600
+func (c *Controller) GetPluginGetter() plugingetter.PluginGetter {
601 601
 	return c.drvRegistry.GetPluginGetter()
602 602
 }
603 603
 
604
-func (c *controller) RegisterDriver(networkType string, driver driverapi.Driver, capability driverapi.Capability) error {
604
+func (c *Controller) RegisterDriver(networkType string, driver driverapi.Driver, capability driverapi.Capability) error {
605 605
 	c.agentDriverNotify(driver)
606 606
 	return nil
607 607
 }
... ...
@@ -611,7 +548,7 @@ const overlayDSROptionString = "dsr"
611 611
 
612 612
 // NewNetwork creates a new network of the specified network type. The options
613 613
 // are network specific and modeled in a generic way.
614
-func (c *controller) NewNetwork(networkType, name string, id string, options ...NetworkOption) (Network, error) {
614
+func (c *Controller) NewNetwork(networkType, name string, id string, options ...NetworkOption) (Network, error) {
615 615
 	var (
616 616
 		caps           *driverapi.Capability
617 617
 		err            error
... ...
@@ -832,7 +769,7 @@ var joinCluster NetworkWalker = func(nw Network) bool {
832 832
 	return false
833 833
 }
834 834
 
835
-func (c *controller) reservePools() {
835
+func (c *Controller) reservePools() {
836 836
 	networks, err := c.getNetworksForScope(datastore.LocalScope)
837 837
 	if err != nil {
838 838
 		logrus.Warnf("Could not retrieve networks from local store during ipam allocation for existing networks: %v", err)
... ...
@@ -905,7 +842,7 @@ func doReplayPoolReserve(n *network) bool {
905 905
 	return caps.RequiresRequestReplay
906 906
 }
907 907
 
908
-func (c *controller) addNetwork(n *network) error {
908
+func (c *Controller) addNetwork(n *network) error {
909 909
 	d, err := n.driver(true)
910 910
 	if err != nil {
911 911
 		return err
... ...
@@ -921,7 +858,8 @@ func (c *controller) addNetwork(n *network) error {
921 921
 	return nil
922 922
 }
923 923
 
924
-func (c *controller) Networks() []Network {
924
+// Networks returns the list of Network(s) managed by this controller.
925
+func (c *Controller) Networks() []Network {
925 926
 	var list []Network
926 927
 
927 928
 	for _, n := range c.getNetworksFromStore() {
... ...
@@ -934,7 +872,8 @@ func (c *controller) Networks() []Network {
934 934
 	return list
935 935
 }
936 936
 
937
-func (c *controller) WalkNetworks(walker NetworkWalker) {
937
+// WalkNetworks uses the provided function to walk the Network(s) managed by this controller.
938
+func (c *Controller) WalkNetworks(walker NetworkWalker) {
938 939
 	for _, n := range c.Networks() {
939 940
 		if walker(n) {
940 941
 			return
... ...
@@ -942,7 +881,9 @@ func (c *controller) WalkNetworks(walker NetworkWalker) {
942 942
 	}
943 943
 }
944 944
 
945
-func (c *controller) NetworkByName(name string) (Network, error) {
945
+// NetworkByName returns the Network which has the passed name.
946
+// If not found, the error [ErrNoSuchNetwork] is returned.
947
+func (c *Controller) NetworkByName(name string) (Network, error) {
946 948
 	if name == "" {
947 949
 		return nil, ErrInvalidName(name)
948 950
 	}
... ...
@@ -965,7 +906,9 @@ func (c *controller) NetworkByName(name string) (Network, error) {
965 965
 	return n, nil
966 966
 }
967 967
 
968
-func (c *controller) NetworkByID(id string) (Network, error) {
968
+// NetworkByID returns the Network which has the passed id.
969
+// If not found, the error [ErrNoSuchNetwork] is returned.
970
+func (c *Controller) NetworkByID(id string) (Network, error) {
969 971
 	if id == "" {
970 972
 		return nil, ErrInvalidID(id)
971 973
 	}
... ...
@@ -978,8 +921,8 @@ func (c *controller) NetworkByID(id string) (Network, error) {
978 978
 	return n, nil
979 979
 }
980 980
 
981
-// NewSandbox creates a new sandbox for the passed container id
982
-func (c *controller) NewSandbox(containerID string, options ...SandboxOption) (Sandbox, error) {
981
+// NewSandbox creates a new sandbox for containerID.
982
+func (c *Controller) NewSandbox(containerID string, options ...SandboxOption) (Sandbox, error) {
983 983
 	if containerID == "" {
984 984
 		return nil, types.BadRequestErrorf("invalid container ID")
985 985
 	}
... ...
@@ -1109,7 +1052,8 @@ func (c *controller) NewSandbox(containerID string, options ...SandboxOption) (S
1109 1109
 	return sb, nil
1110 1110
 }
1111 1111
 
1112
-func (c *controller) Sandboxes() []Sandbox {
1112
+// Sandboxes returns the list of Sandbox(s) managed by this controller.
1113
+func (c *Controller) Sandboxes() []Sandbox {
1113 1114
 	c.mu.Lock()
1114 1115
 	defer c.mu.Unlock()
1115 1116
 
... ...
@@ -1126,7 +1070,8 @@ func (c *controller) Sandboxes() []Sandbox {
1126 1126
 	return list
1127 1127
 }
1128 1128
 
1129
-func (c *controller) WalkSandboxes(walker SandboxWalker) {
1129
+// WalkSandboxes uses the provided function to walk the Sandbox(s) managed by this controller.
1130
+func (c *Controller) WalkSandboxes(walker SandboxWalker) {
1130 1131
 	for _, sb := range c.Sandboxes() {
1131 1132
 		if walker(sb) {
1132 1133
 			return
... ...
@@ -1134,7 +1079,9 @@ func (c *controller) WalkSandboxes(walker SandboxWalker) {
1134 1134
 	}
1135 1135
 }
1136 1136
 
1137
-func (c *controller) SandboxByID(id string) (Sandbox, error) {
1137
+// SandboxByID returns the Sandbox which has the passed id.
1138
+// If not found, a [types.NotFoundError] is returned.
1139
+func (c *Controller) SandboxByID(id string) (Sandbox, error) {
1138 1140
 	if id == "" {
1139 1141
 		return nil, ErrInvalidID(id)
1140 1142
 	}
... ...
@@ -1147,8 +1094,8 @@ func (c *controller) SandboxByID(id string) (Sandbox, error) {
1147 1147
 	return s, nil
1148 1148
 }
1149 1149
 
1150
-// SandboxDestroy destroys a sandbox given a container ID
1151
-func (c *controller) SandboxDestroy(id string) error {
1150
+// SandboxDestroy destroys a sandbox given a container ID.
1151
+func (c *Controller) SandboxDestroy(id string) error {
1152 1152
 	var sb *sandbox
1153 1153
 	c.mu.Lock()
1154 1154
 	for _, s := range c.sandboxes {
... ...
@@ -1189,7 +1136,7 @@ func SandboxKeyWalker(out *Sandbox, key string) SandboxWalker {
1189 1189
 	}
1190 1190
 }
1191 1191
 
1192
-func (c *controller) loadDriver(networkType string) error {
1192
+func (c *Controller) loadDriver(networkType string) error {
1193 1193
 	var err error
1194 1194
 
1195 1195
 	if pg := c.GetPluginGetter(); pg != nil {
... ...
@@ -1208,7 +1155,7 @@ func (c *controller) loadDriver(networkType string) error {
1208 1208
 	return nil
1209 1209
 }
1210 1210
 
1211
-func (c *controller) loadIPAMDriver(name string) error {
1211
+func (c *Controller) loadIPAMDriver(name string) error {
1212 1212
 	var err error
1213 1213
 
1214 1214
 	if pg := c.GetPluginGetter(); pg != nil {
... ...
@@ -1227,7 +1174,7 @@ func (c *controller) loadIPAMDriver(name string) error {
1227 1227
 	return nil
1228 1228
 }
1229 1229
 
1230
-func (c *controller) getIPAMDriver(name string) (ipamapi.Ipam, *ipamapi.Capability, error) {
1230
+func (c *Controller) getIPAMDriver(name string) (ipamapi.Ipam, *ipamapi.Capability, error) {
1231 1231
 	id, cap := c.drvRegistry.IPAM(name)
1232 1232
 	if id == nil {
1233 1233
 		// Might be a plugin name. Try loading it
... ...
@@ -1245,14 +1192,15 @@ func (c *controller) getIPAMDriver(name string) (ipamapi.Ipam, *ipamapi.Capabili
1245 1245
 	return id, cap, nil
1246 1246
 }
1247 1247
 
1248
-func (c *controller) Stop() {
1248
+// Stop stops the network controller.
1249
+func (c *Controller) Stop() {
1249 1250
 	c.closeStores()
1250 1251
 	c.stopExternalKeyListener()
1251 1252
 	osl.GC()
1252 1253
 }
1253 1254
 
1254
-// StartDiagnostic start the network dias mode
1255
-func (c *controller) StartDiagnostic(port int) {
1255
+// StartDiagnostic starts the network diagnostic server listening on port.
1256
+func (c *Controller) StartDiagnostic(port int) {
1256 1257
 	c.mu.Lock()
1257 1258
 	if !c.DiagnosticServer.IsDiagnosticEnabled() {
1258 1259
 		c.DiagnosticServer.EnableDiagnostic("127.0.0.1", port)
... ...
@@ -1260,8 +1208,8 @@ func (c *controller) StartDiagnostic(port int) {
1260 1260
 	c.mu.Unlock()
1261 1261
 }
1262 1262
 
1263
-// StopDiagnostic start the network dias mode
1264
-func (c *controller) StopDiagnostic() {
1263
+// StopDiagnostic stops the network diagnostic server.
1264
+func (c *Controller) StopDiagnostic() {
1265 1265
 	c.mu.Lock()
1266 1266
 	if c.DiagnosticServer.IsDiagnosticEnabled() {
1267 1267
 		c.DiagnosticServer.DisableDiagnostic()
... ...
@@ -1269,14 +1217,14 @@ func (c *controller) StopDiagnostic() {
1269 1269
 	c.mu.Unlock()
1270 1270
 }
1271 1271
 
1272
-// IsDiagnosticEnabled returns true if the dias is enabled
1273
-func (c *controller) IsDiagnosticEnabled() bool {
1272
+// IsDiagnosticEnabled returns true if the diagnostic server is running.
1273
+func (c *Controller) IsDiagnosticEnabled() bool {
1274 1274
 	c.mu.Lock()
1275 1275
 	defer c.mu.Unlock()
1276 1276
 	return c.DiagnosticServer.IsDiagnosticEnabled()
1277 1277
 }
1278 1278
 
1279
-func (c *controller) iptablesEnabled() bool {
1279
+func (c *Controller) iptablesEnabled() bool {
1280 1280
 	c.mu.Lock()
1281 1281
 	defer c.mu.Unlock()
1282 1282
 
... ...
@@ -163,7 +163,7 @@ func (ep *endpoint) endpointInGWNetwork() bool {
163 163
 
164 164
 // Looks for the default gw network and creates it if not there.
165 165
 // Parallel executions are serialized.
166
-func (c *controller) defaultGwNetwork() (Network, error) {
166
+func (c *Controller) defaultGwNetwork() (Network, error) {
167 167
 	procGwNetwork <- true
168 168
 	defer func() { <-procGwNetwork }()
169 169
 
... ...
@@ -8,6 +8,6 @@ func getPlatformOption() EndpointOption {
8 8
 	return nil
9 9
 }
10 10
 
11
-func (c *controller) createGWNetwork() (Network, error) {
11
+func (c *Controller) createGWNetwork() (Network, error) {
12 12
 	return nil, types.NotImplementedErrorf("default gateway functionality is not implemented in freebsd")
13 13
 }
... ...
@@ -13,7 +13,7 @@ func getPlatformOption() EndpointOption {
13 13
 	return nil
14 14
 }
15 15
 
16
-func (c *controller) createGWNetwork() (Network, error) {
16
+func (c *Controller) createGWNetwork() (Network, error) {
17 17
 	netOption := map[string]string{
18 18
 		bridge.BridgeName:         libnGWNetwork,
19 19
 		bridge.EnableICC:          strconv.FormatBool(false),
... ...
@@ -17,6 +17,6 @@ func getPlatformOption() EndpointOption {
17 17
 	return EndpointOptionGeneric(epOption)
18 18
 }
19 19
 
20
-func (c *controller) createGWNetwork() (Network, error) {
20
+func (c *Controller) createGWNetwork() (Network, error) {
21 21
 	return nil, types.NotImplementedErrorf("default gateway functionality is not implemented in windows")
22 22
 }
... ...
@@ -1173,7 +1173,7 @@ func (ep *endpoint) releaseAddress() {
1173 1173
 	}
1174 1174
 }
1175 1175
 
1176
-func (c *controller) cleanupLocalEndpoints() {
1176
+func (c *Controller) cleanupLocalEndpoints() {
1177 1177
 	// Get used endpoints
1178 1178
 	eps := make(map[string]interface{})
1179 1179
 	for _, sb := range c.sandboxes {
... ...
@@ -30,8 +30,7 @@ fe90::2	somehost.example.com somehost
30 30
 		[]*IpamConf{{PreferredPool: "fe90::/64", Gateway: "fe90::1"}},
31 31
 		nil)}
32 32
 
33
-	c, nws := getTestEnv(t, opts)
34
-	ctrlr := c.(*controller)
33
+	ctrlr, nws := getTestEnv(t, opts)
35 34
 
36 35
 	hostsFile, err := os.CreateTemp("", "")
37 36
 	if err != nil {
... ...
@@ -7,9 +7,9 @@ import (
7 7
 
8 8
 const userChain = "DOCKER-USER"
9 9
 
10
-var ctrl *controller
10
+var ctrl *Controller
11 11
 
12
-func setupArrangeUserFilterRule(c *controller) {
12
+func setupArrangeUserFilterRule(c *Controller) {
13 13
 	ctrl = c
14 14
 	iptables.OnReloaded(arrangeUserFilterRule)
15 15
 }
... ...
@@ -51,10 +51,9 @@ func TestUserChain(t *testing.T) {
51 51
 			defer testutils.SetupTestOSContext(t)()
52 52
 			defer resetIptables(t)
53 53
 
54
-			nc, err := New()
54
+			c, err := New()
55 55
 			assert.NilError(t, err)
56
-			defer nc.Stop()
57
-			c := nc.(*controller)
56
+			defer c.Stop()
58 57
 			c.cfg.DriverCfg["bridge"] = map[string]interface{}{
59 58
 				netlabel.GenericData: options.Generic{
60 59
 					"EnableIPTables": tc.iptables,
... ...
@@ -3,5 +3,5 @@
3 3
 
4 4
 package libnetwork
5 5
 
6
-func setupArrangeUserFilterRule(c *controller) {}
6
+func setupArrangeUserFilterRule(c *Controller) {}
7 7
 func arrangeUserFilterRule()                   {}
... ...
@@ -320,7 +320,7 @@ func TestAuxAddresses(t *testing.T) {
320 320
 	}
321 321
 	defer c.Stop()
322 322
 
323
-	n := &network{ipamType: ipamapi.DefaultIPAM, networkType: "bridge", ctrlr: c.(*controller)}
323
+	n := &network{ipamType: ipamapi.DefaultIPAM, networkType: "bridge", ctrlr: c}
324 324
 
325 325
 	input := []struct {
326 326
 		masterPool   string
... ...
@@ -421,7 +421,7 @@ func TestSRVServiceQuery(t *testing.T) {
421 421
 	sr.service["web.swarm"] = append(sr.service["web.swarm"], httpPort)
422 422
 	sr.service["web.swarm"] = append(sr.service["web.swarm"], extHTTPPort)
423 423
 
424
-	c.(*controller).svcRecords[n.ID()] = sr
424
+	c.svcRecords[n.ID()] = sr
425 425
 
426 426
 	_, ip := ep.Info().Sandbox().ResolveService("_http._tcp.web.swarm")
427 427
 
... ...
@@ -576,9 +576,7 @@ func TestIpamReleaseOnNetDriverFailures(t *testing.T) {
576 576
 	}
577 577
 	defer c.Stop()
578 578
 
579
-	cc := c.(*controller)
580
-
581
-	if err := cc.drvRegistry.AddDriver(badDriverName, badDriverInit, nil); err != nil {
579
+	if err := c.drvRegistry.AddDriver(badDriverName, badDriverInit, nil); err != nil {
582 580
 		t.Fatal(err)
583 581
 	}
584 582
 
... ...
@@ -30,7 +30,7 @@ const (
30 30
 	bridgeNetType = "bridge"
31 31
 )
32 32
 
33
-func makeTesthostNetwork(t *testing.T, c libnetwork.NetworkController) libnetwork.Network {
33
+func makeTesthostNetwork(t *testing.T, c *libnetwork.Controller) libnetwork.Network {
34 34
 	t.Helper()
35 35
 	n, err := createTestNetwork(c, "host", "testhost", options.Generic{}, nil, nil)
36 36
 	if err != nil {
... ...
@@ -845,7 +845,7 @@ func TestResolvConf(t *testing.T) {
845 845
 
846 846
 type parallelTester struct {
847 847
 	osctx      *testutils.OSContext
848
-	controller libnetwork.NetworkController
848
+	controller *libnetwork.Controller
849 849
 	net1, net2 libnetwork.Network
850 850
 	iterCnt    int
851 851
 }
... ...
@@ -43,7 +43,7 @@ func TestMain(m *testing.M) {
43 43
 	os.Exit(m.Run())
44 44
 }
45 45
 
46
-func newController(t *testing.T) libnetwork.NetworkController {
46
+func newController(t *testing.T) *libnetwork.Controller {
47 47
 	t.Helper()
48 48
 	genericOption := map[string]interface{}{
49 49
 		netlabel.GenericData: options.Generic{
... ...
@@ -62,7 +62,7 @@ func newController(t *testing.T) libnetwork.NetworkController {
62 62
 	return c
63 63
 }
64 64
 
65
-func createTestNetwork(c libnetwork.NetworkController, networkType, networkName string, netOption options.Generic, ipamV4Configs, ipamV6Configs []*libnetwork.IpamConf) (libnetwork.Network, error) {
65
+func createTestNetwork(c *libnetwork.Controller, networkType, networkName string, netOption options.Generic, ipamV4Configs, ipamV6Configs []*libnetwork.IpamConf) (libnetwork.Network, error) {
66 66
 	return c.NewNetwork(networkType, networkName, "",
67 67
 		libnetwork.NetworkOptionGeneric(netOption),
68 68
 		libnetwork.NetworkOptionIpam(ipamapi.DefaultIPAM, "", ipamV4Configs, ipamV6Configs, nil))
... ...
@@ -200,7 +200,7 @@ func (i *IpamInfo) UnmarshalJSON(data []byte) error {
200 200
 }
201 201
 
202 202
 type network struct {
203
-	ctrlr            *controller
203
+	ctrlr            *Controller
204 204
 	name             string
205 205
 	networkType      string
206 206
 	id               string
... ...
@@ -1517,7 +1517,7 @@ func (n *network) getSvcRecords(ep *endpoint) []etchosts.Record {
1517 1517
 	return recs
1518 1518
 }
1519 1519
 
1520
-func (n *network) getController() *controller {
1520
+func (n *network) getController() *Controller {
1521 1521
 	n.Lock()
1522 1522
 	defer n.Unlock()
1523 1523
 	return n.ctrlr
... ...
@@ -2139,7 +2139,7 @@ func (n *network) NdotsSet() bool {
2139 2139
 }
2140 2140
 
2141 2141
 // config-only network is looked up by name
2142
-func (c *controller) getConfigNetwork(name string) (*network, error) {
2142
+func (c *Controller) getConfigNetwork(name string) (*network, error) {
2143 2143
 	var n Network
2144 2144
 
2145 2145
 	s := func(current Network) bool {
... ...
@@ -69,7 +69,7 @@ type sandbox struct {
69 69
 	config             containerConfig
70 70
 	extDNS             []extDNSEntry
71 71
 	osSbox             osl.Sandbox
72
-	controller         *controller
72
+	controller         *Controller
73 73
 	resolver           Resolver
74 74
 	resolverOnce       sync.Once
75 75
 	endpoints          []*endpoint
... ...
@@ -112,7 +112,7 @@ func processReturn(r io.Reader) error {
112 112
 	return nil
113 113
 }
114 114
 
115
-func (c *controller) startExternalKeyListener() error {
115
+func (c *Controller) startExternalKeyListener() error {
116 116
 	execRoot := defaultExecRoot
117 117
 	if v := c.Config().ExecRoot; v != "" {
118 118
 		execRoot = v
... ...
@@ -139,7 +139,7 @@ func (c *controller) startExternalKeyListener() error {
139 139
 	return nil
140 140
 }
141 141
 
142
-func (c *controller) acceptClientConnections(sock string, l net.Listener) {
142
+func (c *Controller) acceptClientConnections(sock string, l net.Listener) {
143 143
 	for {
144 144
 		conn, err := l.Accept()
145 145
 		if err != nil {
... ...
@@ -167,7 +167,7 @@ func (c *controller) acceptClientConnections(sock string, l net.Listener) {
167 167
 	}
168 168
 }
169 169
 
170
-func (c *controller) processExternalKey(conn net.Conn) error {
170
+func (c *Controller) processExternalKey(conn net.Conn) error {
171 171
 	buf := make([]byte, 1280)
172 172
 	nr, err := conn.Read(buf)
173 173
 	if err != nil {
... ...
@@ -188,6 +188,6 @@ func (c *controller) processExternalKey(conn net.Conn) error {
188 188
 	return sandbox.SetKey(s.Key)
189 189
 }
190 190
 
191
-func (c *controller) stopExternalKeyListener() {
191
+func (c *Controller) stopExternalKeyListener() {
192 192
 	c.extKeyListener.Close()
193 193
 }
... ...
@@ -31,16 +31,16 @@ func processReturn(r io.Reader) error {
31 31
 }
32 32
 
33 33
 // no-op on non linux systems
34
-func (c *controller) startExternalKeyListener() error {
34
+func (c *Controller) startExternalKeyListener() error {
35 35
 	return nil
36 36
 }
37 37
 
38
-func (c *controller) acceptClientConnections(sock string, l net.Listener) {
38
+func (c *Controller) acceptClientConnections(sock string, l net.Listener) {
39 39
 }
40 40
 
41
-func (c *controller) processExternalKey(conn net.Conn) error {
41
+func (c *Controller) processExternalKey(conn net.Conn) error {
42 42
 	return types.NotImplementedErrorf("processExternalKey isn't supported on non linux systems")
43 43
 }
44 44
 
45
-func (c *controller) stopExternalKeyListener() {
45
+func (c *Controller) stopExternalKeyListener() {
46 46
 }
... ...
@@ -21,7 +21,7 @@ type epState struct {
21 21
 type sbState struct {
22 22
 	ID         string
23 23
 	Cid        string
24
-	c          *controller
24
+	c          *Controller
25 25
 	dbIndex    uint64
26 26
 	dbExists   bool
27 27
 	Eps        []epState
... ...
@@ -189,7 +189,7 @@ func (sb *sandbox) storeDelete() error {
189 189
 	return sb.controller.deleteFromStore(sbs)
190 190
 }
191 191
 
192
-func (c *controller) sandboxCleanup(activeSandboxes map[string]interface{}) {
192
+func (c *Controller) sandboxCleanup(activeSandboxes map[string]interface{}) {
193 193
 	store := c.getStore(datastore.LocalScope)
194 194
 	if store == nil {
195 195
 		logrus.Error("Could not find local scope store while trying to cleanup sandboxes")
... ...
@@ -14,7 +14,7 @@ import (
14 14
 	"gotest.tools/v3/skip"
15 15
 )
16 16
 
17
-func getTestEnv(t *testing.T, opts ...[]NetworkOption) (NetworkController, []Network) {
17
+func getTestEnv(t *testing.T, opts ...[]NetworkOption) (*Controller, []Network) {
18 18
 	skip.If(t, runtime.GOOS == "windows", "test only works on linux")
19 19
 
20 20
 	netType := "bridge"
... ...
@@ -61,8 +61,7 @@ func getTestEnv(t *testing.T, opts ...[]NetworkOption) (NetworkController, []Net
61 61
 }
62 62
 
63 63
 func TestSandboxAddEmpty(t *testing.T) {
64
-	c, _ := getTestEnv(t)
65
-	ctrlr := c.(*controller)
64
+	ctrlr, _ := getTestEnv(t)
66 65
 
67 66
 	sbx, err := ctrlr.NewSandbox("sandbox0")
68 67
 	if err != nil {
... ...
@@ -90,8 +89,7 @@ func TestSandboxAddMultiPrio(t *testing.T) {
90 90
 		{},
91 91
 	}
92 92
 
93
-	c, nws := getTestEnv(t, opts...)
94
-	ctrlr := c.(*controller)
93
+	ctrlr, nws := getTestEnv(t, opts...)
95 94
 
96 95
 	sbx, err := ctrlr.NewSandbox("sandbox1")
97 96
 	if err != nil {
... ...
@@ -176,9 +174,7 @@ func TestSandboxAddSamePrio(t *testing.T) {
176 176
 		{NetworkOptionInternalNetwork()},
177 177
 	}
178 178
 
179
-	c, nws := getTestEnv(t, opts...)
180
-
181
-	ctrlr := c.(*controller)
179
+	ctrlr, nws := getTestEnv(t, opts...)
182 180
 
183 181
 	sbx, err := ctrlr.NewSandbox("sandbox1")
184 182
 	if err != nil {
... ...
@@ -12,7 +12,7 @@ import (
12 12
 
13 13
 const maxSetStringLen = 350
14 14
 
15
-func (c *controller) addEndpointNameResolution(svcName, svcID, nID, eID, containerName string, vip net.IP, serviceAliases, taskAliases []string, ip net.IP, addService bool, method string) error {
15
+func (c *Controller) addEndpointNameResolution(svcName, svcID, nID, eID, containerName string, vip net.IP, serviceAliases, taskAliases []string, ip net.IP, addService bool, method string) error {
16 16
 	n, err := c.NetworkByID(nID)
17 17
 	if err != nil {
18 18
 		return err
... ...
@@ -55,7 +55,7 @@ func (c *controller) addEndpointNameResolution(svcName, svcID, nID, eID, contain
55 55
 	return nil
56 56
 }
57 57
 
58
-func (c *controller) addContainerNameResolution(nID, eID, containerName string, taskAliases []string, ip net.IP, method string) error {
58
+func (c *Controller) addContainerNameResolution(nID, eID, containerName string, taskAliases []string, ip net.IP, method string) error {
59 59
 	n, err := c.NetworkByID(nID)
60 60
 	if err != nil {
61 61
 		return err
... ...
@@ -73,7 +73,7 @@ func (c *controller) addContainerNameResolution(nID, eID, containerName string,
73 73
 	return nil
74 74
 }
75 75
 
76
-func (c *controller) deleteEndpointNameResolution(svcName, svcID, nID, eID, containerName string, vip net.IP, serviceAliases, taskAliases []string, ip net.IP, rmService, multipleEntries bool, method string) error {
76
+func (c *Controller) deleteEndpointNameResolution(svcName, svcID, nID, eID, containerName string, vip net.IP, serviceAliases, taskAliases []string, ip net.IP, rmService, multipleEntries bool, method string) error {
77 77
 	n, err := c.NetworkByID(nID)
78 78
 	if err != nil {
79 79
 		return err
... ...
@@ -119,7 +119,7 @@ func (c *controller) deleteEndpointNameResolution(svcName, svcID, nID, eID, cont
119 119
 	return nil
120 120
 }
121 121
 
122
-func (c *controller) delContainerNameResolution(nID, eID, containerName string, taskAliases []string, ip net.IP, method string) error {
122
+func (c *Controller) delContainerNameResolution(nID, eID, containerName string, taskAliases []string, ip net.IP, method string) error {
123 123
 	n, err := c.NetworkByID(nID)
124 124
 	if err != nil {
125 125
 		return err
... ...
@@ -148,7 +148,7 @@ func newService(name string, id string, ingressPorts []*PortConfig, serviceAlias
148 148
 	}
149 149
 }
150 150
 
151
-func (c *controller) getLBIndex(sid, nid string, ingressPorts []*PortConfig) int {
151
+func (c *Controller) getLBIndex(sid, nid string, ingressPorts []*PortConfig) int {
152 152
 	skey := serviceKey{
153 153
 		id:    sid,
154 154
 		ports: portConfigs(ingressPorts).String(),
... ...
@@ -169,7 +169,7 @@ func (c *controller) getLBIndex(sid, nid string, ingressPorts []*PortConfig) int
169 169
 }
170 170
 
171 171
 // cleanupServiceDiscovery when the network is being deleted, erase all the associated service discovery records
172
-func (c *controller) cleanupServiceDiscovery(cleanupNID string) {
172
+func (c *Controller) cleanupServiceDiscovery(cleanupNID string) {
173 173
 	c.mu.Lock()
174 174
 	defer c.mu.Unlock()
175 175
 	if cleanupNID == "" {
... ...
@@ -181,7 +181,7 @@ func (c *controller) cleanupServiceDiscovery(cleanupNID string) {
181 181
 	delete(c.svcRecords, cleanupNID)
182 182
 }
183 183
 
184
-func (c *controller) cleanupServiceBindings(cleanupNID string) {
184
+func (c *Controller) cleanupServiceBindings(cleanupNID string) {
185 185
 	var cleanupFuncs []func()
186 186
 
187 187
 	logrus.Debugf("cleanupServiceBindings for %s", cleanupNID)
... ...
@@ -215,7 +215,7 @@ func (c *controller) cleanupServiceBindings(cleanupNID string) {
215 215
 	}
216 216
 }
217 217
 
218
-func makeServiceCleanupFunc(c *controller, s *service, nID, eID string, vip net.IP, ip net.IP) func() {
218
+func makeServiceCleanupFunc(c *Controller, s *service, nID, eID string, vip net.IP, ip net.IP) func() {
219 219
 	// ContainerName and taskAliases are not available here, this is still fine because the Service discovery
220 220
 	// cleanup already happened before. The only thing that rmServiceBinding is still doing here a part from the Load
221 221
 	// Balancer bookeeping, is to keep consistent the mapping of endpoint to IP.
... ...
@@ -226,7 +226,7 @@ func makeServiceCleanupFunc(c *controller, s *service, nID, eID string, vip net.
226 226
 	}
227 227
 }
228 228
 
229
-func (c *controller) addServiceBinding(svcName, svcID, nID, eID, containerName string, vip net.IP, ingressPorts []*PortConfig, serviceAliases, taskAliases []string, ip net.IP, method string) error {
229
+func (c *Controller) addServiceBinding(svcName, svcID, nID, eID, containerName string, vip net.IP, ingressPorts []*PortConfig, serviceAliases, taskAliases []string, ip net.IP, method string) error {
230 230
 	var addService bool
231 231
 
232 232
 	// Failure to lock the network ID on add can result in racing
... ...
@@ -313,7 +313,7 @@ func (c *controller) addServiceBinding(svcName, svcID, nID, eID, containerName s
313 313
 	return nil
314 314
 }
315 315
 
316
-func (c *controller) rmServiceBinding(svcName, svcID, nID, eID, containerName string, vip net.IP, ingressPorts []*PortConfig, serviceAliases []string, taskAliases []string, ip net.IP, method string, deleteSvcRecords bool, fullRemove bool) error {
316
+func (c *Controller) rmServiceBinding(svcName, svcID, nID, eID, containerName string, vip net.IP, ingressPorts []*PortConfig, serviceAliases []string, taskAliases []string, ip net.IP, method string, deleteSvcRecords bool, fullRemove bool) error {
317 317
 	var rmService bool
318 318
 
319 319
 	skey := serviceKey{
... ...
@@ -39,21 +39,21 @@ func TestCleanupServiceDiscovery(t *testing.T) {
39 39
 	n2.(*network).addSvcRecords("N2ep1", "service_test", "serviceID1", net.ParseIP("192.168.1.1"), net.IP{}, true, "test")
40 40
 	n2.(*network).addSvcRecords("N2ep2", "service_test", "serviceID2", net.ParseIP("192.168.1.2"), net.IP{}, true, "test")
41 41
 
42
-	if len(c.(*controller).svcRecords) != 2 {
43
-		t.Fatalf("Service record not added correctly:%v", c.(*controller).svcRecords)
42
+	if len(c.svcRecords) != 2 {
43
+		t.Fatalf("Service record not added correctly:%v", c.svcRecords)
44 44
 	}
45 45
 
46 46
 	// cleanup net1
47
-	c.(*controller).cleanupServiceDiscovery(n1.ID())
47
+	c.cleanupServiceDiscovery(n1.ID())
48 48
 
49
-	if len(c.(*controller).svcRecords) != 1 {
50
-		t.Fatalf("Service record not cleaned correctly:%v", c.(*controller).svcRecords)
49
+	if len(c.svcRecords) != 1 {
50
+		t.Fatalf("Service record not cleaned correctly:%v", c.svcRecords)
51 51
 	}
52 52
 
53
-	c.(*controller).cleanupServiceDiscovery("")
53
+	c.cleanupServiceDiscovery("")
54 54
 
55
-	if len(c.(*controller).svcRecords) != 0 {
56
-		t.Fatalf("Service record not cleaned correctly:%v", c.(*controller).svcRecords)
55
+	if len(c.svcRecords) != 0 {
56
+		t.Fatalf("Service record not cleaned correctly:%v", c.svcRecords)
57 57
 	}
58 58
 }
59 59
 
... ...
@@ -63,7 +63,7 @@ func TestDNSOptions(t *testing.T) {
63 63
 	c, err := New()
64 64
 	assert.NilError(t, err)
65 65
 
66
-	sb, err := c.(*controller).NewSandbox("cnt1", nil)
66
+	sb, err := c.NewSandbox("cnt1", nil)
67 67
 	assert.NilError(t, err)
68 68
 
69 69
 	cleanup := func(s Sandbox) {
... ...
@@ -102,7 +102,7 @@ func TestDNSOptions(t *testing.T) {
102 102
 	assert.Check(t, is.Len(dnsOptionsList, 1))
103 103
 	assert.Check(t, is.Equal("ndots:5", dnsOptionsList[0]))
104 104
 
105
-	sb2, err := c.(*controller).NewSandbox("cnt2", nil)
105
+	sb2, err := c.NewSandbox("cnt2", nil)
106 106
 	assert.NilError(t, err)
107 107
 	defer cleanup(sb2)
108 108
 	sb2.(*sandbox).startResolver(false)
... ...
@@ -8,14 +8,14 @@ import (
8 8
 	"net"
9 9
 )
10 10
 
11
-func (c *controller) cleanupServiceBindings(nid string) {
11
+func (c *Controller) cleanupServiceBindings(nid string) {
12 12
 }
13 13
 
14
-func (c *controller) addServiceBinding(name, sid, nid, eid string, vip net.IP, ingressPorts []*PortConfig, aliases []string, ip net.IP) error {
14
+func (c *Controller) addServiceBinding(name, sid, nid, eid string, vip net.IP, ingressPorts []*PortConfig, aliases []string, ip net.IP) error {
15 15
 	return fmt.Errorf("not supported")
16 16
 }
17 17
 
18
-func (c *controller) rmServiceBinding(name, sid, nid, eid string, vip net.IP, ingressPorts []*PortConfig, aliases []string, ip net.IP) error {
18
+func (c *Controller) rmServiceBinding(name, sid, nid, eid string, vip net.IP, ingressPorts []*PortConfig, aliases []string, ip net.IP) error {
19 19
 	return fmt.Errorf("not supported")
20 20
 }
21 21
 
... ...
@@ -13,7 +13,7 @@ func registerKVStores() {
13 13
 	boltdb.Register()
14 14
 }
15 15
 
16
-func (c *controller) initScopedStore(scope string, scfg *datastore.ScopeCfg) error {
16
+func (c *Controller) initScopedStore(scope string, scfg *datastore.ScopeCfg) error {
17 17
 	store, err := datastore.NewDataStore(scope, scfg)
18 18
 	if err != nil {
19 19
 		return err
... ...
@@ -25,7 +25,7 @@ func (c *controller) initScopedStore(scope string, scfg *datastore.ScopeCfg) err
25 25
 	return nil
26 26
 }
27 27
 
28
-func (c *controller) initStores() error {
28
+func (c *Controller) initStores() error {
29 29
 	registerKVStores()
30 30
 
31 31
 	c.mu.Lock()
... ...
@@ -47,13 +47,13 @@ func (c *controller) initStores() error {
47 47
 	return nil
48 48
 }
49 49
 
50
-func (c *controller) closeStores() {
50
+func (c *Controller) closeStores() {
51 51
 	for _, store := range c.getStores() {
52 52
 		store.Close()
53 53
 	}
54 54
 }
55 55
 
56
-func (c *controller) getStore(scope string) datastore.DataStore {
56
+func (c *Controller) getStore(scope string) datastore.DataStore {
57 57
 	c.mu.Lock()
58 58
 	defer c.mu.Unlock()
59 59
 
... ...
@@ -66,14 +66,14 @@ func (c *controller) getStore(scope string) datastore.DataStore {
66 66
 	return nil
67 67
 }
68 68
 
69
-func (c *controller) getStores() []datastore.DataStore {
69
+func (c *Controller) getStores() []datastore.DataStore {
70 70
 	c.mu.Lock()
71 71
 	defer c.mu.Unlock()
72 72
 
73 73
 	return c.stores
74 74
 }
75 75
 
76
-func (c *controller) getNetworkFromStore(nid string) (*network, error) {
76
+func (c *Controller) getNetworkFromStore(nid string) (*network, error) {
77 77
 	for _, n := range c.getNetworksFromStore() {
78 78
 		if n.id == nid {
79 79
 			return n, nil
... ...
@@ -82,7 +82,7 @@ func (c *controller) getNetworkFromStore(nid string) (*network, error) {
82 82
 	return nil, ErrNoSuchNetwork(nid)
83 83
 }
84 84
 
85
-func (c *controller) getNetworksForScope(scope string) ([]*network, error) {
85
+func (c *Controller) getNetworksForScope(scope string) ([]*network, error) {
86 86
 	var nl []*network
87 87
 
88 88
 	store := c.getStore(scope)
... ...
@@ -118,7 +118,7 @@ func (c *controller) getNetworksForScope(scope string) ([]*network, error) {
118 118
 	return nl, nil
119 119
 }
120 120
 
121
-func (c *controller) getNetworksFromStore() []*network {
121
+func (c *Controller) getNetworksFromStore() []*network {
122 122
 	var nl []*network
123 123
 
124 124
 	for _, store := range c.getStores() {
... ...
@@ -200,7 +200,7 @@ func (n *network) getEndpointsFromStore() ([]*endpoint, error) {
200 200
 	return epl, nil
201 201
 }
202 202
 
203
-func (c *controller) updateToStore(kvObject datastore.KVObject) error {
203
+func (c *Controller) updateToStore(kvObject datastore.KVObject) error {
204 204
 	cs := c.getStore(kvObject.DataScope())
205 205
 	if cs == nil {
206 206
 		return ErrDataStoreNotInitialized(kvObject.DataScope())
... ...
@@ -216,7 +216,7 @@ func (c *controller) updateToStore(kvObject datastore.KVObject) error {
216 216
 	return nil
217 217
 }
218 218
 
219
-func (c *controller) deleteFromStore(kvObject datastore.KVObject) error {
219
+func (c *Controller) deleteFromStore(kvObject datastore.KVObject) error {
220 220
 	cs := c.getStore(kvObject.DataScope())
221 221
 	if cs == nil {
222 222
 		return ErrDataStoreNotInitialized(kvObject.DataScope())
... ...
@@ -243,7 +243,7 @@ type netWatch struct {
243 243
 	stopCh    chan struct{}
244 244
 }
245 245
 
246
-func (c *controller) getLocalEps(nw *netWatch) []*endpoint {
246
+func (c *Controller) getLocalEps(nw *netWatch) []*endpoint {
247 247
 	c.mu.Lock()
248 248
 	defer c.mu.Unlock()
249 249
 
... ...
@@ -255,15 +255,15 @@ func (c *controller) getLocalEps(nw *netWatch) []*endpoint {
255 255
 	return epl
256 256
 }
257 257
 
258
-func (c *controller) watchSvcRecord(ep *endpoint) {
258
+func (c *Controller) watchSvcRecord(ep *endpoint) {
259 259
 	c.watchCh <- ep
260 260
 }
261 261
 
262
-func (c *controller) unWatchSvcRecord(ep *endpoint) {
262
+func (c *Controller) unWatchSvcRecord(ep *endpoint) {
263 263
 	c.unWatchCh <- ep
264 264
 }
265 265
 
266
-func (c *controller) networkWatchLoop(nw *netWatch, ep *endpoint, ecCh <-chan datastore.KVObject) {
266
+func (c *Controller) networkWatchLoop(nw *netWatch, ep *endpoint, ecCh <-chan datastore.KVObject) {
267 267
 	for {
268 268
 		select {
269 269
 		case <-nw.stopCh:
... ...
@@ -327,7 +327,7 @@ func (c *controller) networkWatchLoop(nw *netWatch, ep *endpoint, ecCh <-chan da
327 327
 	}
328 328
 }
329 329
 
330
-func (c *controller) processEndpointCreate(nmap map[string]*netWatch, ep *endpoint) {
330
+func (c *Controller) processEndpointCreate(nmap map[string]*netWatch, ep *endpoint) {
331 331
 	n := ep.getNetwork()
332 332
 	if !c.isDistributedControl() && n.Scope() == datastore.SwarmScope && n.driverIsMultihost() {
333 333
 		return
... ...
@@ -389,7 +389,7 @@ func (c *controller) processEndpointCreate(nmap map[string]*netWatch, ep *endpoi
389 389
 	go c.networkWatchLoop(nw, ep, ch)
390 390
 }
391 391
 
392
-func (c *controller) processEndpointDelete(nmap map[string]*netWatch, ep *endpoint) {
392
+func (c *Controller) processEndpointDelete(nmap map[string]*netWatch, ep *endpoint) {
393 393
 	n := ep.getNetwork()
394 394
 	if !c.isDistributedControl() && n.Scope() == datastore.SwarmScope && n.driverIsMultihost() {
395 395
 		return
... ...
@@ -424,7 +424,7 @@ func (c *controller) processEndpointDelete(nmap map[string]*netWatch, ep *endpoi
424 424
 	c.mu.Unlock()
425 425
 }
426 426
 
427
-func (c *controller) watchLoop() {
427
+func (c *Controller) watchLoop() {
428 428
 	for {
429 429
 		select {
430 430
 		case ep := <-c.watchCh:
... ...
@@ -435,7 +435,7 @@ func (c *controller) watchLoop() {
435 435
 	}
436 436
 }
437 437
 
438
-func (c *controller) startWatch() {
438
+func (c *Controller) startWatch() {
439 439
 	if c.watchCh != nil {
440 440
 		return
441 441
 	}
... ...
@@ -446,7 +446,7 @@ func (c *controller) startWatch() {
446 446
 	go c.watchLoop()
447 447
 }
448 448
 
449
-func (c *controller) networkCleanup() {
449
+func (c *Controller) networkCleanup() {
450 450
 	for _, n := range c.getNetworksFromStore() {
451 451
 		if n.inDelete {
452 452
 			logrus.Infof("Removing stale network %s (%s)", n.Name(), n.ID())
... ...
@@ -30,7 +30,7 @@ func TestNoPersist(t *testing.T) {
30 30
 	if err != nil {
31 31
 		t.Fatalf("Error creating endpoint: %v", err)
32 32
 	}
33
-	store := ctrl.(*controller).getStore(datastore.LocalScope).KVStore()
33
+	store := ctrl.getStore(datastore.LocalScope).KVStore()
34 34
 	if exists, _ := store.Exists(datastore.Key(datastore.NetworkKeyPrefix, nw.ID())); exists {
35 35
 		t.Fatalf("Network with persist=false should not be stored in KV Store")
36 36
 	}
... ...
@@ -36,7 +36,7 @@ func testLocalBackend(t *testing.T, provider, url string, storeConfig *store.Con
36 36
 	if err != nil {
37 37
 		t.Fatalf("Error creating endpoint: %v", err)
38 38
 	}
39
-	store := ctrl.(*controller).getStore(datastore.LocalScope).KVStore()
39
+	store := ctrl.getStore(datastore.LocalScope).KVStore()
40 40
 	if exists, err := store.Exists(datastore.Key(datastore.NetworkKeyPrefix, nw.ID())); !exists || err != nil {
41 41
 		t.Fatalf("Network key should have been created.")
42 42
 	}