From 627da8bf04de9006909f407405afc235493cbd2e Mon Sep 17 00:00:00 2001 From: Flavio Crisciani Date: Wed, 24 May 2017 11:28:23 -0700 Subject: [PATCH] Moved the cluster provider to Moby Moved the cluster provider interface definition from libnetwork to moby Signed-off-by: Flavio Crisciani --- libnetwork/agent.go | 4 ++-- libnetwork/cluster/provider.go | 36 ---------------------------------- libnetwork/cmd/dnet/dnet.go | 10 +++++----- libnetwork/config/config.go | 4 ++-- libnetwork/controller.go | 14 ++++++------- 5 files changed, 16 insertions(+), 52 deletions(-) delete mode 100644 libnetwork/cluster/provider.go diff --git a/libnetwork/agent.go b/libnetwork/agent.go index d67d446fe8..1ceb97e73a 100644 --- a/libnetwork/agent.go +++ b/libnetwork/agent.go @@ -11,9 +11,9 @@ import ( "sync" "github.com/Sirupsen/logrus" + "github.com/docker/docker/daemon/cluster/provider" "github.com/docker/docker/pkg/stringid" "github.com/docker/go-events" - "github.com/docker/libnetwork/cluster" "github.com/docker/libnetwork/datastore" "github.com/docker/libnetwork/discoverapi" "github.com/docker/libnetwork/driverapi" @@ -193,7 +193,7 @@ func (c *controller) handleKeyChange(keys []*types.EncryptionKey) error { return nil } -func (c *controller) agentSetup(clusterProvider cluster.Provider) error { +func (c *controller) agentSetup(clusterProvider provider.Cluster) error { agent := c.getAgent() // If the agent is already present there is no need to try to initilize it again diff --git a/libnetwork/cluster/provider.go b/libnetwork/cluster/provider.go deleted file mode 100644 index 491ccfd4b8..0000000000 --- a/libnetwork/cluster/provider.go +++ /dev/null @@ -1,36 +0,0 @@ -package cluster - -import ( - "github.com/docker/docker/api/types/network" - "golang.org/x/net/context" -) - -const ( - // EventSocketChange control socket changed - EventSocketChange = iota - // EventNodeReady cluster node in ready state - EventNodeReady - // EventNodeLeave node is leaving the cluster - EventNodeLeave - // EventNetworkKeysAvailable network keys correctly configured in the networking layer - EventNetworkKeysAvailable -) - -// ConfigEventType type of the event produced by the cluster -type ConfigEventType uint8 - -// Provider provides clustering config details -type Provider interface { - IsManager() bool - IsAgent() bool - GetLocalAddress() string - GetListenAddress() string - GetAdvertiseAddress() string - GetDataPathAddress() string - GetRemoteAddressList() []string - ListenClusterEvents() <-chan ConfigEventType - AttachNetwork(string, string, []string) (*network.NetworkingConfig, error) - DetachNetwork(string, string) error - UpdateAttachment(string, string, *network.NetworkingConfig) error - WaitForDetachment(context.Context, string, string, string, string) error -} diff --git a/libnetwork/cmd/dnet/dnet.go b/libnetwork/cmd/dnet/dnet.go index 0762de3349..354b479308 100644 --- a/libnetwork/cmd/dnet/dnet.go +++ b/libnetwork/cmd/dnet/dnet.go @@ -24,10 +24,10 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/docker/api/types/network" + "github.com/docker/docker/daemon/cluster/provider" "github.com/docker/docker/pkg/term" "github.com/docker/libnetwork" "github.com/docker/libnetwork/api" - "github.com/docker/libnetwork/cluster" "github.com/docker/libnetwork/config" "github.com/docker/libnetwork/datastore" "github.com/docker/libnetwork/driverapi" @@ -235,7 +235,7 @@ type dnetConnection struct { // addr holds the client address. addr string Orchestration *NetworkOrchestration - configEvent chan cluster.ConfigEventType + configEvent chan provider.ClusterConfigEventType } // NetworkOrchestration exported @@ -276,7 +276,7 @@ func (d *dnetConnection) dnetDaemon(cfgFile string) error { controller.SetClusterProvider(d) if d.Orchestration.Agent || d.Orchestration.Manager { - d.configEvent <- cluster.EventNodeReady + d.configEvent <- provider.ClusterEventNodeReady } createDefaultNetwork(controller) @@ -336,7 +336,7 @@ func (d *dnetConnection) GetNetworkKeys() []*types.EncryptionKey { func (d *dnetConnection) SetNetworkKeys([]*types.EncryptionKey) { } -func (d *dnetConnection) ListenClusterEvents() <-chan cluster.ConfigEventType { +func (d *dnetConnection) ListenClusterEvents() <-chan provider.ClusterConfigEventType { return d.configEvent } @@ -439,7 +439,7 @@ func newDnetConnection(val string) (*dnetConnection, error) { return nil, errors.New("dnet currently only supports tcp transport") } - return &dnetConnection{protoAddrParts[0], protoAddrParts[1], &NetworkOrchestration{}, make(chan cluster.ConfigEventType, 10)}, nil + return &dnetConnection{protoAddrParts[0], protoAddrParts[1], &NetworkOrchestration{}, make(chan provider.ClusterConfigEventType, 10)}, nil } func (d *dnetConnection) httpCall(method, path string, data interface{}, headers map[string][]string) (io.ReadCloser, http.Header, int, error) { diff --git a/libnetwork/config/config.go b/libnetwork/config/config.go index 3acb4320c4..fb4525bfba 100644 --- a/libnetwork/config/config.go +++ b/libnetwork/config/config.go @@ -5,11 +5,11 @@ import ( "github.com/BurntSushi/toml" "github.com/Sirupsen/logrus" + "github.com/docker/docker/daemon/cluster/provider" "github.com/docker/docker/pkg/discovery" "github.com/docker/docker/pkg/plugingetter" "github.com/docker/go-connections/tlsconfig" "github.com/docker/libkv/store" - "github.com/docker/libnetwork/cluster" "github.com/docker/libnetwork/datastore" "github.com/docker/libnetwork/netlabel" "github.com/docker/libnetwork/osl" @@ -33,7 +33,7 @@ type DaemonCfg struct { DefaultDriver string Labels []string DriverCfg map[string]interface{} - ClusterProvider cluster.Provider + ClusterProvider provider.Cluster } // ClusterCfg represents cluster configuration diff --git a/libnetwork/controller.go b/libnetwork/controller.go index df75be707f..d6773d84e1 100644 --- a/libnetwork/controller.go +++ b/libnetwork/controller.go @@ -53,12 +53,12 @@ import ( "time" "github.com/Sirupsen/logrus" + "github.com/docker/docker/daemon/cluster/provider" "github.com/docker/docker/pkg/discovery" "github.com/docker/docker/pkg/locker" "github.com/docker/docker/pkg/plugingetter" "github.com/docker/docker/pkg/plugins" "github.com/docker/docker/pkg/stringid" - "github.com/docker/libnetwork/cluster" "github.com/docker/libnetwork/config" "github.com/docker/libnetwork/datastore" "github.com/docker/libnetwork/discoverapi" @@ -123,7 +123,7 @@ type NetworkController interface { ReloadConfiguration(cfgOptions ...config.Option) error // SetClusterProvider sets cluster provider - SetClusterProvider(provider cluster.Provider) + SetClusterProvider(provider provider.Cluster) // Wait for agent initialization complete in libnetwork controller AgentInitWait() @@ -243,7 +243,7 @@ func New(cfgOptions ...config.Option) (NetworkController, error) { return c, nil } -func (c *controller) SetClusterProvider(provider cluster.Provider) { +func (c *controller) SetClusterProvider(provider provider.Cluster) { var sameProvider bool c.Lock() // Avoids to spawn multiple goroutine for the same cluster provider @@ -307,17 +307,17 @@ func (c *controller) clusterAgentInit() { var keysAvailable bool for { eventType := <-clusterProvider.ListenClusterEvents() - // The events: EventSocketChange, EventNodeReady and EventNetworkKeysAvailable are not ordered + // The events: ClusterEventSocketChange, ClusterEventNodeReady and ClusterEventNetworkKeysAvailable are not ordered // when all the condition for the agent initialization are met then proceed with it switch eventType { - case cluster.EventNetworkKeysAvailable: + case provider.ClusterEventNetworkKeysAvailable: // Validates that the keys are actually available before starting the initialization // This will handle old spurious messages left on the channel c.Lock() keysAvailable = c.keys != nil c.Unlock() fallthrough - case cluster.EventSocketChange, cluster.EventNodeReady: + case provider.ClusterEventSocketChange, provider.ClusterEventNodeReady: if keysAvailable && !c.isDistributedControl() { c.agentOperationStart() if err := c.agentSetup(clusterProvider); err != nil { @@ -326,7 +326,7 @@ func (c *controller) clusterAgentInit() { c.agentInitComplete() } } - case cluster.EventNodeLeave: + case provider.ClusterEventNodeLeave: keysAvailable = false c.agentOperationStart() c.Lock()