|
@@ -135,10 +135,11 @@ type Cluster struct {
|
|
|
// helps in identifying the attachment ID via the taskID and the
|
|
|
// corresponding attachment configuration obtained from the manager.
|
|
|
type attacher struct {
|
|
|
- taskID string
|
|
|
- config *network.NetworkingConfig
|
|
|
- attachWaitCh chan *network.NetworkingConfig
|
|
|
- detachWaitCh chan struct{}
|
|
|
+ taskID string
|
|
|
+ config *network.NetworkingConfig
|
|
|
+ attachWaitCh chan *network.NetworkingConfig
|
|
|
+ attachCompleteCh chan struct{}
|
|
|
+ detachWaitCh chan struct{}
|
|
|
}
|
|
|
|
|
|
type node struct {
|
|
@@ -1262,12 +1263,24 @@ func (c *Cluster) WaitForDetachment(ctx context.Context, networkName, networkID,
|
|
|
agent := c.node.Agent()
|
|
|
c.RUnlock()
|
|
|
|
|
|
- if ok && attacher != nil && attacher.detachWaitCh != nil {
|
|
|
+ if ok && attacher != nil &&
|
|
|
+ attacher.detachWaitCh != nil &&
|
|
|
+ attacher.attachCompleteCh != nil {
|
|
|
+ // Attachment may be in progress still so wait for
|
|
|
+ // attachment to complete.
|
|
|
select {
|
|
|
- case <-attacher.detachWaitCh:
|
|
|
+ case <-attacher.attachCompleteCh:
|
|
|
case <-ctx.Done():
|
|
|
return ctx.Err()
|
|
|
}
|
|
|
+
|
|
|
+ if attacher.taskID == taskID {
|
|
|
+ select {
|
|
|
+ case <-attacher.detachWaitCh:
|
|
|
+ case <-ctx.Done():
|
|
|
+ return ctx.Err()
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return agent.ResourceAllocator().DetachNetwork(ctx, taskID)
|
|
@@ -1289,9 +1302,11 @@ func (c *Cluster) AttachNetwork(target string, containerID string, addresses []s
|
|
|
agent := c.node.Agent()
|
|
|
attachWaitCh := make(chan *network.NetworkingConfig)
|
|
|
detachWaitCh := make(chan struct{})
|
|
|
+ attachCompleteCh := make(chan struct{})
|
|
|
c.attachers[aKey] = &attacher{
|
|
|
- attachWaitCh: attachWaitCh,
|
|
|
- detachWaitCh: detachWaitCh,
|
|
|
+ attachWaitCh: attachWaitCh,
|
|
|
+ attachCompleteCh: attachCompleteCh,
|
|
|
+ detachWaitCh: detachWaitCh,
|
|
|
}
|
|
|
c.Unlock()
|
|
|
|
|
@@ -1306,6 +1321,11 @@ func (c *Cluster) AttachNetwork(target string, containerID string, addresses []s
|
|
|
return nil, fmt.Errorf("Could not attach to network %s: %v", target, err)
|
|
|
}
|
|
|
|
|
|
+ c.Lock()
|
|
|
+ c.attachers[aKey].taskID = taskID
|
|
|
+ close(attachCompleteCh)
|
|
|
+ c.Unlock()
|
|
|
+
|
|
|
logrus.Debugf("Successfully attached to network %s with tid %s", target, taskID)
|
|
|
|
|
|
var config *network.NetworkingConfig
|
|
@@ -1316,7 +1336,6 @@ func (c *Cluster) AttachNetwork(target string, containerID string, addresses []s
|
|
|
}
|
|
|
|
|
|
c.Lock()
|
|
|
- c.attachers[aKey].taskID = taskID
|
|
|
c.attachers[aKey].config = config
|
|
|
c.Unlock()
|
|
|
return config, nil
|