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>
This commit is contained in:
Cory Snider 2023-01-11 17:43:32 -05:00
parent ae09fe3da7
commit f96b9bf761
33 changed files with 177 additions and 237 deletions

View file

@ -69,7 +69,7 @@ type Opt struct {
SessionManager *session.Manager
Root string
Dist images.DistributionServices
NetworkController libnetwork.NetworkController
NetworkController *libnetwork.Controller
DefaultCgroupParent string
RegistryHosts docker.RegistryHosts
BuilderConfig config.BuilderConfig

View file

@ -25,10 +25,10 @@ import (
const networkName = "bridge"
func newExecutor(root, cgroupParent string, net libnetwork.NetworkController, dnsConfig *oci.DNSConfig, rootless bool, idmap idtools.IdentityMapping, apparmorProfile string) (executor.Executor, error) {
func newExecutor(root, cgroupParent string, net *libnetwork.Controller, dnsConfig *oci.DNSConfig, rootless bool, idmap idtools.IdentityMapping, apparmorProfile string) (executor.Executor, error) {
netRoot := filepath.Join(root, "net")
networkProviders := map[pb.NetMode]network.Provider{
pb.NetMode_UNSET: &bridgeProvider{NetworkController: net, Root: netRoot},
pb.NetMode_UNSET: &bridgeProvider{Controller: net, Root: netRoot},
pb.NetMode_HOST: network.NewHostProvider(),
pb.NetMode_NONE: network.NewNoneProvider(),
}
@ -64,7 +64,7 @@ func newExecutor(root, cgroupParent string, net libnetwork.NetworkController, dn
}
type bridgeProvider struct {
libnetwork.NetworkController
*libnetwork.Controller
Root string
}
@ -76,7 +76,7 @@ func (p *bridgeProvider) New() (network.Namespace, error) {
iface := &lnInterface{ready: make(chan struct{}), provider: p}
iface.Once.Do(func() {
go iface.init(p.NetworkController, n)
go iface.init(p.Controller, n)
})
return iface, nil
@ -91,7 +91,7 @@ type lnInterface struct {
provider *bridgeProvider
}
func (iface *lnInterface) init(c libnetwork.NetworkController, n libnetwork.Network) {
func (iface *lnInterface) init(c *libnetwork.Controller, n libnetwork.Network) {
defer close(iface.ready)
id := identity.NewID()
@ -123,7 +123,7 @@ func (iface *lnInterface) Set(s *specs.Spec) error {
logrus.WithError(iface.err).Error("failed to set networking spec")
return iface.err
}
shortNetCtlrID := stringid.TruncateID(iface.provider.NetworkController.ID())
shortNetCtlrID := stringid.TruncateID(iface.provider.Controller.ID())
// attach netns to bridge within the container namespace, using reexec in a prestart hook
s.Hooks = &specs.Hooks{
Prestart: []specs.Hook{{

View file

@ -11,7 +11,7 @@ import (
"github.com/moby/buildkit/executor/oci"
)
func newExecutor(_, _ string, _ libnetwork.NetworkController, _ *oci.DNSConfig, _ bool, _ idtools.IdentityMapping, _ string) (executor.Executor, error) {
func newExecutor(_, _ string, _ *libnetwork.Controller, _ *oci.DNSConfig, _ bool, _ idtools.IdentityMapping, _ string) (executor.Executor, error) {
return &winExecutor{}, nil
}

View file

@ -83,7 +83,7 @@ type Daemon struct {
defaultLogConfig containertypes.LogConfig
registryService registry.Service
EventsService *events.Events
netController libnetwork.NetworkController
netController *libnetwork.Controller
volumes *volumesservice.VolumesService
root string
sysInfoOnce sync.Once

View file

@ -864,7 +864,7 @@ func (daemon *Daemon) initNetworkController(activeSandboxes map[string]interface
return nil
}
func configureNetworking(controller libnetwork.NetworkController, conf *config.Config) error {
func configureNetworking(controller *libnetwork.Controller, conf *config.Config) error {
// Initialize default network on "null"
if n, _ := controller.NetworkByName("none"); n == nil {
if _, err := controller.NewNetwork("null", "none", "", libnetwork.NetworkOptionPersist(true)); err != nil {
@ -902,7 +902,7 @@ func configureNetworking(controller libnetwork.NetworkController, conf *config.C
}
// setHostGatewayIP sets cfg.HostGatewayIP to the default bridge's IP if it is empty.
func setHostGatewayIP(controller libnetwork.NetworkController, config *config.Config) {
func setHostGatewayIP(controller *libnetwork.Controller, config *config.Config) {
if config.HostGatewayIP != nil {
return
}
@ -930,7 +930,7 @@ func driverOptions(config *config.Config) nwconfig.Option {
})
}
func initBridgeDriver(controller libnetwork.NetworkController, config *config.Config) error {
func initBridgeDriver(controller *libnetwork.Controller, config *config.Config) error {
bridgeName := bridge.DefaultBridgeName
if config.BridgeConfig.Iface != "" {
bridgeName = config.BridgeConfig.Iface

View file

@ -409,7 +409,7 @@ func (daemon *Daemon) initNetworkController(activeSandboxes map[string]interface
return nil
}
func initBridgeDriver(controller libnetwork.NetworkController, config *config.Config) error {
func initBridgeDriver(controller *libnetwork.Controller, config *config.Config) error {
if _, err := controller.NetworkByName(runconfig.DefaultDaemonNetworkMode().NetworkName()); err == nil {
return nil
}

View file

@ -50,7 +50,7 @@ func (daemon *Daemon) NetworkControllerEnabled() bool {
}
// NetworkController returns the network controller created by the daemon.
func (daemon *Daemon) NetworkController() libnetwork.NetworkController {
func (daemon *Daemon) NetworkController() *libnetwork.Controller {
return daemon.netController
}

View file

@ -97,7 +97,7 @@ func resolveAddr(addrOrInterface string) (string, error) {
return addr.String(), nil
}
func (c *controller) handleKeyChange(keys []*types.EncryptionKey) error {
func (c *Controller) handleKeyChange(keys []*types.EncryptionKey) error {
drvEnc := discoverapi.DriverEncryptionUpdate{}
a := c.getAgent()
@ -201,7 +201,7 @@ func (c *controller) handleKeyChange(keys []*types.EncryptionKey) error {
return nil
}
func (c *controller) agentSetup(clusterProvider cluster.Provider) error {
func (c *Controller) agentSetup(clusterProvider cluster.Provider) error {
agent := c.getAgent()
// 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 {
// For a given subsystem getKeys sorts the keys by lamport time and returns
// slice of keys and lamport time which can used as a unique tag for the keys
func (c *controller) getKeys(subsys string) ([][]byte, []uint64) {
func (c *Controller) getKeys(subsys string) ([][]byte, []uint64) {
c.mu.Lock()
defer c.mu.Unlock()
@ -270,7 +270,7 @@ func (c *controller) getKeys(subsys string) ([][]byte, []uint64) {
// getPrimaryKeyTag returns the primary key for a given subsystem from the
// list of sorted key and the associated tag
func (c *controller) getPrimaryKeyTag(subsys string) ([]byte, uint64, error) {
func (c *Controller) getPrimaryKeyTag(subsys string) ([]byte, uint64, error) {
c.mu.Lock()
defer c.mu.Unlock()
sort.Sort(ByTime(c.keys))
@ -283,7 +283,7 @@ func (c *controller) getPrimaryKeyTag(subsys string) ([]byte, uint64, error) {
return keys[1].Key, keys[1].LamportTime, nil
}
func (c *controller) agentInit(listenAddr, bindAddrOrInterface, advertiseAddr, dataPathAddr string) error {
func (c *Controller) agentInit(listenAddr, bindAddrOrInterface, advertiseAddr, dataPathAddr string) error {
bindAddr, err := resolveAddr(bindAddrOrInterface)
if err != nil {
return err
@ -348,7 +348,7 @@ func (c *controller) agentInit(listenAddr, bindAddrOrInterface, advertiseAddr, d
return nil
}
func (c *controller) agentJoin(remoteAddrList []string) error {
func (c *Controller) agentJoin(remoteAddrList []string) error {
agent := c.getAgent()
if agent == nil {
return nil
@ -356,7 +356,7 @@ func (c *controller) agentJoin(remoteAddrList []string) error {
return agent.networkDB.Join(remoteAddrList)
}
func (c *controller) agentDriverNotify(d driverapi.Driver) {
func (c *Controller) agentDriverNotify(d driverapi.Driver) {
agent := c.getAgent()
if agent == nil {
return
@ -380,7 +380,7 @@ func (c *controller) agentDriverNotify(d driverapi.Driver) {
}
}
func (c *controller) agentClose() {
func (c *Controller) agentClose() {
// Acquire current agent instance and reset its pointer
// then run closing functions
c.mu.Lock()
@ -827,7 +827,7 @@ func (n *network) cancelDriverWatches() {
}
}
func (c *controller) handleTableEvents(ch *events.Channel, fn func(events.Event)) {
func (c *Controller) handleTableEvents(ch *events.Channel, fn func(events.Event)) {
for {
select {
case ev := <-ch.C:
@ -873,7 +873,7 @@ func (n *network) handleDriverTableEvent(ev events.Event) {
d.EventNotify(etype, n.ID(), tname, key, value)
}
func (c *controller) handleNodeTableEvent(ev events.Event) {
func (c *Controller) handleNodeTableEvent(ev events.Event) {
var (
value []byte
isAdd bool
@ -897,7 +897,7 @@ func (c *controller) handleNodeTableEvent(ev events.Event) {
c.processNodeDiscovery([]net.IP{nodeAddr.Addr}, isAdd)
}
func (c *controller) handleEpTableEvent(ev events.Event) {
func (c *Controller) handleEpTableEvent(ev events.Event) {
var (
nid string
eid string

View file

@ -72,77 +72,6 @@ import (
"github.com/sirupsen/logrus"
)
// NetworkController provides the interface for controller instance which manages
// networks.
type NetworkController interface {
// ID provides a unique identity for the controller
ID() string
// BuiltinDrivers returns list of builtin drivers
BuiltinDrivers() []string
// BuiltinIPAMDrivers returns list of builtin ipam drivers
BuiltinIPAMDrivers() []string
// Config method returns the bootup configuration for the controller
Config() config.Config
// Create a new network. The options parameter carries network specific options.
NewNetwork(networkType, name string, id string, options ...NetworkOption) (Network, error)
// Networks returns the list of Network(s) managed by this controller.
Networks() []Network
// WalkNetworks uses the provided function to walk the Network(s) managed by this controller.
WalkNetworks(walker NetworkWalker)
// NetworkByName returns the Network which has the passed name. If not found, the error ErrNoSuchNetwork is returned.
NetworkByName(name string) (Network, error)
// NetworkByID returns the Network which has the passed id. If not found, the error ErrNoSuchNetwork is returned.
NetworkByID(id string) (Network, error)
// NewSandbox creates a new network sandbox for the passed container id
NewSandbox(containerID string, options ...SandboxOption) (Sandbox, error)
// Sandboxes returns the list of Sandbox(s) managed by this controller.
Sandboxes() []Sandbox
// WalkSandboxes uses the provided function to walk the Sandbox(s) managed by this controller.
WalkSandboxes(walker SandboxWalker)
// SandboxByID returns the Sandbox which has the passed id. If not found, a types.NotFoundError is returned.
SandboxByID(id string) (Sandbox, error)
// SandboxDestroy destroys a sandbox given a container ID
SandboxDestroy(id string) error
// Stop network controller
Stop()
// ReloadConfiguration updates the controller configuration
ReloadConfiguration(cfgOptions ...config.Option) error
// SetClusterProvider sets cluster provider
SetClusterProvider(provider cluster.Provider)
// Wait for agent initialization complete in libnetwork controller
AgentInitWait()
// Wait for agent to stop if running
AgentStopWait()
// SetKeys configures the encryption key for gossip and overlay data path
SetKeys(keys []*types.EncryptionKey) error
// StartDiagnostic start the network diagnostic mode
StartDiagnostic(port int)
// StopDiagnostic start the network diagnostic mode
StopDiagnostic()
// IsDiagnosticEnabled returns true if the diagnostic is enabled
IsDiagnosticEnabled() bool
}
// NetworkWalker is a client provided function which will be used to walk the Networks.
// When the function returns true, the walk will stop.
type NetworkWalker func(nw Network) bool
@ -153,7 +82,8 @@ type SandboxWalker func(sb Sandbox) bool
type sandboxTable map[string]*sandbox
type controller struct {
// Controller manages networks.
type Controller struct {
id string
drvRegistry *drvregistry.DrvRegistry
sandboxes sandboxTable
@ -183,8 +113,8 @@ type initializer struct {
}
// New creates a new instance of network controller.
func New(cfgOptions ...config.Option) (NetworkController, error) {
c := &controller{
func New(cfgOptions ...config.Option) (*Controller, error) {
c := &Controller{
id: stringid.GenerateRandomID(),
cfg: config.New(cfgOptions...),
sandboxes: sandboxTable{},
@ -245,7 +175,8 @@ func New(cfgOptions ...config.Option) (NetworkController, error) {
return c, nil
}
func (c *controller) SetClusterProvider(provider cluster.Provider) {
// SetClusterProvider sets the cluster provider.
func (c *Controller) SetClusterProvider(provider cluster.Provider) {
var sameProvider bool
c.mu.Lock()
// Avoids to spawn multiple goroutine for the same cluster provider
@ -266,9 +197,10 @@ func (c *controller) SetClusterProvider(provider cluster.Provider) {
go c.clusterAgentInit()
}
// libnetwork side of agent depends on the keys. On the first receipt of
// keys setup the agent. For subsequent key set handle the key change
func (c *controller) SetKeys(keys []*types.EncryptionKey) error {
// SetKeys configures the encryption key for gossip and overlay data path.
func (c *Controller) SetKeys(keys []*types.EncryptionKey) error {
// libnetwork side of agent depends on the keys. On the first receipt of
// keys setup the agent. For subsequent key set handle the key change
subsysKeys := make(map[string]int)
for _, key := range keys {
if key.Subsystem != subsysGossip &&
@ -292,13 +224,13 @@ func (c *controller) SetKeys(keys []*types.EncryptionKey) error {
return c.handleKeyChange(keys)
}
func (c *controller) getAgent() *agent {
func (c *Controller) getAgent() *agent {
c.mu.Lock()
defer c.mu.Unlock()
return c.agent
}
func (c *controller) clusterAgentInit() {
func (c *Controller) clusterAgentInit() {
clusterProvider := c.cfg.ClusterProvider
var keysAvailable bool
for {
@ -347,7 +279,7 @@ func (c *controller) clusterAgentInit() {
}
// AgentInitWait waits for agent initialization to be completed in the controller.
func (c *controller) AgentInitWait() {
func (c *Controller) AgentInitWait() {
c.mu.Lock()
agentInitDone := c.agentInitDone
c.mu.Unlock()
@ -357,8 +289,8 @@ func (c *controller) AgentInitWait() {
}
}
// AgentStopWait waits for the Agent stop to be completed in the controller
func (c *controller) AgentStopWait() {
// AgentStopWait waits for the Agent stop to be completed in the controller.
func (c *Controller) AgentStopWait() {
c.mu.Lock()
agentStopDone := c.agentStopDone
c.mu.Unlock()
@ -368,7 +300,7 @@ func (c *controller) AgentStopWait() {
}
// agentOperationStart marks the start of an Agent Init or Agent Stop
func (c *controller) agentOperationStart() {
func (c *Controller) agentOperationStart() {
c.mu.Lock()
if c.agentInitDone == nil {
c.agentInitDone = make(chan struct{})
@ -380,7 +312,7 @@ func (c *controller) agentOperationStart() {
}
// agentInitComplete notifies the successful completion of the Agent initialization
func (c *controller) agentInitComplete() {
func (c *Controller) agentInitComplete() {
c.mu.Lock()
if c.agentInitDone != nil {
close(c.agentInitDone)
@ -390,7 +322,7 @@ func (c *controller) agentInitComplete() {
}
// agentStopComplete notifies the successful completion of the Agent stop
func (c *controller) agentStopComplete() {
func (c *Controller) agentStopComplete() {
c.mu.Lock()
if c.agentStopDone != nil {
close(c.agentStopDone)
@ -399,7 +331,7 @@ func (c *controller) agentStopComplete() {
c.mu.Unlock()
}
func (c *controller) makeDriverConfig(ntype string) map[string]interface{} {
func (c *Controller) makeDriverConfig(ntype string) map[string]interface{} {
if c.cfg == nil {
return nil
}
@ -438,7 +370,8 @@ func (c *controller) makeDriverConfig(ntype string) map[string]interface{} {
var procReloadConfig = make(chan (bool), 1)
func (c *controller) ReloadConfiguration(cfgOptions ...config.Option) error {
// ReloadConfiguration updates the controller configuration.
func (c *Controller) ReloadConfiguration(cfgOptions ...config.Option) error {
procReloadConfig <- true
defer func() { <-procReloadConfig }()
@ -508,11 +441,13 @@ func (c *controller) ReloadConfiguration(cfgOptions ...config.Option) error {
return nil
}
func (c *controller) ID() string {
// ID returns the controller's unique identity.
func (c *Controller) ID() string {
return c.id
}
func (c *controller) BuiltinDrivers() []string {
// BuiltinDrivers returns the list of builtin network drivers.
func (c *Controller) BuiltinDrivers() []string {
drivers := []string{}
c.drvRegistry.WalkDrivers(func(name string, driver driverapi.Driver, capability driverapi.Capability) bool {
if driver.IsBuiltIn() {
@ -523,7 +458,8 @@ func (c *controller) BuiltinDrivers() []string {
return drivers
}
func (c *controller) BuiltinIPAMDrivers() []string {
// BuiltinIPAMDrivers returns the list of builtin ipam drivers.
func (c *Controller) BuiltinIPAMDrivers() []string {
drivers := []string{}
c.drvRegistry.WalkIPAMs(func(name string, driver ipamapi.Ipam, cap *ipamapi.Capability) bool {
if driver.IsBuiltIn() {
@ -534,14 +470,14 @@ func (c *controller) BuiltinIPAMDrivers() []string {
return drivers
}
func (c *controller) processNodeDiscovery(nodes []net.IP, add bool) {
func (c *Controller) processNodeDiscovery(nodes []net.IP, add bool) {
c.drvRegistry.WalkDrivers(func(name string, driver driverapi.Driver, capability driverapi.Capability) bool {
c.pushNodeDiscovery(driver, capability, nodes, add)
return false
})
}
func (c *controller) pushNodeDiscovery(d driverapi.Driver, cap driverapi.Capability, nodes []net.IP, add bool) {
func (c *Controller) pushNodeDiscovery(d driverapi.Driver, cap driverapi.Capability, nodes []net.IP, add bool) {
var self net.IP
// try swarm-mode config
if agent := c.getAgent(); agent != nil {
@ -566,7 +502,8 @@ func (c *controller) pushNodeDiscovery(d driverapi.Driver, cap driverapi.Capabil
}
}
func (c *controller) Config() config.Config {
// Config returns the bootup configuration for the controller.
func (c *Controller) Config() config.Config {
c.mu.Lock()
defer c.mu.Unlock()
if c.cfg == nil {
@ -575,7 +512,7 @@ func (c *controller) Config() config.Config {
return *c.cfg
}
func (c *controller) isManager() bool {
func (c *Controller) isManager() bool {
c.mu.Lock()
defer c.mu.Unlock()
if c.cfg == nil || c.cfg.ClusterProvider == nil {
@ -584,7 +521,7 @@ func (c *controller) isManager() bool {
return c.cfg.ClusterProvider.IsManager()
}
func (c *controller) isAgent() bool {
func (c *Controller) isAgent() bool {
c.mu.Lock()
defer c.mu.Unlock()
if c.cfg == nil || c.cfg.ClusterProvider == nil {
@ -593,15 +530,15 @@ func (c *controller) isAgent() bool {
return c.cfg.ClusterProvider.IsAgent()
}
func (c *controller) isDistributedControl() bool {
func (c *Controller) isDistributedControl() bool {
return !c.isManager() && !c.isAgent()
}
func (c *controller) GetPluginGetter() plugingetter.PluginGetter {
func (c *Controller) GetPluginGetter() plugingetter.PluginGetter {
return c.drvRegistry.GetPluginGetter()
}
func (c *controller) RegisterDriver(networkType string, driver driverapi.Driver, capability driverapi.Capability) error {
func (c *Controller) RegisterDriver(networkType string, driver driverapi.Driver, capability driverapi.Capability) error {
c.agentDriverNotify(driver)
return nil
}
@ -611,7 +548,7 @@ const overlayDSROptionString = "dsr"
// NewNetwork creates a new network of the specified network type. The options
// are network specific and modeled in a generic way.
func (c *controller) NewNetwork(networkType, name string, id string, options ...NetworkOption) (Network, error) {
func (c *Controller) NewNetwork(networkType, name string, id string, options ...NetworkOption) (Network, error) {
var (
caps *driverapi.Capability
err error
@ -832,7 +769,7 @@ var joinCluster NetworkWalker = func(nw Network) bool {
return false
}
func (c *controller) reservePools() {
func (c *Controller) reservePools() {
networks, err := c.getNetworksForScope(datastore.LocalScope)
if err != nil {
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 {
return caps.RequiresRequestReplay
}
func (c *controller) addNetwork(n *network) error {
func (c *Controller) addNetwork(n *network) error {
d, err := n.driver(true)
if err != nil {
return err
@ -921,7 +858,8 @@ func (c *controller) addNetwork(n *network) error {
return nil
}
func (c *controller) Networks() []Network {
// Networks returns the list of Network(s) managed by this controller.
func (c *Controller) Networks() []Network {
var list []Network
for _, n := range c.getNetworksFromStore() {
@ -934,7 +872,8 @@ func (c *controller) Networks() []Network {
return list
}
func (c *controller) WalkNetworks(walker NetworkWalker) {
// WalkNetworks uses the provided function to walk the Network(s) managed by this controller.
func (c *Controller) WalkNetworks(walker NetworkWalker) {
for _, n := range c.Networks() {
if walker(n) {
return
@ -942,7 +881,9 @@ func (c *controller) WalkNetworks(walker NetworkWalker) {
}
}
func (c *controller) NetworkByName(name string) (Network, error) {
// NetworkByName returns the Network which has the passed name.
// If not found, the error [ErrNoSuchNetwork] is returned.
func (c *Controller) NetworkByName(name string) (Network, error) {
if name == "" {
return nil, ErrInvalidName(name)
}
@ -965,7 +906,9 @@ func (c *controller) NetworkByName(name string) (Network, error) {
return n, nil
}
func (c *controller) NetworkByID(id string) (Network, error) {
// NetworkByID returns the Network which has the passed id.
// If not found, the error [ErrNoSuchNetwork] is returned.
func (c *Controller) NetworkByID(id string) (Network, error) {
if id == "" {
return nil, ErrInvalidID(id)
}
@ -978,8 +921,8 @@ func (c *controller) NetworkByID(id string) (Network, error) {
return n, nil
}
// NewSandbox creates a new sandbox for the passed container id
func (c *controller) NewSandbox(containerID string, options ...SandboxOption) (Sandbox, error) {
// NewSandbox creates a new sandbox for containerID.
func (c *Controller) NewSandbox(containerID string, options ...SandboxOption) (Sandbox, error) {
if containerID == "" {
return nil, types.BadRequestErrorf("invalid container ID")
}
@ -1109,7 +1052,8 @@ func (c *controller) NewSandbox(containerID string, options ...SandboxOption) (S
return sb, nil
}
func (c *controller) Sandboxes() []Sandbox {
// Sandboxes returns the list of Sandbox(s) managed by this controller.
func (c *Controller) Sandboxes() []Sandbox {
c.mu.Lock()
defer c.mu.Unlock()
@ -1126,7 +1070,8 @@ func (c *controller) Sandboxes() []Sandbox {
return list
}
func (c *controller) WalkSandboxes(walker SandboxWalker) {
// WalkSandboxes uses the provided function to walk the Sandbox(s) managed by this controller.
func (c *Controller) WalkSandboxes(walker SandboxWalker) {
for _, sb := range c.Sandboxes() {
if walker(sb) {
return
@ -1134,7 +1079,9 @@ func (c *controller) WalkSandboxes(walker SandboxWalker) {
}
}
func (c *controller) SandboxByID(id string) (Sandbox, error) {
// SandboxByID returns the Sandbox which has the passed id.
// If not found, a [types.NotFoundError] is returned.
func (c *Controller) SandboxByID(id string) (Sandbox, error) {
if id == "" {
return nil, ErrInvalidID(id)
}
@ -1147,8 +1094,8 @@ func (c *controller) SandboxByID(id string) (Sandbox, error) {
return s, nil
}
// SandboxDestroy destroys a sandbox given a container ID
func (c *controller) SandboxDestroy(id string) error {
// SandboxDestroy destroys a sandbox given a container ID.
func (c *Controller) SandboxDestroy(id string) error {
var sb *sandbox
c.mu.Lock()
for _, s := range c.sandboxes {
@ -1189,7 +1136,7 @@ func SandboxKeyWalker(out *Sandbox, key string) SandboxWalker {
}
}
func (c *controller) loadDriver(networkType string) error {
func (c *Controller) loadDriver(networkType string) error {
var err error
if pg := c.GetPluginGetter(); pg != nil {
@ -1208,7 +1155,7 @@ func (c *controller) loadDriver(networkType string) error {
return nil
}
func (c *controller) loadIPAMDriver(name string) error {
func (c *Controller) loadIPAMDriver(name string) error {
var err error
if pg := c.GetPluginGetter(); pg != nil {
@ -1227,7 +1174,7 @@ func (c *controller) loadIPAMDriver(name string) error {
return nil
}
func (c *controller) getIPAMDriver(name string) (ipamapi.Ipam, *ipamapi.Capability, error) {
func (c *Controller) getIPAMDriver(name string) (ipamapi.Ipam, *ipamapi.Capability, error) {
id, cap := c.drvRegistry.IPAM(name)
if id == nil {
// Might be a plugin name. Try loading it
@ -1245,14 +1192,15 @@ func (c *controller) getIPAMDriver(name string) (ipamapi.Ipam, *ipamapi.Capabili
return id, cap, nil
}
func (c *controller) Stop() {
// Stop stops the network controller.
func (c *Controller) Stop() {
c.closeStores()
c.stopExternalKeyListener()
osl.GC()
}
// StartDiagnostic start the network dias mode
func (c *controller) StartDiagnostic(port int) {
// StartDiagnostic starts the network diagnostic server listening on port.
func (c *Controller) StartDiagnostic(port int) {
c.mu.Lock()
if !c.DiagnosticServer.IsDiagnosticEnabled() {
c.DiagnosticServer.EnableDiagnostic("127.0.0.1", port)
@ -1260,8 +1208,8 @@ func (c *controller) StartDiagnostic(port int) {
c.mu.Unlock()
}
// StopDiagnostic start the network dias mode
func (c *controller) StopDiagnostic() {
// StopDiagnostic stops the network diagnostic server.
func (c *Controller) StopDiagnostic() {
c.mu.Lock()
if c.DiagnosticServer.IsDiagnosticEnabled() {
c.DiagnosticServer.DisableDiagnostic()
@ -1269,14 +1217,14 @@ func (c *controller) StopDiagnostic() {
c.mu.Unlock()
}
// IsDiagnosticEnabled returns true if the dias is enabled
func (c *controller) IsDiagnosticEnabled() bool {
// IsDiagnosticEnabled returns true if the diagnostic server is running.
func (c *Controller) IsDiagnosticEnabled() bool {
c.mu.Lock()
defer c.mu.Unlock()
return c.DiagnosticServer.IsDiagnosticEnabled()
}
func (c *controller) iptablesEnabled() bool {
func (c *Controller) iptablesEnabled() bool {
c.mu.Lock()
defer c.mu.Unlock()

View file

@ -163,7 +163,7 @@ func (ep *endpoint) endpointInGWNetwork() bool {
// Looks for the default gw network and creates it if not there.
// Parallel executions are serialized.
func (c *controller) defaultGwNetwork() (Network, error) {
func (c *Controller) defaultGwNetwork() (Network, error) {
procGwNetwork <- true
defer func() { <-procGwNetwork }()

View file

@ -8,6 +8,6 @@ func getPlatformOption() EndpointOption {
return nil
}
func (c *controller) createGWNetwork() (Network, error) {
func (c *Controller) createGWNetwork() (Network, error) {
return nil, types.NotImplementedErrorf("default gateway functionality is not implemented in freebsd")
}

View file

@ -13,7 +13,7 @@ func getPlatformOption() EndpointOption {
return nil
}
func (c *controller) createGWNetwork() (Network, error) {
func (c *Controller) createGWNetwork() (Network, error) {
netOption := map[string]string{
bridge.BridgeName: libnGWNetwork,
bridge.EnableICC: strconv.FormatBool(false),

View file

@ -17,6 +17,6 @@ func getPlatformOption() EndpointOption {
return EndpointOptionGeneric(epOption)
}
func (c *controller) createGWNetwork() (Network, error) {
func (c *Controller) createGWNetwork() (Network, error) {
return nil, types.NotImplementedErrorf("default gateway functionality is not implemented in windows")
}

View file

@ -1173,7 +1173,7 @@ func (ep *endpoint) releaseAddress() {
}
}
func (c *controller) cleanupLocalEndpoints() {
func (c *Controller) cleanupLocalEndpoints() {
// Get used endpoints
eps := make(map[string]interface{})
for _, sb := range c.sandboxes {

View file

@ -30,8 +30,7 @@ fe90::2 somehost.example.com somehost
[]*IpamConf{{PreferredPool: "fe90::/64", Gateway: "fe90::1"}},
nil)}
c, nws := getTestEnv(t, opts)
ctrlr := c.(*controller)
ctrlr, nws := getTestEnv(t, opts)
hostsFile, err := os.CreateTemp("", "")
if err != nil {

View file

@ -7,9 +7,9 @@ import (
const userChain = "DOCKER-USER"
var ctrl *controller
var ctrl *Controller
func setupArrangeUserFilterRule(c *controller) {
func setupArrangeUserFilterRule(c *Controller) {
ctrl = c
iptables.OnReloaded(arrangeUserFilterRule)
}

View file

@ -51,10 +51,9 @@ func TestUserChain(t *testing.T) {
defer testutils.SetupTestOSContext(t)()
defer resetIptables(t)
nc, err := New()
c, err := New()
assert.NilError(t, err)
defer nc.Stop()
c := nc.(*controller)
defer c.Stop()
c.cfg.DriverCfg["bridge"] = map[string]interface{}{
netlabel.GenericData: options.Generic{
"EnableIPTables": tc.iptables,

View file

@ -3,5 +3,5 @@
package libnetwork
func setupArrangeUserFilterRule(c *controller) {}
func setupArrangeUserFilterRule(c *Controller) {}
func arrangeUserFilterRule() {}

View file

@ -320,7 +320,7 @@ func TestAuxAddresses(t *testing.T) {
}
defer c.Stop()
n := &network{ipamType: ipamapi.DefaultIPAM, networkType: "bridge", ctrlr: c.(*controller)}
n := &network{ipamType: ipamapi.DefaultIPAM, networkType: "bridge", ctrlr: c}
input := []struct {
masterPool string
@ -421,7 +421,7 @@ func TestSRVServiceQuery(t *testing.T) {
sr.service["web.swarm"] = append(sr.service["web.swarm"], httpPort)
sr.service["web.swarm"] = append(sr.service["web.swarm"], extHTTPPort)
c.(*controller).svcRecords[n.ID()] = sr
c.svcRecords[n.ID()] = sr
_, ip := ep.Info().Sandbox().ResolveService("_http._tcp.web.swarm")
@ -576,9 +576,7 @@ func TestIpamReleaseOnNetDriverFailures(t *testing.T) {
}
defer c.Stop()
cc := c.(*controller)
if err := cc.drvRegistry.AddDriver(badDriverName, badDriverInit, nil); err != nil {
if err := c.drvRegistry.AddDriver(badDriverName, badDriverInit, nil); err != nil {
t.Fatal(err)
}

View file

@ -30,7 +30,7 @@ const (
bridgeNetType = "bridge"
)
func makeTesthostNetwork(t *testing.T, c libnetwork.NetworkController) libnetwork.Network {
func makeTesthostNetwork(t *testing.T, c *libnetwork.Controller) libnetwork.Network {
t.Helper()
n, err := createTestNetwork(c, "host", "testhost", options.Generic{}, nil, nil)
if err != nil {
@ -845,7 +845,7 @@ func TestResolvConf(t *testing.T) {
type parallelTester struct {
osctx *testutils.OSContext
controller libnetwork.NetworkController
controller *libnetwork.Controller
net1, net2 libnetwork.Network
iterCnt int
}

View file

@ -43,7 +43,7 @@ func TestMain(m *testing.M) {
os.Exit(m.Run())
}
func newController(t *testing.T) libnetwork.NetworkController {
func newController(t *testing.T) *libnetwork.Controller {
t.Helper()
genericOption := map[string]interface{}{
netlabel.GenericData: options.Generic{
@ -62,7 +62,7 @@ func newController(t *testing.T) libnetwork.NetworkController {
return c
}
func createTestNetwork(c libnetwork.NetworkController, networkType, networkName string, netOption options.Generic, ipamV4Configs, ipamV6Configs []*libnetwork.IpamConf) (libnetwork.Network, error) {
func createTestNetwork(c *libnetwork.Controller, networkType, networkName string, netOption options.Generic, ipamV4Configs, ipamV6Configs []*libnetwork.IpamConf) (libnetwork.Network, error) {
return c.NewNetwork(networkType, networkName, "",
libnetwork.NetworkOptionGeneric(netOption),
libnetwork.NetworkOptionIpam(ipamapi.DefaultIPAM, "", ipamV4Configs, ipamV6Configs, nil))

View file

@ -200,7 +200,7 @@ func (i *IpamInfo) UnmarshalJSON(data []byte) error {
}
type network struct {
ctrlr *controller
ctrlr *Controller
name string
networkType string
id string
@ -1517,7 +1517,7 @@ func (n *network) getSvcRecords(ep *endpoint) []etchosts.Record {
return recs
}
func (n *network) getController() *controller {
func (n *network) getController() *Controller {
n.Lock()
defer n.Unlock()
return n.ctrlr
@ -2139,7 +2139,7 @@ func (n *network) NdotsSet() bool {
}
// config-only network is looked up by name
func (c *controller) getConfigNetwork(name string) (*network, error) {
func (c *Controller) getConfigNetwork(name string) (*network, error) {
var n Network
s := func(current Network) bool {

View file

@ -69,7 +69,7 @@ type sandbox struct {
config containerConfig
extDNS []extDNSEntry
osSbox osl.Sandbox
controller *controller
controller *Controller
resolver Resolver
resolverOnce sync.Once
endpoints []*endpoint

View file

@ -112,7 +112,7 @@ func processReturn(r io.Reader) error {
return nil
}
func (c *controller) startExternalKeyListener() error {
func (c *Controller) startExternalKeyListener() error {
execRoot := defaultExecRoot
if v := c.Config().ExecRoot; v != "" {
execRoot = v
@ -139,7 +139,7 @@ func (c *controller) startExternalKeyListener() error {
return nil
}
func (c *controller) acceptClientConnections(sock string, l net.Listener) {
func (c *Controller) acceptClientConnections(sock string, l net.Listener) {
for {
conn, err := l.Accept()
if err != nil {
@ -167,7 +167,7 @@ func (c *controller) acceptClientConnections(sock string, l net.Listener) {
}
}
func (c *controller) processExternalKey(conn net.Conn) error {
func (c *Controller) processExternalKey(conn net.Conn) error {
buf := make([]byte, 1280)
nr, err := conn.Read(buf)
if err != nil {
@ -188,6 +188,6 @@ func (c *controller) processExternalKey(conn net.Conn) error {
return sandbox.SetKey(s.Key)
}
func (c *controller) stopExternalKeyListener() {
func (c *Controller) stopExternalKeyListener() {
c.extKeyListener.Close()
}

View file

@ -31,16 +31,16 @@ func processReturn(r io.Reader) error {
}
// no-op on non linux systems
func (c *controller) startExternalKeyListener() error {
func (c *Controller) startExternalKeyListener() error {
return nil
}
func (c *controller) acceptClientConnections(sock string, l net.Listener) {
func (c *Controller) acceptClientConnections(sock string, l net.Listener) {
}
func (c *controller) processExternalKey(conn net.Conn) error {
func (c *Controller) processExternalKey(conn net.Conn) error {
return types.NotImplementedErrorf("processExternalKey isn't supported on non linux systems")
}
func (c *controller) stopExternalKeyListener() {
func (c *Controller) stopExternalKeyListener() {
}

View file

@ -21,7 +21,7 @@ type epState struct {
type sbState struct {
ID string
Cid string
c *controller
c *Controller
dbIndex uint64
dbExists bool
Eps []epState
@ -189,7 +189,7 @@ func (sb *sandbox) storeDelete() error {
return sb.controller.deleteFromStore(sbs)
}
func (c *controller) sandboxCleanup(activeSandboxes map[string]interface{}) {
func (c *Controller) sandboxCleanup(activeSandboxes map[string]interface{}) {
store := c.getStore(datastore.LocalScope)
if store == nil {
logrus.Error("Could not find local scope store while trying to cleanup sandboxes")

View file

@ -14,7 +14,7 @@ import (
"gotest.tools/v3/skip"
)
func getTestEnv(t *testing.T, opts ...[]NetworkOption) (NetworkController, []Network) {
func getTestEnv(t *testing.T, opts ...[]NetworkOption) (*Controller, []Network) {
skip.If(t, runtime.GOOS == "windows", "test only works on linux")
netType := "bridge"
@ -61,8 +61,7 @@ func getTestEnv(t *testing.T, opts ...[]NetworkOption) (NetworkController, []Net
}
func TestSandboxAddEmpty(t *testing.T) {
c, _ := getTestEnv(t)
ctrlr := c.(*controller)
ctrlr, _ := getTestEnv(t)
sbx, err := ctrlr.NewSandbox("sandbox0")
if err != nil {
@ -90,8 +89,7 @@ func TestSandboxAddMultiPrio(t *testing.T) {
{},
}
c, nws := getTestEnv(t, opts...)
ctrlr := c.(*controller)
ctrlr, nws := getTestEnv(t, opts...)
sbx, err := ctrlr.NewSandbox("sandbox1")
if err != nil {
@ -176,9 +174,7 @@ func TestSandboxAddSamePrio(t *testing.T) {
{NetworkOptionInternalNetwork()},
}
c, nws := getTestEnv(t, opts...)
ctrlr := c.(*controller)
ctrlr, nws := getTestEnv(t, opts...)
sbx, err := ctrlr.NewSandbox("sandbox1")
if err != nil {

View file

@ -12,7 +12,7 @@ import (
const maxSetStringLen = 350
func (c *controller) addEndpointNameResolution(svcName, svcID, nID, eID, containerName string, vip net.IP, serviceAliases, taskAliases []string, ip net.IP, addService bool, method string) error {
func (c *Controller) addEndpointNameResolution(svcName, svcID, nID, eID, containerName string, vip net.IP, serviceAliases, taskAliases []string, ip net.IP, addService bool, method string) error {
n, err := c.NetworkByID(nID)
if err != nil {
return err
@ -55,7 +55,7 @@ func (c *controller) addEndpointNameResolution(svcName, svcID, nID, eID, contain
return nil
}
func (c *controller) addContainerNameResolution(nID, eID, containerName string, taskAliases []string, ip net.IP, method string) error {
func (c *Controller) addContainerNameResolution(nID, eID, containerName string, taskAliases []string, ip net.IP, method string) error {
n, err := c.NetworkByID(nID)
if err != nil {
return err
@ -73,7 +73,7 @@ func (c *controller) addContainerNameResolution(nID, eID, containerName string,
return nil
}
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 {
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 {
n, err := c.NetworkByID(nID)
if err != nil {
return err
@ -119,7 +119,7 @@ func (c *controller) deleteEndpointNameResolution(svcName, svcID, nID, eID, cont
return nil
}
func (c *controller) delContainerNameResolution(nID, eID, containerName string, taskAliases []string, ip net.IP, method string) error {
func (c *Controller) delContainerNameResolution(nID, eID, containerName string, taskAliases []string, ip net.IP, method string) error {
n, err := c.NetworkByID(nID)
if err != nil {
return err
@ -148,7 +148,7 @@ func newService(name string, id string, ingressPorts []*PortConfig, serviceAlias
}
}
func (c *controller) getLBIndex(sid, nid string, ingressPorts []*PortConfig) int {
func (c *Controller) getLBIndex(sid, nid string, ingressPorts []*PortConfig) int {
skey := serviceKey{
id: sid,
ports: portConfigs(ingressPorts).String(),
@ -169,7 +169,7 @@ func (c *controller) getLBIndex(sid, nid string, ingressPorts []*PortConfig) int
}
// cleanupServiceDiscovery when the network is being deleted, erase all the associated service discovery records
func (c *controller) cleanupServiceDiscovery(cleanupNID string) {
func (c *Controller) cleanupServiceDiscovery(cleanupNID string) {
c.mu.Lock()
defer c.mu.Unlock()
if cleanupNID == "" {
@ -181,7 +181,7 @@ func (c *controller) cleanupServiceDiscovery(cleanupNID string) {
delete(c.svcRecords, cleanupNID)
}
func (c *controller) cleanupServiceBindings(cleanupNID string) {
func (c *Controller) cleanupServiceBindings(cleanupNID string) {
var cleanupFuncs []func()
logrus.Debugf("cleanupServiceBindings for %s", cleanupNID)
@ -215,7 +215,7 @@ func (c *controller) cleanupServiceBindings(cleanupNID string) {
}
}
func makeServiceCleanupFunc(c *controller, s *service, nID, eID string, vip net.IP, ip net.IP) func() {
func makeServiceCleanupFunc(c *Controller, s *service, nID, eID string, vip net.IP, ip net.IP) func() {
// ContainerName and taskAliases are not available here, this is still fine because the Service discovery
// cleanup already happened before. The only thing that rmServiceBinding is still doing here a part from the Load
// 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.
}
}
func (c *controller) addServiceBinding(svcName, svcID, nID, eID, containerName string, vip net.IP, ingressPorts []*PortConfig, serviceAliases, taskAliases []string, ip net.IP, method string) error {
func (c *Controller) addServiceBinding(svcName, svcID, nID, eID, containerName string, vip net.IP, ingressPorts []*PortConfig, serviceAliases, taskAliases []string, ip net.IP, method string) error {
var addService bool
// 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
return nil
}
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 {
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 {
var rmService bool
skey := serviceKey{

View file

@ -39,21 +39,21 @@ func TestCleanupServiceDiscovery(t *testing.T) {
n2.(*network).addSvcRecords("N2ep1", "service_test", "serviceID1", net.ParseIP("192.168.1.1"), net.IP{}, true, "test")
n2.(*network).addSvcRecords("N2ep2", "service_test", "serviceID2", net.ParseIP("192.168.1.2"), net.IP{}, true, "test")
if len(c.(*controller).svcRecords) != 2 {
t.Fatalf("Service record not added correctly:%v", c.(*controller).svcRecords)
if len(c.svcRecords) != 2 {
t.Fatalf("Service record not added correctly:%v", c.svcRecords)
}
// cleanup net1
c.(*controller).cleanupServiceDiscovery(n1.ID())
c.cleanupServiceDiscovery(n1.ID())
if len(c.(*controller).svcRecords) != 1 {
t.Fatalf("Service record not cleaned correctly:%v", c.(*controller).svcRecords)
if len(c.svcRecords) != 1 {
t.Fatalf("Service record not cleaned correctly:%v", c.svcRecords)
}
c.(*controller).cleanupServiceDiscovery("")
c.cleanupServiceDiscovery("")
if len(c.(*controller).svcRecords) != 0 {
t.Fatalf("Service record not cleaned correctly:%v", c.(*controller).svcRecords)
if len(c.svcRecords) != 0 {
t.Fatalf("Service record not cleaned correctly:%v", c.svcRecords)
}
}
@ -63,7 +63,7 @@ func TestDNSOptions(t *testing.T) {
c, err := New()
assert.NilError(t, err)
sb, err := c.(*controller).NewSandbox("cnt1", nil)
sb, err := c.NewSandbox("cnt1", nil)
assert.NilError(t, err)
cleanup := func(s Sandbox) {
@ -102,7 +102,7 @@ func TestDNSOptions(t *testing.T) {
assert.Check(t, is.Len(dnsOptionsList, 1))
assert.Check(t, is.Equal("ndots:5", dnsOptionsList[0]))
sb2, err := c.(*controller).NewSandbox("cnt2", nil)
sb2, err := c.NewSandbox("cnt2", nil)
assert.NilError(t, err)
defer cleanup(sb2)
sb2.(*sandbox).startResolver(false)

View file

@ -8,14 +8,14 @@ import (
"net"
)
func (c *controller) cleanupServiceBindings(nid string) {
func (c *Controller) cleanupServiceBindings(nid string) {
}
func (c *controller) addServiceBinding(name, sid, nid, eid string, vip net.IP, ingressPorts []*PortConfig, aliases []string, ip net.IP) error {
func (c *Controller) addServiceBinding(name, sid, nid, eid string, vip net.IP, ingressPorts []*PortConfig, aliases []string, ip net.IP) error {
return fmt.Errorf("not supported")
}
func (c *controller) rmServiceBinding(name, sid, nid, eid string, vip net.IP, ingressPorts []*PortConfig, aliases []string, ip net.IP) error {
func (c *Controller) rmServiceBinding(name, sid, nid, eid string, vip net.IP, ingressPorts []*PortConfig, aliases []string, ip net.IP) error {
return fmt.Errorf("not supported")
}

View file

@ -13,7 +13,7 @@ func registerKVStores() {
boltdb.Register()
}
func (c *controller) initScopedStore(scope string, scfg *datastore.ScopeCfg) error {
func (c *Controller) initScopedStore(scope string, scfg *datastore.ScopeCfg) error {
store, err := datastore.NewDataStore(scope, scfg)
if err != nil {
return err
@ -25,7 +25,7 @@ func (c *controller) initScopedStore(scope string, scfg *datastore.ScopeCfg) err
return nil
}
func (c *controller) initStores() error {
func (c *Controller) initStores() error {
registerKVStores()
c.mu.Lock()
@ -47,13 +47,13 @@ func (c *controller) initStores() error {
return nil
}
func (c *controller) closeStores() {
func (c *Controller) closeStores() {
for _, store := range c.getStores() {
store.Close()
}
}
func (c *controller) getStore(scope string) datastore.DataStore {
func (c *Controller) getStore(scope string) datastore.DataStore {
c.mu.Lock()
defer c.mu.Unlock()
@ -66,14 +66,14 @@ func (c *controller) getStore(scope string) datastore.DataStore {
return nil
}
func (c *controller) getStores() []datastore.DataStore {
func (c *Controller) getStores() []datastore.DataStore {
c.mu.Lock()
defer c.mu.Unlock()
return c.stores
}
func (c *controller) getNetworkFromStore(nid string) (*network, error) {
func (c *Controller) getNetworkFromStore(nid string) (*network, error) {
for _, n := range c.getNetworksFromStore() {
if n.id == nid {
return n, nil
@ -82,7 +82,7 @@ func (c *controller) getNetworkFromStore(nid string) (*network, error) {
return nil, ErrNoSuchNetwork(nid)
}
func (c *controller) getNetworksForScope(scope string) ([]*network, error) {
func (c *Controller) getNetworksForScope(scope string) ([]*network, error) {
var nl []*network
store := c.getStore(scope)
@ -118,7 +118,7 @@ func (c *controller) getNetworksForScope(scope string) ([]*network, error) {
return nl, nil
}
func (c *controller) getNetworksFromStore() []*network {
func (c *Controller) getNetworksFromStore() []*network {
var nl []*network
for _, store := range c.getStores() {
@ -200,7 +200,7 @@ func (n *network) getEndpointsFromStore() ([]*endpoint, error) {
return epl, nil
}
func (c *controller) updateToStore(kvObject datastore.KVObject) error {
func (c *Controller) updateToStore(kvObject datastore.KVObject) error {
cs := c.getStore(kvObject.DataScope())
if cs == nil {
return ErrDataStoreNotInitialized(kvObject.DataScope())
@ -216,7 +216,7 @@ func (c *controller) updateToStore(kvObject datastore.KVObject) error {
return nil
}
func (c *controller) deleteFromStore(kvObject datastore.KVObject) error {
func (c *Controller) deleteFromStore(kvObject datastore.KVObject) error {
cs := c.getStore(kvObject.DataScope())
if cs == nil {
return ErrDataStoreNotInitialized(kvObject.DataScope())
@ -243,7 +243,7 @@ type netWatch struct {
stopCh chan struct{}
}
func (c *controller) getLocalEps(nw *netWatch) []*endpoint {
func (c *Controller) getLocalEps(nw *netWatch) []*endpoint {
c.mu.Lock()
defer c.mu.Unlock()
@ -255,15 +255,15 @@ func (c *controller) getLocalEps(nw *netWatch) []*endpoint {
return epl
}
func (c *controller) watchSvcRecord(ep *endpoint) {
func (c *Controller) watchSvcRecord(ep *endpoint) {
c.watchCh <- ep
}
func (c *controller) unWatchSvcRecord(ep *endpoint) {
func (c *Controller) unWatchSvcRecord(ep *endpoint) {
c.unWatchCh <- ep
}
func (c *controller) networkWatchLoop(nw *netWatch, ep *endpoint, ecCh <-chan datastore.KVObject) {
func (c *Controller) networkWatchLoop(nw *netWatch, ep *endpoint, ecCh <-chan datastore.KVObject) {
for {
select {
case <-nw.stopCh:
@ -327,7 +327,7 @@ func (c *controller) networkWatchLoop(nw *netWatch, ep *endpoint, ecCh <-chan da
}
}
func (c *controller) processEndpointCreate(nmap map[string]*netWatch, ep *endpoint) {
func (c *Controller) processEndpointCreate(nmap map[string]*netWatch, ep *endpoint) {
n := ep.getNetwork()
if !c.isDistributedControl() && n.Scope() == datastore.SwarmScope && n.driverIsMultihost() {
return
@ -389,7 +389,7 @@ func (c *controller) processEndpointCreate(nmap map[string]*netWatch, ep *endpoi
go c.networkWatchLoop(nw, ep, ch)
}
func (c *controller) processEndpointDelete(nmap map[string]*netWatch, ep *endpoint) {
func (c *Controller) processEndpointDelete(nmap map[string]*netWatch, ep *endpoint) {
n := ep.getNetwork()
if !c.isDistributedControl() && n.Scope() == datastore.SwarmScope && n.driverIsMultihost() {
return
@ -424,7 +424,7 @@ func (c *controller) processEndpointDelete(nmap map[string]*netWatch, ep *endpoi
c.mu.Unlock()
}
func (c *controller) watchLoop() {
func (c *Controller) watchLoop() {
for {
select {
case ep := <-c.watchCh:
@ -435,7 +435,7 @@ func (c *controller) watchLoop() {
}
}
func (c *controller) startWatch() {
func (c *Controller) startWatch() {
if c.watchCh != nil {
return
}
@ -446,7 +446,7 @@ func (c *controller) startWatch() {
go c.watchLoop()
}
func (c *controller) networkCleanup() {
func (c *Controller) networkCleanup() {
for _, n := range c.getNetworksFromStore() {
if n.inDelete {
logrus.Infof("Removing stale network %s (%s)", n.Name(), n.ID())

View file

@ -30,7 +30,7 @@ func TestNoPersist(t *testing.T) {
if err != nil {
t.Fatalf("Error creating endpoint: %v", err)
}
store := ctrl.(*controller).getStore(datastore.LocalScope).KVStore()
store := ctrl.getStore(datastore.LocalScope).KVStore()
if exists, _ := store.Exists(datastore.Key(datastore.NetworkKeyPrefix, nw.ID())); exists {
t.Fatalf("Network with persist=false should not be stored in KV Store")
}

View file

@ -36,7 +36,7 @@ func testLocalBackend(t *testing.T, provider, url string, storeConfig *store.Con
if err != nil {
t.Fatalf("Error creating endpoint: %v", err)
}
store := ctrl.(*controller).getStore(datastore.LocalScope).KVStore()
store := ctrl.getStore(datastore.LocalScope).KVStore()
if exists, err := store.Exists(datastore.Key(datastore.NetworkKeyPrefix, nw.ID())); !exists || err != nil {
t.Fatalf("Network key should have been created.")
}