Skip to content

Commit

Permalink
NetworkAllocator must make use of plugin-v2
Browse files Browse the repository at this point in the history
Signed-off-by: Madhu Venugopal <madhu@docker.com>
(cherry picked from commit f250807)
  • Loading branch information
mavenugo committed Jan 19, 2017
1 parent 1af7400 commit 5e127b7
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 11 deletions.
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
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
1 change: 1 addition & 0 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,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

0 comments on commit 5e127b7

Please sign in to comment.