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.
This commit is contained in:
Martynas Pumputis committed 2017-12-16 21:17:45 +01:00
1 parent a71e90ddb8
commit 541adf6bb1
2 files changed
+6 -14

No files matched your search

+4 -9
View File
@@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"net" "net"
"os" "os"
"strconv"
"strings" "strings"
"syscall" "syscall"
@@ -15,8 +14,8 @@ import (
) )
func attach(args []string) error { func attach(args []string) error {
if len(args) < 4 { if len(args) < 3 {
cmdUsage("attach-container", "[--no-multicast-route] [--keep-tx-on] [--hairpin-mode=true|false] <container-id> <bridge-name> <mtu> <cidr>...") cmdUsage("attach-container", "[--no-multicast-route] [--keep-tx-on] [--hairpin-mode=true|false] <container-id> <bridge-name> <cidr>...")
} }
keepTXOn := false keepTXOn := false
@@ -52,16 +51,12 @@ func attach(args []string) error {
} else if nsHost.Equal(nsContainer) { } 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") 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]) cidrs, err := parseCIDRs(args[2:])
if err != nil && args[3] != "" {
return fmt.Errorf("unable to parse mtu %q: %s", args[2], err)
}
cidrs, err := parseCIDRs(args[3:])
if err != nil { if err != nil {
return err 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 we detected an error but the container has died, tell the user that instead.
if err != nil && !processExists(pid) { if err != nil && !processExists(pid) {
err = fmt.Errorf("Container %s died", args[0]) err = fmt.Errorf("Container %s died", args[0])
+2 -5
View File
@@ -918,9 +918,7 @@ check_overlap() {
} }
detect_awsvpc() { detect_awsvpc() {
# Ignoring errors here: if we cannot detect AWSVPC we will skip the relevant [ "$(call_weave GET /ipinfo/tracker 2>/dev/null)" != "awsvpc" ] || AWSVPC=1
# steps, because "attach" should work without the weave router running.
[ "$(call_weave GET /ipinfo/tracker)" != "awsvpc" ] || AWSVPC=1
} }
# Call IPAM as necessary to lookup or allocate addresses # Call IPAM as necessary to lookup or allocate addresses
@@ -1436,7 +1434,6 @@ case "$COMMAND" in
done done
[ $# -eq 1 ] || usage [ $# -eq 1 ] || usage
CONTAINER=$(util_op container-id $1) CONTAINER=$(util_op container-id $1)
create_bridge
ipam_cidrs allocate $CONTAINER $CIDR_ARGS ipam_cidrs allocate $CONTAINER $CIDR_ARGS
if [ -n "$REWRITE_HOSTS" ] ; then if [ -n "$REWRITE_HOSTS" ] ; then
# rewrite /etc/hosts, unlinking the file (so Docker does # 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 util_op rewrite-etc-hosts "$CONTAINER" "$EXEC_IMAGE" "$ALL_CIDRS" $DNS_EXTRA_HOSTS
fi fi
[ -n "$AWSVPC" ] && ATTACH_ARGS="--no-multicast-route --keep-tx-on" [ -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 [ -n "$WITHOUT_DNS" ] || when_weave_running with_container_fqdn $CONTAINER put_dns_fqdn $ALL_CIDRS
show_addrs $ALL_CIDRS show_addrs $ALL_CIDRS
;; ;;