|
@@ -51,6 +51,7 @@ import (
|
|
types "github.com/docker/docker/api/types/swarm"
|
|
types "github.com/docker/docker/api/types/swarm"
|
|
executorpkg "github.com/docker/docker/daemon/cluster/executor"
|
|
executorpkg "github.com/docker/docker/daemon/cluster/executor"
|
|
"github.com/docker/docker/pkg/signal"
|
|
"github.com/docker/docker/pkg/signal"
|
|
|
|
+ lncluster "github.com/docker/libnetwork/cluster"
|
|
swarmapi "github.com/docker/swarmkit/api"
|
|
swarmapi "github.com/docker/swarmkit/api"
|
|
swarmnode "github.com/docker/swarmkit/node"
|
|
swarmnode "github.com/docker/swarmkit/node"
|
|
"github.com/pkg/errors"
|
|
"github.com/pkg/errors"
|
|
@@ -115,7 +116,7 @@ type Cluster struct {
|
|
root string
|
|
root string
|
|
runtimeRoot string
|
|
runtimeRoot string
|
|
config Config
|
|
config Config
|
|
- configEvent chan struct{} // todo: make this array and goroutine safe
|
|
|
|
|
|
+ configEvent chan lncluster.ConfigEventType // todo: make this array and goroutine safe
|
|
attachers map[string]*attacher
|
|
attachers map[string]*attacher
|
|
}
|
|
}
|
|
|
|
|
|
@@ -147,22 +148,30 @@ func New(config Config) (*Cluster, error) {
|
|
c := &Cluster{
|
|
c := &Cluster{
|
|
root: root,
|
|
root: root,
|
|
config: config,
|
|
config: config,
|
|
- configEvent: make(chan struct{}, 10),
|
|
|
|
|
|
+ configEvent: make(chan lncluster.ConfigEventType, 10),
|
|
runtimeRoot: config.RuntimeRoot,
|
|
runtimeRoot: config.RuntimeRoot,
|
|
attachers: make(map[string]*attacher),
|
|
attachers: make(map[string]*attacher),
|
|
}
|
|
}
|
|
|
|
+ return c, nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// Start the Cluster instance
|
|
|
|
+// TODO The split between New and Start can be join again when the SendClusterEvent
|
|
|
|
+// method is no longer required
|
|
|
|
+func (c *Cluster) Start() error {
|
|
|
|
+ root := filepath.Join(c.config.Root, swarmDirName)
|
|
|
|
|
|
nodeConfig, err := loadPersistentState(root)
|
|
nodeConfig, err := loadPersistentState(root)
|
|
if err != nil {
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
if os.IsNotExist(err) {
|
|
- return c, nil
|
|
|
|
|
|
+ return nil
|
|
}
|
|
}
|
|
- return nil, err
|
|
|
|
|
|
+ return err
|
|
}
|
|
}
|
|
|
|
|
|
nr, err := c.newNodeRunner(*nodeConfig)
|
|
nr, err := c.newNodeRunner(*nodeConfig)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return nil, err
|
|
|
|
|
|
+ return err
|
|
}
|
|
}
|
|
c.nr = nr
|
|
c.nr = nr
|
|
|
|
|
|
@@ -172,10 +181,10 @@ func New(config Config) (*Cluster, error) {
|
|
case err := <-nr.Ready():
|
|
case err := <-nr.Ready():
|
|
if err != nil {
|
|
if err != nil {
|
|
logrus.WithError(err).Error("swarm component could not be started")
|
|
logrus.WithError(err).Error("swarm component could not be started")
|
|
- return c, nil
|
|
|
|
|
|
+ return nil
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return c, nil
|
|
|
|
|
|
+ return nil
|
|
}
|
|
}
|
|
|
|
|
|
func (c *Cluster) newNodeRunner(conf nodeStartConfig) (*nodeRunner, error) {
|
|
func (c *Cluster) newNodeRunner(conf nodeStartConfig) (*nodeRunner, error) {
|
|
@@ -308,7 +317,7 @@ func (c *Cluster) getRemoteAddressList() []string {
|
|
// ListenClusterEvents returns a channel that receives messages on cluster
|
|
// ListenClusterEvents returns a channel that receives messages on cluster
|
|
// participation changes.
|
|
// participation changes.
|
|
// todo: make cancelable and accessible to multiple callers
|
|
// todo: make cancelable and accessible to multiple callers
|
|
-func (c *Cluster) ListenClusterEvents() <-chan struct{} {
|
|
|
|
|
|
+func (c *Cluster) ListenClusterEvents() <-chan lncluster.ConfigEventType {
|
|
return c.configEvent
|
|
return c.configEvent
|
|
}
|
|
}
|
|
|
|
|
|
@@ -413,3 +422,13 @@ func (c *Cluster) lockedManagerAction(fn func(ctx context.Context, state nodeSta
|
|
|
|
|
|
return fn(ctx, state)
|
|
return fn(ctx, state)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// SendClusterEvent allows to send cluster events on the configEvent channel
|
|
|
|
+// TODO This method should not be exposed.
|
|
|
|
+// Currently it is used to notify the network controller that the keys are
|
|
|
|
+// available
|
|
|
|
+func (c *Cluster) SendClusterEvent(event lncluster.ConfigEventType) {
|
|
|
|
+ c.mu.RLock()
|
|
|
|
+ defer c.mu.RUnlock()
|
|
|
|
+ c.configEvent <- event
|
|
|
|
+}
|