It was added so that tests could replace it before it was picked
up and used by a new network's PortMapper, so that tests were isolated
from each other. Now the PortMapper is not used by the bridge driver,
neither is driver's portAllocator.
Instead of replacing the driver.portAllocator in tests, reset the
singleton instance using its ReleaseAll().
Un-export portallocator.NewInstance, now the tests aren't using it.
Signed-off-by: Rob Murray <rob.murray@docker.com>
| ... | ... |
@@ -20,7 +20,6 @@ import ( |
| 20 | 20 |
"github.com/docker/docker/libnetwork/netutils" |
| 21 | 21 |
"github.com/docker/docker/libnetwork/ns" |
| 22 | 22 |
"github.com/docker/docker/libnetwork/options" |
| 23 |
- "github.com/docker/docker/libnetwork/portallocator" |
|
| 24 | 23 |
"github.com/docker/docker/libnetwork/scope" |
| 25 | 24 |
"github.com/docker/docker/libnetwork/types" |
| 26 | 25 |
"github.com/pkg/errors" |
| ... | ... |
@@ -143,7 +142,6 @@ type driver struct {
|
| 143 | 143 |
store *datastore.Store |
| 144 | 144 |
nlh *netlink.Handle |
| 145 | 145 |
configNetwork sync.Mutex |
| 146 |
- portAllocator *portallocator.PortAllocator // Overridable for tests. |
|
| 147 | 146 |
sync.Mutex |
| 148 | 147 |
} |
| 149 | 148 |
|
| ... | ... |
@@ -158,8 +156,7 @@ const ( |
| 158 | 158 |
// New constructs a new bridge driver |
| 159 | 159 |
func newDriver() *driver {
|
| 160 | 160 |
return &driver{
|
| 161 |
- networks: map[string]*bridgeNetwork{},
|
|
| 162 |
- portAllocator: portallocator.Get(), |
|
| 161 |
+ networks: map[string]*bridgeNetwork{},
|
|
| 163 | 162 |
} |
| 164 | 163 |
} |
| 165 | 164 |
|
| ... | ... |
@@ -661,7 +661,7 @@ func TestQueryEndpointInfoHairpin(t *testing.T) {
|
| 661 | 661 |
func testQueryEndpointInfo(t *testing.T, ulPxyEnabled bool) {
|
| 662 | 662 |
defer netnsutils.SetupTestOSContext(t)() |
| 663 | 663 |
d := newDriver() |
| 664 |
- d.portAllocator = portallocator.NewInstance() |
|
| 664 |
+ portallocator.Get().ReleaseAll() |
|
| 665 | 665 |
|
| 666 | 666 |
var proxyBinary string |
| 667 | 667 |
var err error |
| ... | ... |
@@ -1235,7 +1235,7 @@ func TestCreateParallel(t *testing.T) {
|
| 1235 | 1235 |
defer c.Cleanup(t) |
| 1236 | 1236 |
|
| 1237 | 1237 |
d := newDriver() |
| 1238 |
- d.portAllocator = portallocator.NewInstance() |
|
| 1238 |
+ portallocator.Get().ReleaseAll() |
|
| 1239 | 1239 |
|
| 1240 | 1240 |
if err := d.configure(nil); err != nil {
|
| 1241 | 1241 |
t.Fatalf("Failed to setup driver config: %v", err)
|
| ... | ... |
@@ -77,21 +77,16 @@ type ( |
| 77 | 77 |
protoMap map[string]*portMap |
| 78 | 78 |
) |
| 79 | 79 |
|
| 80 |
-// Get returns the default instance of PortAllocator |
|
| 80 |
+// Get returns the PortAllocator |
|
| 81 | 81 |
func Get() *PortAllocator {
|
| 82 | 82 |
// Port Allocator is a singleton |
| 83 |
- // Note: Long term solution will be each PortAllocator will have access to |
|
| 84 |
- // the OS so that it can have up to date view of the OS port allocation. |
|
| 85 |
- // When this happens singleton behavior will be removed. Clients do not |
|
| 86 |
- // need to worry about this, they will not see a change in behavior. |
|
| 87 | 83 |
once.Do(func() {
|
| 88 |
- instance = NewInstance() |
|
| 84 |
+ instance = newInstance() |
|
| 89 | 85 |
}) |
| 90 | 86 |
return instance |
| 91 | 87 |
} |
| 92 | 88 |
|
| 93 |
-// NewInstance is meant for use by libnetwork tests. It is not meant to be called directly. |
|
| 94 |
-func NewInstance() *PortAllocator {
|
|
| 89 |
+func newInstance() *PortAllocator {
|
|
| 95 | 90 |
start, end, err := getDynamicPortRange() |
| 96 | 91 |
if err != nil {
|
| 97 | 92 |
log.G(context.TODO()).WithError(err).Infof("falling back to default port range %d-%d", defaultPortRangeStart, defaultPortRangeEnd)
|