Skip to content

Commit

Permalink
vendor: update swarmkit to cb6d813
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <[email protected]>
  • Loading branch information
tonistiigi committed Aug 10, 2016
1 parent 19a3289 commit 3b555a5
Show file tree
Hide file tree
Showing 38 changed files with 1,415 additions and 572 deletions.
2 changes: 1 addition & 1 deletion hack/vendor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ clone git github.com/docker/docker-credential-helpers v0.3.0
clone git github.com/docker/containerd 0ac3cd1be170d180b2baed755e8f0da547ceb267

# cluster
clone git github.com/docker/swarmkit e1c0d64515d839b76e2ef33d396c74933753ffaf
clone git github.com/docker/swarmkit cb6d81316727941665594f153434e5ce2e425c9b
clone git github.com/golang/mock bd3c8e81be01eef76d4b503f5e687d2d1354d2d9
clone git github.com/gogo/protobuf 43a2e0b1c32252bfbbdf81f7faa7a88fb3fa4028
clone git github.com/cloudflare/cfssl b895b0549c0ff676f92cf09ba971ae02bb41367b
Expand Down
92 changes: 42 additions & 50 deletions vendor/src/github.com/docker/swarmkit/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"math/rand"
"reflect"
"sync"
"time"

"github.com/docker/swarmkit/api"
Expand Down Expand Up @@ -31,11 +32,13 @@ type Agent struct {
sessionq chan sessionOperation
worker Worker

started chan struct{}
ready chan struct{}
stopped chan struct{} // requests shutdown
closed chan struct{} // only closed in run
err error // read only after closed is closed
started chan struct{}
startOnce sync.Once // start only once
ready chan struct{}
stopped chan struct{} // requests shutdown
stopOnce sync.Once // only allow stop to be called once
closed chan struct{} // only closed in run
err error // read only after closed is closed
}

