This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 672
Claim existing IP addresses at startup with no race condition #2787
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
39ac1a0
Collect existing weave addresses at start-up, to avoid a race when
bboreham e26dbf1
Stop collecting addresses in launch script now we do it in Go
bboreham 7075b5d
Extend pre-existing address reclaim to docker containers
bboreham fde7dcd
Stop collecting addresses in weave script now we do it in Go
bboreham 293abd9
Fix flaky test 320
bboreham 4e37f5e
Add explanations of various claim and allocation fields
bboreham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package main | ||
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
Sorry, something went wrong. |
||
|
||
import ( | ||
"net" | ||
|
||
docker "github.com/fsouza/go-dockerclient" | ||
|
||
"github.com/weaveworks/weave/api" | ||
"github.com/weaveworks/weave/common" | ||
weavedocker "github.com/weaveworks/weave/common/docker" | ||
"github.com/weaveworks/weave/ipam" | ||
weavenet "github.com/weaveworks/weave/net" | ||
"github.com/weaveworks/weave/net/address" | ||
) | ||
|
||
func a(cidr *net.IPNet) address.CIDR { | ||
prefixLength, _ := cidr.Mask.Size() | ||
return address.CIDR{Addr: address.FromIP4(cidr.IP), PrefixLen: prefixLength} | ||
} | ||
|
||
// 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) { | ||
Log.Infof("Checking for pre-existing addresses on %s bridge", bridgeName) | ||
// First get the address for the bridge | ||
bridgeNetDev, err := weavenet.GetBridgeNetDev(bridgeName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, cidr := range bridgeNetDev.CIDRs { | ||
Log.Infof("%s bridge has address %v", bridgeName, cidr) | ||
addrs = append(addrs, ipam.PreClaim{Ident: "weave:expose", Cidr: a(cidr)}) | ||
} | ||
|
||
add := func(cid string, isContainer bool, netDevs []weavenet.Dev) { | ||
for _, netDev := range netDevs { | ||
for _, cidr := range netDev.CIDRs { | ||
Log.Infof("Found address %v for ID %s", cidr, cid) | ||
addrs = append(addrs, ipam.PreClaim{Ident: cid, IsContainer: isContainer, Cidr: a(cidr)}) | ||
} | ||
} | ||
} | ||
|
||
// Then find all veths connected to the bridge | ||
peerIDs, err := weavenet.ConnectedToBridgeVethPeerIds(bridgeName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Now iterate over all containers to see if they have a network | ||
// namespace with an attached interface | ||
if dockerCli != nil { | ||
for _, cid := range containerIDs { | ||
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
Sorry, something went wrong. |
||
container, err := dockerCli.InspectContainer(cid) | ||
if err != nil { | ||
if _, ok := err.(*docker.NoSuchContainer); ok { | ||
continue | ||
} | ||
return nil, err | ||
} | ||
if container.State.Pid != 0 { | ||
netDevs, err := weavenet.GetNetDevsByVethPeerIds(container.State.Pid, peerIDs) | ||
if err != nil { | ||
return nil, err | ||
} | ||
add(cid, true, netDevs) | ||
} | ||
} | ||
} else { | ||
// If we don't have a Docker connection, iterate over all processes | ||
pids, err := common.AllPids("/proc") | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, pid := range pids { | ||
netDevs, err := weavenet.GetNetDevsByVethPeerIds(pid, peerIDs) | ||
if err != nil { | ||
return nil, err | ||
} | ||
add(api.NoContainerID, false, netDevs) | ||
} | ||
} | ||
return addrs, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
Sorry, something went wrong.