mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Revendor swarmkit to 2e956c4
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
This commit is contained in:
parent
1b2786c2c2
commit
b1f5320dd6
16 changed files with 295 additions and 148 deletions
49
vendor/github.com/docker/swarmkit/agent/agent.go
generated
vendored
49
vendor/github.com/docker/swarmkit/agent/agent.go
generated
vendored
|
@ -37,6 +37,8 @@ type Agent struct {
|
|||
started chan struct{}
|
||||
startOnce sync.Once // start only once
|
||||
ready chan struct{}
|
||||
leaving chan struct{}
|
||||
leaveOnce sync.Once
|
||||
stopped chan struct{} // requests shutdown
|
||||
stopOnce sync.Once // only allow stop to be called once
|
||||
closed chan struct{} // only closed in run
|
||||
|
@ -53,6 +55,7 @@ func New(config *Config) (*Agent, error) {
|
|||
config: config,
|
||||
sessionq: make(chan sessionOperation),
|
||||
started: make(chan struct{}),
|
||||
leaving: make(chan struct{}),
|
||||
stopped: make(chan struct{}),
|
||||
closed: make(chan struct{}),
|
||||
ready: make(chan struct{}),
|
||||
|
@ -78,6 +81,37 @@ func (a *Agent) Start(ctx context.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Leave instructs the agent to leave the cluster. This method will shutdown
|
||||
// assignment processing and remove all assignments from the node.
|
||||
// Leave blocks until worker has finished closing all task managers or agent
|
||||
// is closed.
|
||||
func (a *Agent) Leave(ctx context.Context) error {
|
||||
select {
|
||||
case <-a.started:
|
||||
default:
|
||||
return errAgentNotStarted
|
||||
}
|
||||
|
||||
a.leaveOnce.Do(func() {
|
||||
close(a.leaving)
|
||||
})
|
||||
|
||||
// agent could be closed while Leave is in progress
|
||||
var err error
|
||||
ch := make(chan struct{})
|
||||
go func() {
|
||||
err = a.worker.Wait(ctx)
|
||||
close(ch)
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-ch:
|
||||
return err
|
||||
case <-a.closed:
|
||||
return ErrClosed
|
||||
}
|
||||
}
|
||||
|
||||
// Stop shuts down the agent, blocking until full shutdown. If the agent is not
|
||||
// started, Stop will block until the agent has fully shutdown.
|
||||
func (a *Agent) Stop(ctx context.Context) error {
|
||||
|
@ -151,6 +185,7 @@ func (a *Agent) run(ctx context.Context) {
|
|||
registered = session.registered
|
||||
ready = a.ready // first session ready
|
||||
sessionq chan sessionOperation
|
||||
leaving = a.leaving
|
||||
subscriptions = map[string]context.CancelFunc{}
|
||||
)
|
||||
|
||||
|
@ -171,7 +206,21 @@ func (a *Agent) run(ctx context.Context) {
|
|||
select {
|
||||
case operation := <-sessionq:
|
||||
operation.response <- operation.fn(session)
|
||||
case <-leaving:
|
||||
leaving = nil
|
||||
|
||||
// TODO(stevvooe): Signal to the manager that the node is leaving.
|
||||
|
||||
// when leaving we remove all assignments.
|
||||
if err := a.worker.Assign(ctx, nil); err != nil {
|
||||
log.G(ctx).WithError(err).Error("failed removing all assignments")
|
||||
}
|
||||
case msg := <-session.assignments:
|
||||
// if we have left, accept no more assignments
|
||||
if leaving == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
switch msg.Type {
|
||||
case api.AssignmentsMessage_COMPLETE:
|
||||
// Need to assign secrets before tasks, because tasks might depend on new secrets
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue