mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Moved the cluster provider to Moby
Moved the cluster provider interface definition from libnetwork to moby Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>
This commit is contained in:
parent
eb0c1ea00c
commit
627da8bf04
5 changed files with 16 additions and 52 deletions
|
@ -11,9 +11,9 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
|
"github.com/docker/docker/daemon/cluster/provider"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
"github.com/docker/go-events"
|
"github.com/docker/go-events"
|
||||||
"github.com/docker/libnetwork/cluster"
|
|
||||||
"github.com/docker/libnetwork/datastore"
|
"github.com/docker/libnetwork/datastore"
|
||||||
"github.com/docker/libnetwork/discoverapi"
|
"github.com/docker/libnetwork/discoverapi"
|
||||||
"github.com/docker/libnetwork/driverapi"
|
"github.com/docker/libnetwork/driverapi"
|
||||||
|
@ -193,7 +193,7 @@ func (c *controller) handleKeyChange(keys []*types.EncryptionKey) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *controller) agentSetup(clusterProvider cluster.Provider) error {
|
func (c *controller) agentSetup(clusterProvider provider.Cluster) error {
|
||||||
agent := c.getAgent()
|
agent := c.getAgent()
|
||||||
|
|
||||||
// If the agent is already present there is no need to try to initilize it again
|
// If the agent is already present there is no need to try to initilize it again
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
|
|
@ -24,10 +24,10 @@ import (
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/docker/api/types/network"
|
"github.com/docker/docker/api/types/network"
|
||||||
|
"github.com/docker/docker/daemon/cluster/provider"
|
||||||
"github.com/docker/docker/pkg/term"
|
"github.com/docker/docker/pkg/term"
|
||||||
"github.com/docker/libnetwork"
|
"github.com/docker/libnetwork"
|
||||||
"github.com/docker/libnetwork/api"
|
"github.com/docker/libnetwork/api"
|
||||||
"github.com/docker/libnetwork/cluster"
|
|
||||||
"github.com/docker/libnetwork/config"
|
"github.com/docker/libnetwork/config"
|
||||||
"github.com/docker/libnetwork/datastore"
|
"github.com/docker/libnetwork/datastore"
|
||||||
"github.com/docker/libnetwork/driverapi"
|
"github.com/docker/libnetwork/driverapi"
|
||||||
|
@ -235,7 +235,7 @@ type dnetConnection struct {
|
||||||
// addr holds the client address.
|
// addr holds the client address.
|
||||||
addr string
|
addr string
|
||||||
Orchestration *NetworkOrchestration
|
Orchestration *NetworkOrchestration
|
||||||
configEvent chan cluster.ConfigEventType
|
configEvent chan provider.ClusterConfigEventType
|
||||||
}
|
}
|
||||||
|
|
||||||
// NetworkOrchestration exported
|
// NetworkOrchestration exported
|
||||||
|
@ -276,7 +276,7 @@ func (d *dnetConnection) dnetDaemon(cfgFile string) error {
|
||||||
controller.SetClusterProvider(d)
|
controller.SetClusterProvider(d)
|
||||||
|
|
||||||
if d.Orchestration.Agent || d.Orchestration.Manager {
|
if d.Orchestration.Agent || d.Orchestration.Manager {
|
||||||
d.configEvent <- cluster.EventNodeReady
|
d.configEvent <- provider.ClusterEventNodeReady
|
||||||
}
|
}
|
||||||
|
|
||||||
createDefaultNetwork(controller)
|
createDefaultNetwork(controller)
|
||||||
|
@ -336,7 +336,7 @@ func (d *dnetConnection) GetNetworkKeys() []*types.EncryptionKey {
|
||||||
func (d *dnetConnection) SetNetworkKeys([]*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
|
return d.configEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -439,7 +439,7 @@ func newDnetConnection(val string) (*dnetConnection, error) {
|
||||||
return nil, errors.New("dnet currently only supports tcp transport")
|
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) {
|
func (d *dnetConnection) httpCall(method, path string, data interface{}, headers map[string][]string) (io.ReadCloser, http.Header, int, error) {
|
||||||
|
|
|
@ -5,11 +5,11 @@ import (
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
|
"github.com/docker/docker/daemon/cluster/provider"
|
||||||
"github.com/docker/docker/pkg/discovery"
|
"github.com/docker/docker/pkg/discovery"
|
||||||
"github.com/docker/docker/pkg/plugingetter"
|
"github.com/docker/docker/pkg/plugingetter"
|
||||||
"github.com/docker/go-connections/tlsconfig"
|
"github.com/docker/go-connections/tlsconfig"
|
||||||
"github.com/docker/libkv/store"
|
"github.com/docker/libkv/store"
|
||||||
"github.com/docker/libnetwork/cluster"
|
|
||||||
"github.com/docker/libnetwork/datastore"
|
"github.com/docker/libnetwork/datastore"
|
||||||
"github.com/docker/libnetwork/netlabel"
|
"github.com/docker/libnetwork/netlabel"
|
||||||
"github.com/docker/libnetwork/osl"
|
"github.com/docker/libnetwork/osl"
|
||||||
|
@ -33,7 +33,7 @@ type DaemonCfg struct {
|
||||||
DefaultDriver string
|
DefaultDriver string
|
||||||
Labels []string
|
Labels []string
|
||||||
DriverCfg map[string]interface{}
|
DriverCfg map[string]interface{}
|
||||||
ClusterProvider cluster.Provider
|
ClusterProvider provider.Cluster
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClusterCfg represents cluster configuration
|
// ClusterCfg represents cluster configuration
|
||||||
|
|
|
@ -53,12 +53,12 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
|
"github.com/docker/docker/daemon/cluster/provider"
|
||||||
"github.com/docker/docker/pkg/discovery"
|
"github.com/docker/docker/pkg/discovery"
|
||||||
"github.com/docker/docker/pkg/locker"
|
"github.com/docker/docker/pkg/locker"
|
||||||
"github.com/docker/docker/pkg/plugingetter"
|
"github.com/docker/docker/pkg/plugingetter"
|
||||||
"github.com/docker/docker/pkg/plugins"
|
"github.com/docker/docker/pkg/plugins"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
"github.com/docker/libnetwork/cluster"
|
|
||||||
"github.com/docker/libnetwork/config"
|
"github.com/docker/libnetwork/config"
|
||||||
"github.com/docker/libnetwork/datastore"
|
"github.com/docker/libnetwork/datastore"
|
||||||
"github.com/docker/libnetwork/discoverapi"
|
"github.com/docker/libnetwork/discoverapi"
|
||||||
|
@ -123,7 +123,7 @@ type NetworkController interface {
|
||||||
ReloadConfiguration(cfgOptions ...config.Option) error
|
ReloadConfiguration(cfgOptions ...config.Option) error
|
||||||
|
|
||||||
// SetClusterProvider sets cluster provider
|
// SetClusterProvider sets cluster provider
|
||||||
SetClusterProvider(provider cluster.Provider)
|
SetClusterProvider(provider provider.Cluster)
|
||||||
|
|
||||||
// Wait for agent initialization complete in libnetwork controller
|
// Wait for agent initialization complete in libnetwork controller
|
||||||
AgentInitWait()
|
AgentInitWait()
|
||||||
|
@ -243,7 +243,7 @@ func New(cfgOptions ...config.Option) (NetworkController, error) {
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *controller) SetClusterProvider(provider cluster.Provider) {
|
func (c *controller) SetClusterProvider(provider provider.Cluster) {
|
||||||
var sameProvider bool
|
var sameProvider bool
|
||||||
c.Lock()
|
c.Lock()
|
||||||
// Avoids to spawn multiple goroutine for the same cluster provider
|
// Avoids to spawn multiple goroutine for the same cluster provider
|
||||||
|
@ -307,17 +307,17 @@ func (c *controller) clusterAgentInit() {
|
||||||
var keysAvailable bool
|
var keysAvailable bool
|
||||||
for {
|
for {
|
||||||
eventType := <-clusterProvider.ListenClusterEvents()
|
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
|
// when all the condition for the agent initialization are met then proceed with it
|
||||||
switch eventType {
|
switch eventType {
|
||||||
case cluster.EventNetworkKeysAvailable:
|
case provider.ClusterEventNetworkKeysAvailable:
|
||||||
// Validates that the keys are actually available before starting the initialization
|
// Validates that the keys are actually available before starting the initialization
|
||||||
// This will handle old spurious messages left on the channel
|
// This will handle old spurious messages left on the channel
|
||||||
c.Lock()
|
c.Lock()
|
||||||
keysAvailable = c.keys != nil
|
keysAvailable = c.keys != nil
|
||||||
c.Unlock()
|
c.Unlock()
|
||||||
fallthrough
|
fallthrough
|
||||||
case cluster.EventSocketChange, cluster.EventNodeReady:
|
case provider.ClusterEventSocketChange, provider.ClusterEventNodeReady:
|
||||||
if keysAvailable && !c.isDistributedControl() {
|
if keysAvailable && !c.isDistributedControl() {
|
||||||
c.agentOperationStart()
|
c.agentOperationStart()
|
||||||
if err := c.agentSetup(clusterProvider); err != nil {
|
if err := c.agentSetup(clusterProvider); err != nil {
|
||||||
|
@ -326,7 +326,7 @@ func (c *controller) clusterAgentInit() {
|
||||||
c.agentInitComplete()
|
c.agentInitComplete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case cluster.EventNodeLeave:
|
case provider.ClusterEventNodeLeave:
|
||||||
keysAvailable = false
|
keysAvailable = false
|
||||||
c.agentOperationStart()
|
c.agentOperationStart()
|
||||||
c.Lock()
|
c.Lock()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue