Skip to content

Commit 4b261ae

Browse files
authored
Merge pull request #3167 from corhere/inject-allocator
Inject network allocator into Node
2 parents dcda100 + e1c4a7d commit 4b261ae

29 files changed

+1611
-756
lines changed

manager/allocator/allocator.go

+10-15
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import (
44
"context"
55
"sync"
66

7-
"github.com/docker/docker/pkg/plugingetter"
87
"github.com/docker/go-events"
98
"github.com/moby/swarmkit/v2/api"
10-
"github.com/moby/swarmkit/v2/manager/allocator/cnmallocator"
9+
"github.com/moby/swarmkit/v2/manager/allocator/networkallocator"
1110
"github.com/moby/swarmkit/v2/manager/state"
1211
"github.com/moby/swarmkit/v2/manager/state/store"
1312
)
@@ -31,11 +30,7 @@ type Allocator struct {
3130
// doneChan is closed when the allocator is finished running.
3231
doneChan chan struct{}
3332

34-
// pluginGetter provides access to docker's plugin inventory.
35-
pluginGetter plugingetter.PluginGetter
36-
37-
// networkConfig stores network related config for the cluster
38-
networkConfig *cnmallocator.NetworkConfig
33+
nwkAllocator networkallocator.NetworkAllocator
3934
}
4035

4136
// taskBallot controls how the voting for task allocation is
@@ -69,19 +64,19 @@ type allocActor struct {
6964

7065
// New returns a new instance of Allocator for use during allocation
7166
// stage of the manager.
72-
func New(store *store.MemoryStore, pg plugingetter.PluginGetter, netConfig *cnmallocator.NetworkConfig) (*Allocator, error) {
73-
a := &Allocator{
67+
func New(store *store.MemoryStore, na networkallocator.NetworkAllocator) *Allocator {
68+
if na == nil {
69+
na = networkallocator.Inert{}
70+
}
71+
return &Allocator{
7472
store: store,
7573
taskBallot: &taskBallot{
7674
votes: make(map[string][]string),
7775
},
78-
stopChan: make(chan struct{}),
79-
doneChan: make(chan struct{}),
80-
pluginGetter: pg,
81-
networkConfig: netConfig,
76+
stopChan: make(chan struct{}),
77+
doneChan: make(chan struct{}),
78+
nwkAllocator: na,
8279
}
83-
84-
return a, nil
8580
}
8681

8782
// Run starts all allocator go-routines and waits for Stop to be called.

0 commit comments

Comments
 (0)