Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-picking #1876 and reverts #1856 in 1.13.1 branch #1883

Merged
merged 3 commits into from
Jan 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions manager/allocator/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package allocator
import (
"sync"

"github.com/docker/docker/pkg/plugingetter"
"github.com/docker/go-events"
"github.com/docker/swarmkit/manager/state"
"github.com/docker/swarmkit/manager/state/store"
Expand All @@ -27,6 +28,9 @@ type Allocator struct {
stopChan chan struct{}
// doneChan is closed when the allocator is finished running.
doneChan chan struct{}

// pluginGetter provides access to docker's plugin inventory.
pluginGetter plugingetter.PluginGetter
}

// taskBallot controls how the voting for task allocation is
Expand Down Expand Up @@ -67,14 +71,15 @@ type allocActor struct {

// New returns a new instance of Allocator for use during allocation
// stage of the manager.
func New(store *store.MemoryStore) (*Allocator, error) {
func New(store *store.MemoryStore, pg plugingetter.PluginGetter) (*Allocator, error) {
a := &Allocator{
store: store,
taskBallot: &taskBallot{
votes: make(map[string][]string),
},
stopChan: make(chan struct{}),
doneChan: make(chan struct{}),
stopChan: make(chan struct{}),
doneChan: make(chan struct{}),
pluginGetter: pg,
}

return a, nil
Expand Down
2 changes: 1 addition & 1 deletion manager/allocator/allocator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestAllocator(t *testing.T) {
assert.NotNil(t, s)
defer s.Close()

a, err := New(s)
a, err := New(s, nil)
assert.NoError(t, err)
assert.NotNil(t, a)

Expand Down
2 changes: 1 addition & 1 deletion manager/allocator/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type networkContext struct {
}

func (a *Allocator) doNetworkInit(ctx context.Context) (err error) {
na, err := networkallocator.New()
na, err := networkallocator.New(a.pluginGetter)
if err != nil {
return err
}
Expand Down
12 changes: 8 additions & 4 deletions manager/allocator/networkallocator/networkallocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"net"

"github.com/docker/docker/pkg/plugins"
"github.com/docker/docker/pkg/plugingetter"
"github.com/docker/libnetwork/datastore"
"github.com/docker/libnetwork/driverapi"
"github.com/docker/libnetwork/drvregistry"
Expand Down Expand Up @@ -69,7 +69,7 @@ type initializer struct {
}

// New returns a new NetworkAllocator handle
func New() (*NetworkAllocator, error) {
func New(pg plugingetter.PluginGetter) (*NetworkAllocator, error) {
na := &NetworkAllocator{
networks: make(map[string]*network),
services: make(map[string]struct{}),
Expand All @@ -79,7 +79,7 @@ func New() (*NetworkAllocator, error) {

// There are no driver configurations and notification
// functions as of now.
reg, err := drvregistry.New(nil, nil, nil, nil, nil)
reg, err := drvregistry.New(nil, nil, nil, nil, pg)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -657,7 +657,11 @@ func (na *NetworkAllocator) resolveDriver(n *api.Network) (driverapi.Driver, str
}

func (na *NetworkAllocator) loadDriver(name string) error {
_, err := plugins.Get(name, driverapi.NetworkPluginEndpointType)
pg := na.drvRegistry.GetPluginGetter()
if pg == nil {
return fmt.Errorf("plugin store is unintialized")
}
_, err := pg.Get(name, driverapi.NetworkPluginEndpointType, plugingetter.LOOKUP)
return err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func newNetworkAllocator(t *testing.T) *NetworkAllocator {
na, err := New()
na, err := New(nil)
assert.NoError(t, err)
assert.NotNil(t, na)
return na
Expand Down
5 changes: 1 addition & 4 deletions manager/controlapi/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func validateAnnotations(m api.Annotations) error {
return nil
}

func validateDriver(driver *api.Driver, defName string) error {
func validateDriver(driver *api.Driver) error {
if driver == nil {
// It is ok to not specify the driver. We will choose
// a default driver.
Expand All @@ -87,8 +87,5 @@ func validateDriver(driver *api.Driver, defName string) error {
return grpc.Errorf(codes.InvalidArgument, "driver name: if driver is specified name is required")
}

if driver.Name != defName {
return grpc.Errorf(codes.InvalidArgument, "invalid driver (%s) specified", driver.Name)
}
return nil
}
6 changes: 2 additions & 4 deletions manager/controlapi/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import (
"fmt"
"net"

"github.com/docker/libnetwork/ipamapi"
"github.com/docker/swarmkit/api"
"github.com/docker/swarmkit/identity"
"github.com/docker/swarmkit/manager/allocator/networkallocator"
"github.com/docker/swarmkit/manager/state/store"
"golang.org/x/net/context"
"google.golang.org/grpc"
Expand Down Expand Up @@ -56,7 +54,7 @@ func validateIPAM(ipam *api.IPAMOptions) error {
return nil
}

if err := validateDriver(ipam.Driver, ipamapi.DefaultIPAM); err != nil {
if err := validateDriver(ipam.Driver); err != nil {
return err
}

Expand All @@ -78,7 +76,7 @@ func validateNetworkSpec(spec *api.NetworkSpec) error {
return err
}

if err := validateDriver(spec.DriverConfig, networkallocator.DefaultDriver); err != nil {
if err := validateDriver(spec.DriverConfig); err != nil {
return err
}

Expand Down
8 changes: 2 additions & 6 deletions manager/controlapi/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,9 @@ func createServiceInNetwork(t *testing.T, ts *testServer, name, image string, nw
}

func TestValidateDriver(t *testing.T) {
assert.NoError(t, validateDriver(nil, ""))
assert.NoError(t, validateDriver(nil))

err := validateDriver(&api.Driver{Name: ""}, "")
assert.Error(t, err)
assert.Equal(t, codes.InvalidArgument, grpc.Code(err))

err = validateDriver(&api.Driver{Name: "test"}, "default")
err := validateDriver(&api.Driver{Name: ""})
assert.Error(t, err)
assert.Equal(t, codes.InvalidArgument, grpc.Code(err))
}
Expand Down
6 changes: 5 additions & 1 deletion manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/Sirupsen/logrus"
"github.com/docker/docker/pkg/plugingetter"
"github.com/docker/go-events"
"github.com/docker/swarmkit/api"
"github.com/docker/swarmkit/ca"
Expand Down Expand Up @@ -99,6 +100,9 @@ type Config struct {
// bootstrapping a cluster for the first time (it's a cluster-wide setting),
// and also when loading up any raft data on disk (as a KEK for the raft DEK).
UnlockKey []byte

// PluginGetter provides access to docker's plugin inventory.
PluginGetter plugingetter.PluginGetter
}

// Manager is the cluster manager for Swarm.
Expand Down Expand Up @@ -780,7 +784,7 @@ func (m *Manager) becomeLeader(ctx context.Context) {
// shutdown underlying manager processes when leadership is
// lost.

m.allocator, err = allocator.New(s)
m.allocator, err = allocator.New(s, m.config.PluginGetter)
if err != nil {
log.G(ctx).WithError(err).Error("failed to create allocator")
// TODO(stevvooe): It doesn't seem correct here to fail
Expand Down
5 changes: 5 additions & 0 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/Sirupsen/logrus"
"github.com/boltdb/bolt"
"github.com/docker/docker/pkg/plugingetter"
"github.com/docker/swarmkit/agent"
"github.com/docker/swarmkit/agent/exec"
"github.com/docker/swarmkit/api"
Expand Down Expand Up @@ -95,6 +96,9 @@ type Config struct {
// UnlockKey is the key to unlock a node - used for decrypting at rest. This
// only applies to nodes that have already joined a cluster.
UnlockKey []byte

// PluginGetter provides access to docker's plugin inventory.
PluginGetter plugingetter.PluginGetter
}

// Node implements the primary node functionality for a member of a swarm
Expand Down Expand Up @@ -681,6 +685,7 @@ func (n *Node) runManager(ctx context.Context, securityConfig *ca.SecurityConfig
ElectionTick: n.config.ElectionTick,
AutoLockManagers: n.config.AutoLockManagers,
UnlockKey: n.unlockKey,
PluginGetter: n.config.PluginGetter,
})
if err != nil {
return err
Expand Down