From 541adf6bb1504d37448a890cde8a3621a9f650ac Mon Sep 17 00:00:00 2001 From: Martynas Pumputis Date: Sat, 16 Dec 2017 20:57:58 +0100 Subject: [PATCH] Make "weave attach" to depend on running weaver "weave attach $CIDR $CONTAINER_ID" is no longer possible w/o running weaver. This feature was undocumented and complicated the weave script, as "weave attach" required to call "create_bridge". Removing the feature allows us to eliminate the bridge creation from the script. Running "weave attach" w/o weaver results in the following err: bridge "weave" not present; did you launch weave? Also, this commit simplifies the "attach-container" cmd from weaveutil by removing "mtu" as a param. The cmd is used only by "weave attach", and a mtu is value for an attached container interface is exactly the same as one of the weave bridge. --- prog/weaveutil/attach.go | 13 ++++--------- weave | 7 ++----- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/prog/weaveutil/attach.go b/prog/weaveutil/attach.go index 8ffce5f2..e4cfe0b9 100644 --- a/prog/weaveutil/attach.go +++ b/prog/weaveutil/attach.go @@ -4,7 +4,6 @@ import ( "fmt" "net" "os" - "strconv" "strings" "syscall" @@ -15,8 +14,8 @@ import ( ) func attach(args []string) error { - if len(args) < 4 { - cmdUsage("attach-container", "[--no-multicast-route] [--keep-tx-on] [--hairpin-mode=true|false] ...") + if len(args) < 3 { + cmdUsage("attach-container", "[--no-multicast-route] [--keep-tx-on] [--hairpin-mode=true|false] ...") } keepTXOn := false @@ -52,16 +51,12 @@ func attach(args []string) error { } else if nsHost.Equal(nsContainer) { return fmt.Errorf("Container is running in the host network namespace, and therefore cannot be\nconnected to weave - perhaps the container was started with --net=host") } - mtu, err := strconv.Atoi(args[2]) - if err != nil && args[3] != "" { - return fmt.Errorf("unable to parse mtu %q: %s", args[2], err) - } - cidrs, err := parseCIDRs(args[3:]) + cidrs, err := parseCIDRs(args[2:]) if err != nil { return err } - err = weavenet.AttachContainer(weavenet.NSPathByPid(pid), fmt.Sprint(pid), weavenet.VethName, args[1], mtu, withMulticastRoute, cidrs, keepTXOn, hairpinMode) + err = weavenet.AttachContainer(weavenet.NSPathByPid(pid), fmt.Sprint(pid), weavenet.VethName, args[1], 0, withMulticastRoute, cidrs, keepTXOn, hairpinMode) // If we detected an error but the container has died, tell the user that instead. if err != nil && !processExists(pid) { err = fmt.Errorf("Container %s died", args[0]) diff --git a/weave b/weave index f3f5a9c7..eccad81e 100755 --- a/weave +++ b/weave @@ -918,9 +918,7 @@ check_overlap() { } detect_awsvpc() { - # Ignoring errors here: if we cannot detect AWSVPC we will skip the relevant - # steps, because "attach" should work without the weave router running. - [ "$(call_weave GET /ipinfo/tracker)" != "awsvpc" ] || AWSVPC=1 + [ "$(call_weave GET /ipinfo/tracker 2>/dev/null)" != "awsvpc" ] || AWSVPC=1 } # Call IPAM as necessary to lookup or allocate addresses @@ -1436,7 +1434,6 @@ case "$COMMAND" in done [ $# -eq 1 ] || usage CONTAINER=$(util_op container-id $1) - create_bridge ipam_cidrs allocate $CONTAINER $CIDR_ARGS if [ -n "$REWRITE_HOSTS" ] ; then # rewrite /etc/hosts, unlinking the file (so Docker does @@ -1444,7 +1441,7 @@ case "$COMMAND" in util_op rewrite-etc-hosts "$CONTAINER" "$EXEC_IMAGE" "$ALL_CIDRS" $DNS_EXTRA_HOSTS fi [ -n "$AWSVPC" ] && ATTACH_ARGS="--no-multicast-route --keep-tx-on" - util_op attach-container $ATTACH_ARGS $CONTAINER $BRIDGE $MTU $ALL_CIDRS >/dev/null + util_op attach-container $ATTACH_ARGS $CONTAINER $BRIDGE $ALL_CIDRS >/dev/null [ -n "$WITHOUT_DNS" ] || when_weave_running with_container_fqdn $CONTAINER put_dns_fqdn $ALL_CIDRS show_addrs $ALL_CIDRS ;;