Move container lists to scope they are used in

This commit is contained in:
Daniel Middlecote committed 2017-03-08 21:43:21 +00:00
1 parent fd28740108
commit 104d2240ec
2 files changed
+14 -11

No files matched your search

+8 -10
View File
@@ -306,20 +306,18 @@ 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, runningContainerIDs, weavenet.WeaveBridgeName)
preClaims, err := findExistingAddresses(dockerCli, weavenet.WeaveBridgeName)
checkFatal(err)
allocator, defaultSubnet = createAllocator(router, ipamConfig, preClaims, db, t, isKnownPeer)
observeContainers(allocator)
allocator.PruneOwned(allContainerIDs)
if dockerCli != nil {
allContainerIDs, err := dockerCli.AllContainerIDs()
checkFatal(err)
allocator.PruneOwned(allContainerIDs)
}
}
var (
+6 -1
View File
@@ -20,7 +20,7 @@ func a(cidr *net.IPNet) address.CIDR {
// Get all the existing Weave IPs at startup, so we can stop IPAM
// 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)
// First get the address for the bridge
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
// namespace with an attached interface
if dockerCli != nil {
containerIDs, err := dockerCli.RunningContainerIDs()
if err != nil {
return nil, err
}
for _, cid := range containerIDs {
container, err := dockerCli.InspectContainer(cid)
if err != nil {