Skip to content

Commit

Permalink
Merge pull request #2409 from /issues/2381-awsvpc-fix-attach-router
Browse files Browse the repository at this point in the history
Fix re-attaching of weave router in awsvpc mode
  • Loading branch information
bboreham committed Jun 29, 2016
2 parents 7165414 + 6319860 commit f1ca485
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
2 changes: 2 additions & 0 deletions ipam/ring/ring.go
Expand Up @@ -119,6 +119,8 @@ func New(start, end address.Address, peer mesh.PeerName, f OnUpdate) *Ring {
}

func (r *Ring) Restore(other *Ring) {
defer r.trackUpdates()()

onUpdate := r.onUpdate
*r = *other
r.onUpdate = onUpdate
Expand Down
17 changes: 8 additions & 9 deletions ipam/tracker/awsvpc.go
Expand Up @@ -21,6 +21,7 @@ package tracker
import (
"fmt"
"net"
"syscall"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/ec2metadata"
Expand Down Expand Up @@ -94,14 +95,14 @@ func (t *AWSVPCTracker) HandleUpdate(prevRanges, currRanges []address.Range, loc
for _, cidr := range curr {
cidrStr := cidr.String()
t.debugf("adding route %s to %s", cidrStr, t.instanceID)
_, err := t.createVPCRoute(cidrStr)
if err != nil {
if _, err := t.createVPCRoute(cidrStr); err != nil {
return fmt.Errorf("createVPCRoutes failed: %s", err)
}
if local {
err = t.createHostRoute(cidrStr)
if err != nil {
return fmt.Errorf("createHostRoute failed: %s", err)
if err := t.createHostRoute(cidrStr); err != nil {
if errno, ok := err.(syscall.Errno); !(ok && errno == syscall.EEXIST) {
return fmt.Errorf("createHostRoute failed: %s", err)
}
}
}
}
Expand All @@ -110,13 +111,11 @@ func (t *AWSVPCTracker) HandleUpdate(prevRanges, currRanges []address.Range, loc
for _, cidr := range prev {
cidrStr := cidr.String()
t.debugf("removing %s route", cidrStr)
_, err := t.deleteVPCRoute(cidrStr)
if err != nil {
if _, err := t.deleteVPCRoute(cidrStr); err != nil {
return fmt.Errorf("deleteVPCRoute failed: %s", err)
}
if local {
err = t.deleteHostRoute(cidrStr)
if err != nil {
if err := t.deleteHostRoute(cidrStr); err != nil {
return fmt.Errorf("deleteHostRoute failed: %s", err)
}
}
Expand Down
12 changes: 10 additions & 2 deletions weave
Expand Up @@ -1655,9 +1655,12 @@ launch_router() {
"$@")
setup_router_iface_$BRIDGE_TYPE
wait_for_status $CONTAINER_NAME http_call $HTTP_ADDR
setup_awsvpc
populate_router
}

setup_awsvpc() {
if [ -n "$AWSVPC" ]; then
expose_ip
# Set proxy_arp on the bridge, so that it could accept packets destined
# to containers within the same subnet but running on remote hosts.
# Without it, exact routes on each container are required.
Expand All @@ -1666,6 +1669,7 @@ launch_router() {
# placing the request into a bounded queue as it can be seen:
# https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/net/ipv4/arp.c?id=refs/tags/v4.6.1#n819
echo 0 >/proc/sys/net/ipv4/neigh/$BRIDGE/proxy_delay
expose_ip
fi
}

Expand All @@ -1679,7 +1683,8 @@ fetch_router_args() {
populate_router() {
if [ -n "$IPRANGE" ] ; then
# Tell the newly-started weave IP allocator about existing weave IPs
with_container_addresses ipam_reclaim_no_check_alive weave:expose
# In the case of AWSVPC, we do expose before calling populate_router
[ -n "$AWSVPC" ] || with_container_addresses ipam_reclaim_no_check_alive weave:expose
with_container_addresses ipam_reclaim $(docker ps -q --no-trunc)
fi
if [ -z "$NO_DNS_OPT" ] ; then
Expand Down Expand Up @@ -1956,10 +1961,13 @@ EOF
attach-router)
check_running $CONTAINER_NAME
enforce_docker_bridge_addr_assign_type
# We cannot use detect_awsvpc here, because HTTP server might not be started
! docker inspect -f '{{.Config.Cmd}}' $CONTAINER_NAME | grep -q -- "--awsvpc" || AWSVPC=1
create_bridge
fetch_router_args
setup_router_iface_$BRIDGE_TYPE
wait_for_status $CONTAINER_NAME http_call $HTTP_ADDR
setup_awsvpc
populate_router
;;
launch-proxy)
Expand Down

0 comments on commit f1ca485

Please sign in to comment.