Only check running containers for existing addresses
This commit is contained in:
1 parent
26b566b541
commit
fd28740108
2 files changed
+19
-3
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) {
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
var ids []string
|
||||
for _, c := range all {
|
||||
for _, c := range containers {
|
||||
ids = append(ids, c.ID)
|
||||
}
|
||||
return ids, nil
|
||||
|
||||
+5
-1
@@ -307,11 +307,15 @@ func main() {
|
||||
trackerName = "awsvpc"
|
||||
}
|
||||
var allContainerIDs []string
|
||||
var runningContainerIDs []string
|
||||
if dockerCli != nil {
|
||||
allContainerIDs, err = dockerCli.AllContainerIDs()
|
||||
checkFatal(err)
|
||||
|
||||
runningContainerIDs, err = dockerCli.RunningContainerIDs()
|
||||
checkFatal(err)
|
||||
}
|
||||
preClaims, err := findExistingAddresses(dockerCli, allContainerIDs, weavenet.WeaveBridgeName)
|
||||
preClaims, err := findExistingAddresses(dockerCli, runningContainerIDs, weavenet.WeaveBridgeName)
|
||||
checkFatal(err)
|
||||
allocator, defaultSubnet = createAllocator(router, ipamConfig, preClaims, db, t, isKnownPeer)
|
||||
observeContainers(allocator)
|
||||
|
||||
Reference in new issue
Block a user