Skip to content

Commit

Permalink
Serializing IP allocation
Browse files Browse the repository at this point in the history
This commit contains fix to serialize IPAM and Port allocation.
This would fix transient issues seen due to immediate resource
release.

Signed-off-by: Abhinandan Prativadi <[email protected]>
  • Loading branch information
abhi committed Oct 4, 2017
1 parent ed271d4 commit d53074a
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 160 deletions.
9 changes: 9 additions & 0 deletions manager/allocator/cnmallocator/networkallocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,10 @@ func (na *cnmNetworkAllocator) allocateVIP(vip *api.Endpoint_VirtualIP) error {
}
if localNet.nw.IPAM != nil && localNet.nw.IPAM.Driver != nil {
opts = localNet.nw.IPAM.Driver.Options
if opts == nil {
opts = make(map[string]string)
}
opts[ipamapi.AllocSerialPrefix] = "true"
}

for _, poolID := range localNet.pools {
Expand Down Expand Up @@ -694,6 +698,10 @@ func (na *cnmNetworkAllocator) allocateNetworkIPs(nAttach *api.NetworkAttachment

if localNet.nw.IPAM != nil && localNet.nw.IPAM.Driver != nil {
opts = localNet.nw.IPAM.Driver.Options
if opts == nil {
opts = make(map[string]string)
}
opts[ipamapi.AllocSerialPrefix] = "true"
}

for _, poolID := range localNet.pools {
Expand Down Expand Up @@ -931,6 +939,7 @@ func (na *cnmNetworkAllocator) allocatePools(n *api.Network) (map[string]string,
dOptions = make(map[string]string)
}
dOptions[ipamapi.RequestAddressType] = netlabel.Gateway
dOptions[ipamapi.AllocSerialPrefix] = "true"
defer delete(dOptions, ipamapi.RequestAddressType)

if ic.Gateway != "" || gwIP == nil {
Expand Down
6 changes: 3 additions & 3 deletions manager/allocator/cnmallocator/networkallocator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,8 @@ func TestServiceAddRemovePortsIngressMode(t *testing.T) {
assert.Len(t, s.Endpoint.Ports, 0)
assert.Len(t, s.Endpoint.VirtualIPs, 0)

// Publish port again and ensure VIP is the same that was deallocated
// and there is no leak.
// Publish port again and ensure VIP is not the same that was deallocated.
// Since IP allocation is serial we should receive the next available IP.
s.Spec.Endpoint.Ports = append(s.Spec.Endpoint.Ports, &api.PortConfig{Name: "some_tcp",
TargetPort: 1234,
PublishedPort: 1234,
Expand All @@ -786,7 +786,7 @@ func TestServiceAddRemovePortsIngressMode(t *testing.T) {
assert.Len(t, s.Endpoint.Ports, 1)
assert.Equal(t, uint32(1234), s.Endpoint.Ports[0].PublishedPort)
assert.Len(t, s.Endpoint.VirtualIPs, 1)
assert.Equal(t, allocatedVIP, s.Endpoint.VirtualIPs[0].Addr)
assert.NotEqual(t, allocatedVIP, s.Endpoint.VirtualIPs[0].Addr)
}

func TestServiceUpdate(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion manager/allocator/cnmallocator/portallocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func (ps *portSpace) allocate(p *api.PortConfig) (err error) {
}

// Check out an arbitrary port from dynamic port space.
swarmPort, err := ps.dynamicPortSpace.GetID()
swarmPort, err := ps.dynamicPortSpace.GetID(true)
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion vendor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ github.com/docker/go-connections 3ede32e2033de7505e6500d6c868c2b9ed9f169d
github.com/docker/go-events 9461782956ad83b30282bf90e31fa6a70c255ba9
github.com/docker/go-units 954fed01cc617c55d838fa2230073f2cb17386c8
github.com/docker/libkv 9fd56606e928ff1f309808f5d5a0b7a2ef73f9a8
github.com/docker/libnetwork 19ac3ea7f52bb46e0eb10669756cdae0c441a5b1
github.com/docker/libnetwork 21544598c53fa36a3c771a8725c643dd2340f845
github.com/docker/libtrust 9cbd2a1374f46905c68a4eb3694a130610adc62a
github.com/opencontainers/runc d40db12e72a40109dfcf28539f5ee0930d2f0277
github.com/opencontainers/go-digest 21dfd564fd89c944783d00d069f33e3e7123c448
Expand Down
60 changes: 0 additions & 60 deletions vendor/github.com/docker/docker/hack/README.md

This file was deleted.

This file was deleted.

This file was deleted.

49 changes: 39 additions & 10 deletions vendor/github.com/docker/libnetwork/bitseq/sequence.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/docker/libnetwork/bitseq/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions vendor/github.com/docker/libnetwork/idm/idm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d53074a

Please sign in to comment.