Merge pull request #2829 from dlmiddlecote/issues/2815-check-live-containers
Only check running containers for existing addresses
This commit is contained in:
commit
39563fc142
3 files changed
+29
-10
No files matched your search
+14
-2
@@ -165,13 +165,25 @@ func (pending pendingStarts) finish(id string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AllContainerIDs returns all the IDs of Docker containers,
|
||||||
|
// whether they are running or not.
|
||||||
func (c *Client) AllContainerIDs() ([]string, error) {
|
func (c *Client) AllContainerIDs() ([]string, error) {
|
||||||
all, err := c.ListContainers(docker.ListContainersOptions{All: true})
|
return c.containerIDs(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RunningContainerIDs returns all the IDs of the running
|
||||||
|
// Docker containers.
|
||||||
|
func (c *Client) RunningContainerIDs() ([]string, error) {
|
||||||
|
return c.containerIDs(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) containerIDs(all bool) ([]string, error) {
|
||||||
|
containers, err := c.ListContainers(docker.ListContainersOptions{All: all})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var ids []string
|
var ids []string
|
||||||
for _, c := range all {
|
for _, c := range containers {
|
||||||
ids = append(ids, c.ID)
|
ids = append(ids, c.ID)
|
||||||
}
|
}
|
||||||
return ids, nil
|
return ids, nil
|
||||||
|
|||||||
+9
-7
@@ -306,16 +306,18 @@ func main() {
|
|||||||
}
|
}
|
||||||
trackerName = "awsvpc"
|
trackerName = "awsvpc"
|
||||||
}
|
}
|
||||||
var allContainerIDs []string
|
|
||||||
if dockerCli != nil {
|
preClaims, err := findExistingAddresses(dockerCli, weavenet.WeaveBridgeName)
|
||||||
allContainerIDs, err = dockerCli.AllContainerIDs()
|
|
||||||
checkFatal(err)
|
|
||||||
}
|
|
||||||
preClaims, err := findExistingAddresses(dockerCli, allContainerIDs, weavenet.WeaveBridgeName)
|
|
||||||
checkFatal(err)
|
checkFatal(err)
|
||||||
|
|
||||||
allocator, defaultSubnet = createAllocator(router, ipamConfig, preClaims, db, t, isKnownPeer)
|
allocator, defaultSubnet = createAllocator(router, ipamConfig, preClaims, db, t, isKnownPeer)
|
||||||
observeContainers(allocator)
|
observeContainers(allocator)
|
||||||
allocator.PruneOwned(allContainerIDs)
|
|
||||||
|
if dockerCli != nil {
|
||||||
|
allContainerIDs, err := dockerCli.AllContainerIDs()
|
||||||
|
checkFatal(err)
|
||||||
|
allocator.PruneOwned(allContainerIDs)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ func a(cidr *net.IPNet) address.CIDR {
|
|||||||
|
|
||||||
// Get all the existing Weave IPs at startup, so we can stop IPAM
|
// Get all the existing Weave IPs at startup, so we can stop IPAM
|
||||||
// giving out any as duplicates
|
// giving out any as duplicates
|
||||||
func findExistingAddresses(dockerCli *weavedocker.Client, containerIDs []string, bridgeName string) (addrs []ipam.PreClaim, err error) {
|
func findExistingAddresses(dockerCli *weavedocker.Client, bridgeName string) (addrs []ipam.PreClaim, err error) {
|
||||||
Log.Infof("Checking for pre-existing addresses on %s bridge", bridgeName)
|
Log.Infof("Checking for pre-existing addresses on %s bridge", bridgeName)
|
||||||
// First get the address for the bridge
|
// First get the address for the bridge
|
||||||
bridgeNetDev, err := weavenet.GetBridgeNetDev(bridgeName)
|
bridgeNetDev, err := weavenet.GetBridgeNetDev(bridgeName)
|
||||||
@@ -50,6 +50,11 @@ func findExistingAddresses(dockerCli *weavedocker.Client, containerIDs []string,
|
|||||||
// Now iterate over all containers to see if they have a network
|
// Now iterate over all containers to see if they have a network
|
||||||
// namespace with an attached interface
|
// namespace with an attached interface
|
||||||
if dockerCli != nil {
|
if dockerCli != nil {
|
||||||
|
containerIDs, err := dockerCli.RunningContainerIDs()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
for _, cid := range containerIDs {
|
for _, cid := range containerIDs {
|
||||||
container, err := dockerCli.InspectContainer(cid)
|
container, err := dockerCli.InspectContainer(cid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in new issue
Block a user