// New returns a new agent, ready for task dispatch.
Expand All @@ -59,57 +62,50 @@ func New(config *Config) (*Agent, error) {

// Start begins execution of the agent in the provided context, if not already
// started.
//
// Start returns an error if the agent has already started.
func (a *Agent) Start(ctx context.Context) error {
select {
case <-a.started:
select {
case <-a.closed:
return a.err
case <-a.stopped:
return errAgentStopped
case <-ctx.Done():
return ctx.Err()
default:
return errAgentStarted
}
case <-ctx.Done():
return ctx.Err()
default:
}
err := errAgentStarted

close(a.started)
go a.run(ctx)
a.startOnce.Do(func() {
close(a.started)
go a.run(ctx)
err = nil // clear error above, only once.
})

return nil
return err
}

// Stop shuts down the agent, blocking until full shutdown. If the agent is not
// started, Stop will block until Started.
// started, Stop will block until the agent has fully shutdown.
func (a *Agent) Stop(ctx context.Context) error {
select {
case <-a.started:
select {
case <-a.closed:
return a.err
case <-a.stopped:
select {
case <-a.closed:
return a.err
case <-ctx.Done():
return ctx.Err()
}
case <-ctx.Done():
return ctx.Err()
default:
close(a.stopped)
// recurse and wait for closure
return a.Stop(ctx)
}
case <-ctx.Done():
return ctx.Err()
default:
return errAgentNotStarted
}

a.stop()

// wait till closed or context cancelled
select {
case <-a.closed:
return nil
case <-ctx.Done():
return ctx.Err()
}
}

// stop signals the agent shutdown process, returning true if this call was the
// first to actually shutdown the agent.
func (a *Agent) stop() bool {
var stopped bool
a.stopOnce.Do(func() {
close(a.stopped)
stopped = true
})

return stopped
}

// Err returns the error that caused the agent to shutdown or nil. Err blocks
Expand All @@ -133,7 +129,7 @@ func (a *Agent) run(ctx context.Context) {
defer cancel()
defer close(a.closed) // full shutdown.

ctx = log.WithLogger(ctx, log.G(ctx).WithField("module", "agent"))
ctx = log.WithModule(ctx, "agent")

log.G(ctx).Debugf("(*Agent).run")
defer log.G(ctx).Debugf("(*Agent).run exited")
Expand Down Expand Up @@ -197,11 +193,6 @@ func (a *Agent) run(ctx context.Context) {
sessionq = nil
// if we're here before <-registered, do nothing for that event
registered = nil

// Bounce the connection.
if a.config.Picker != nil {
a.config.Picker.Reset()
}
case <-session.closed:
log.G(ctx).Debugf("agent: rebuild session")

Expand All @@ -218,6 +209,7 @@ func (a *Agent) run(ctx context.Context) {
if a.err == nil {
a.err = ctx.Err()
}
session.close()

return
}
Expand Down
18 changes: 6 additions & 12 deletions vendor/src/github.com/docker/swarmkit/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/docker/swarmkit/agent/exec"
"github.com/docker/swarmkit/api"
"github.com/docker/swarmkit/picker"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
)

// Config provides values for an Agent.
Expand All @@ -19,15 +19,6 @@ type Config struct {
// updated with managers weights as observed by the agent.
Managers picker.Remotes

// Conn specifies the client connection Agent will use.
Conn *grpc.ClientConn

// Picker is the picker used by Conn.
// TODO(aaronl): This is only part of the config to allow resetting the
// GRPC connection. This should be refactored to address the coupling
// between Conn and Picker.
Picker *picker.Picker

// Executor specifies the executor to use for the agent.
Executor exec.Executor

Expand All @@ -36,11 +27,14 @@ type Config struct {

// NotifyRoleChange channel receives new roles from session messages.
NotifyRoleChange chan<- api.NodeRole

// Credentials is credentials for grpc connection to manager.
Credentials credentials.TransportAuthenticator
}

func (c *Config) validate() error {
if c.Conn == nil {
return fmt.Errorf("agent: Connection is required")
if c.Credentials == nil {
return fmt.Errorf("agent: Credentials is required")
}

if c.Executor == nil {
Expand Down
5 changes: 3 additions & 2 deletions vendor/src/github.com/docker/swarmkit/agent/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ var (
ErrClosed = errors.New("agent: closed")

errNodeNotRegistered = fmt.Errorf("node not registered")
errNodeStarted = errors.New("node: already started")
errNodeNotStarted = errors.New("node: not started")

errAgentNotStarted = errors.New("agent: not started")
errAgentStarted = errors.New("agent: already started")
errAgentStopped = errors.New("agent: stopped")
errAgentNotStarted = errors.New("agent: not started")

errTaskNoContoller = errors.New("agent: no task controller")
errTaskNotAssigned = errors.New("agent: task not assigned")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package exec

import (
"fmt"
"reflect"
"time"

"github.com/Sirupsen/logrus"
"github.com/docker/swarmkit/api"
"github.com/docker/swarmkit/api/equality"
"github.com/docker/swarmkit/log"
"github.com/docker/swarmkit/protobuf/ptypes"
"github.com/pkg/errors"
Expand Down Expand Up @@ -186,7 +186,7 @@ func Do(ctx context.Context, task *api.Task, ctlr Controller) (*api.TaskStatus,
defer func() {
logStateChange(ctx, task.DesiredState, task.Status.State, status.State)

if !reflect.DeepEqual(status, task.Status) {
if !equality.TaskStatusesEqualStable(status, &task.Status) {
status.Timestamp = ptypes.MustTimestampProto(time.Now())
}
}()
Expand Down
2 changes: 1 addition & 1 deletion vendor/src/github.com/docker/swarmkit/agent/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package agent
import "golang.org/x/net/context"

// runctx blocks until the function exits, closed is closed, or the context is
// cancelled. Call as part os go statement.
// cancelled. Call as part of go statement.
func runctx(ctx context.Context, closed chan struct{}, errs chan error, fn func(ctx context.Context) error) {
select {
case errs <- fn(ctx):
Expand Down
75 changes: 24 additions & 51 deletions vendor/src/github.com/docker/swarmkit/agent/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ type Node struct {
nodeID string
nodeMembership api.NodeSpec_Membership
started chan struct{}
startOnce sync.Once
stopped chan struct{}
stopOnce sync.Once
ready chan struct{} // closed when agent has completed registration and manager(if enabled) is ready to receive control requests
certificateRequested chan struct{} // closed when certificate issue request has been sent by node
closed chan struct{}
Expand Down Expand Up @@ -137,26 +139,15 @@ func NewNode(c *NodeConfig) (*Node, error) {

// Start starts a node instance.
func (n *Node) Start(ctx context.Context) error {
select {
case <-n.started:
select {
case <-n.closed:
return n.err
case <-n.stopped:
return errAgentStopped
case <-ctx.Done():
return ctx.Err()
default:
return errAgentStarted
}
case <-ctx.Done():
return ctx.Err()
default:
}
err := errNodeStarted

close(n.started)
go n.run(ctx)
return nil
n.startOnce.Do(func() {
close(n.started)
go n.run(ctx)
err = nil // clear error above, only once.
})

return err
}

func (n *Node) run(ctx context.Context) (err error) {
Expand All @@ -166,7 +157,7 @@ func (n *Node) run(ctx context.Context) (err error) {
}()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
ctx = log.WithLogger(ctx, log.G(ctx).WithField("module", "node"))
ctx = log.WithModule(ctx, "node")

go func() {
select {
Expand Down Expand Up @@ -325,27 +316,19 @@ func (n *Node) run(ctx context.Context) (err error) {
func (n *Node) Stop(ctx context.Context) error {
select {
case <-n.started:
select {
case <-n.closed:
return n.err
case <-n.stopped:
select {
case <-n.closed:
return n.err
case <-ctx.Done():
return ctx.Err()
}
case <-ctx.Done():
return ctx.Err()
default:
close(n.stopped)
// recurse and wait for closure
return n.Stop(ctx)
}
default:
return errNodeNotStarted
}

n.stopOnce.Do(func() {
close(n.stopped)
})

select {
case <-n.closed:
return nil
case <-ctx.Done():
return ctx.Err()
default:
return errAgentNotStarted
}
}

Expand All @@ -361,31 +344,21 @@ func (n *Node) Err(ctx context.Context) error {
}

func (n *Node) runAgent(ctx context.Context, db *bolt.DB, creds credentials.TransportAuthenticator, ready chan<- struct{}) error {
var manager api.Peer
select {
case <-ctx.Done():
case manager = <-n.remotes.WaitSelect(ctx):
case <-n.remotes.WaitSelect(ctx):
}
if ctx.Err() != nil {
return ctx.Err()
}
picker := picker.NewPicker(n.remotes, manager.Addr)
conn, err := grpc.Dial(manager.Addr,
grpc.WithPicker(picker),
grpc.WithTransportCredentials(creds),
grpc.WithBackoffMaxDelay(maxSessionFailureBackoff))
if err != nil {
return err
}

agent, err := New(&Config{
Hostname: n.config.Hostname,
Managers: n.remotes,
Executor: n.config.Executor,
DB: db,
Conn: conn,
Picker: picker,
NotifyRoleChange: n.roleChangeReq,
Credentials: creds,
})
if err != nil {
return err
Expand Down
Loading

0 comments on commit 3b555a5

Please sign in to comment.