From 9801e00ba60559cd87711dcff818280a974bc8c8 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Fri, 1 Jan 2016 19:29:37 +0000 Subject: [PATCH 1/5] add weaveutil just a placeholder for now --- .gitignore | 2 ++ Makefile | 9 ++++-- prog/weaveexec/Dockerfile | 2 +- prog/weaveutil/main.go | 58 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 prog/weaveutil/main.go diff --git a/.gitignore b/.gitignore index 4d5f7002..a2b647f6 100644 --- a/.gitignore +++ b/.gitignore @@ -41,6 +41,7 @@ prog/sigproxy/sigproxy prog/weavewait/weavewait prog/weavewait/weavewait_noop prog/weavewait/weavewait_nomcast +prog/weaveutil/weaveutil prog/netcheck/netcheck prog/docker_tls_args/docker_tls_args prog/plugin/plugin @@ -59,6 +60,7 @@ prog/weaveexec/weavewait prog/weaveexec/weavewait_noop prog/weaveexec/weavewait_nomcast prog/weaveexec/sigproxy +prog/weaveexec/weaveutil prog/weaveexec/netcheck prog/weaveexec/docker_tls_args prog/weaveexec/docker*.tgz diff --git a/Makefile b/Makefile index 29190932..b44bd237 100644 --- a/Makefile +++ b/Makefile @@ -15,13 +15,14 @@ SIGPROXY_EXE=prog/sigproxy/sigproxy WEAVEWAIT_EXE=prog/weavewait/weavewait WEAVEWAIT_NOOP_EXE=prog/weavewait/weavewait_noop WEAVEWAIT_NOMCAST_EXE=prog/weavewait/weavewait_nomcast +WEAVEUTIL_EXE=prog/weaveutil/weaveutil NETCHECK_EXE=prog/netcheck/netcheck DOCKERTLSARGS_EXE=prog/docker_tls_args/docker_tls_args DOCKERPLUGIN_EXE=prog/plugin/plugin RUNNER_EXE=tools/runner/runner TEST_TLS_EXE=test/tls/tls -EXES=$(WEAVER_EXE) $(SIGPROXY_EXE) $(WEAVEPROXY_EXE) $(WEAVEWAIT_EXE) $(WEAVEWAIT_NOOP_EXE) $(WEAVEWAIT_NOMCAST_EXE) $(NETCHECK_EXE) $(DOCKERTLSARGS_EXE) $(DOCKERPLUGIN_EXE) $(TEST_TLS_EXE) +EXES=$(WEAVER_EXE) $(SIGPROXY_EXE) $(WEAVEPROXY_EXE) $(WEAVEWAIT_EXE) $(WEAVEWAIT_NOOP_EXE) $(WEAVEWAIT_NOMCAST_EXE) $(WEAVEUTIL_EXE) $(NETCHECK_EXE) $(DOCKERTLSARGS_EXE) $(DOCKERPLUGIN_EXE) $(TEST_TLS_EXE) WEAVER_UPTODATE=.weaver.uptodate WEAVEEXEC_UPTODATE=.weaveexec.uptodate @@ -70,13 +71,14 @@ else endif $(NETGO_CHECK) -$(NETCHECK_EXE): common/*.go common/*/*.go net/*.go +$(WEAVEUTIL_EXE) $(NETCHECK_EXE): common/*.go common/*/*.go net/*.go go get -tags netgo ./$(@D) go build $(BUILD_FLAGS) -o $@ ./$(@D) $(NETGO_CHECK) $(WEAVER_EXE): router/*.go mesh/*.go ipam/*.go ipam/*/*.go nameserver/*.go prog/weaver/*.go $(WEAVEPROXY_EXE): proxy/*.go prog/weaveproxy/*.go +$(WEAVEUTIL_EXE): prog/weaveutil/*.go $(NETCHECK_EXE): prog/netcheck/*.go # These next programs need separate rules as they fail the netgo check in @@ -106,13 +108,14 @@ $(WEAVER_UPTODATE): prog/weaver/Dockerfile $(WEAVER_EXE) $(SUDO) DOCKER_HOST=$(DOCKER_HOST) docker build -t $(WEAVER_IMAGE) prog/weaver touch $@ -$(WEAVEEXEC_UPTODATE): prog/weaveexec/Dockerfile prog/weaveexec/symlink $(DOCKER_DISTRIB) weave $(SIGPROXY_EXE) $(WEAVEPROXY_EXE) $(WEAVEWAIT_EXE) $(WEAVEWAIT_NOOP_EXE) $(WEAVEWAIT_NOMCAST_EXE) $(NETCHECK_EXE) $(DOCKERTLSARGS_EXE) +$(WEAVEEXEC_UPTODATE): prog/weaveexec/Dockerfile prog/weaveexec/symlink $(DOCKER_DISTRIB) weave $(SIGPROXY_EXE) $(WEAVEPROXY_EXE) $(WEAVEWAIT_EXE) $(WEAVEWAIT_NOOP_EXE) $(WEAVEWAIT_NOMCAST_EXE) $(WEAVEUTIL_EXE) $(NETCHECK_EXE) $(DOCKERTLSARGS_EXE) cp weave prog/weaveexec/weave cp $(SIGPROXY_EXE) prog/weaveexec/sigproxy cp $(WEAVEPROXY_EXE) prog/weaveexec/weaveproxy cp $(WEAVEWAIT_EXE) prog/weaveexec/weavewait cp $(WEAVEWAIT_NOOP_EXE) prog/weaveexec/weavewait_noop cp $(WEAVEWAIT_NOMCAST_EXE) prog/weaveexec/weavewait_nomcast + cp $(WEAVEUTIL_EXE) prog/weaveexec/weaveutil cp $(NETCHECK_EXE) prog/weaveexec/netcheck cp $(DOCKERTLSARGS_EXE) prog/weaveexec/docker_tls_args cp $(DOCKER_DISTRIB) prog/weaveexec/docker.tgz diff --git a/prog/weaveexec/Dockerfile b/prog/weaveexec/Dockerfile index f700f20a..fd367dcd 100644 --- a/prog/weaveexec/Dockerfile +++ b/prog/weaveexec/Dockerfile @@ -20,7 +20,7 @@ RUN apk add --update \ && rm -rf /var/cache/apk/* ADD ./weave ./sigproxy ./weaveproxy ./symlink /home/weave/ -ADD ./netcheck ./docker_tls_args /usr/bin/ +ADD ./weaveutil ./netcheck ./docker_tls_args /usr/bin/ ADD ./weavewait /w/w ADD ./weavewait_noop /w-noop/w ADD ./weavewait_nomcast /w-nomcast/w diff --git a/prog/weaveutil/main.go b/prog/weaveutil/main.go new file mode 100644 index 00000000..be58423e --- /dev/null +++ b/prog/weaveutil/main.go @@ -0,0 +1,58 @@ +/* weaveutil: collection of operations required by weave script */ +package main + +import ( + "fmt" + "os" + + weavenet "github.com/weaveworks/weave/net" +) + +var f = weavenet.EnsureInterface // placeholder to force inclusion of 'net' + +var commands map[string]func([]string) error + +func init() { + commands = map[string]func([]string) error{ + "help": help, + } +} + +func main() { + if len(os.Args) < 2 { + usage() + os.Exit(1) + } + cmd, found := commands[os.Args[1]] + if !found { + usage() + os.Exit(1) + } + if err := cmd(os.Args[2:]); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } +} + +func help(args []string) error { + if len(args) > 0 { + cmdUsage("help", "") + } + usage() + return nil +} + +func usage() { + fmt.Fprintln(os.Stderr, "usage: weaveutil ...") + fmt.Fprintln(os.Stderr) + fmt.Fprintln(os.Stderr, "where is one of:") + fmt.Fprintln(os.Stderr) + for cmd := range commands { + fmt.Fprintln(os.Stderr, cmd) + } +} + +func cmdUsage(cmd string, usage string) { + fmt.Fprintf(os.Stderr, "usage: weaveutil %s %s\n", cmd, usage) + os.Exit(1) +} From ec872d7b45cbd72062401e391886a6281ab48308 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Fri, 1 Jan 2016 21:37:25 +0000 Subject: [PATCH 2/5] move netcheck into weaveutil --- .gitignore | 2 -- Makefile | 9 +++---- prog/netcheck/main.go | 54 -------------------------------------- prog/weaveexec/Dockerfile | 2 +- prog/weaveutil/main.go | 7 ++--- prog/weaveutil/netcheck.go | 28 ++++++++++++++++++++ weave | 2 +- 7 files changed, 35 insertions(+), 69 deletions(-) delete mode 100644 prog/netcheck/main.go create mode 100644 prog/weaveutil/netcheck.go diff --git a/.gitignore b/.gitignore index a2b647f6..8277a2f7 100644 --- a/.gitignore +++ b/.gitignore @@ -42,7 +42,6 @@ prog/weavewait/weavewait prog/weavewait/weavewait_noop prog/weavewait/weavewait_nomcast prog/weaveutil/weaveutil -prog/netcheck/netcheck prog/docker_tls_args/docker_tls_args prog/plugin/plugin testing/cover/cover @@ -61,7 +60,6 @@ prog/weaveexec/weavewait_noop prog/weaveexec/weavewait_nomcast prog/weaveexec/sigproxy prog/weaveexec/weaveutil -prog/weaveexec/netcheck prog/weaveexec/docker_tls_args prog/weaveexec/docker*.tgz Vagrantfile.local diff --git a/Makefile b/Makefile index b44bd237..321a6740 100644 --- a/Makefile +++ b/Makefile @@ -16,13 +16,12 @@ WEAVEWAIT_EXE=prog/weavewait/weavewait WEAVEWAIT_NOOP_EXE=prog/weavewait/weavewait_noop WEAVEWAIT_NOMCAST_EXE=prog/weavewait/weavewait_nomcast WEAVEUTIL_EXE=prog/weaveutil/weaveutil -NETCHECK_EXE=prog/netcheck/netcheck DOCKERTLSARGS_EXE=prog/docker_tls_args/docker_tls_args DOCKERPLUGIN_EXE=prog/plugin/plugin RUNNER_EXE=tools/runner/runner TEST_TLS_EXE=test/tls/tls -EXES=$(WEAVER_EXE) $(SIGPROXY_EXE) $(WEAVEPROXY_EXE) $(WEAVEWAIT_EXE) $(WEAVEWAIT_NOOP_EXE) $(WEAVEWAIT_NOMCAST_EXE) $(WEAVEUTIL_EXE) $(NETCHECK_EXE) $(DOCKERTLSARGS_EXE) $(DOCKERPLUGIN_EXE) $(TEST_TLS_EXE) +EXES=$(WEAVER_EXE) $(SIGPROXY_EXE) $(WEAVEPROXY_EXE) $(WEAVEWAIT_EXE) $(WEAVEWAIT_NOOP_EXE) $(WEAVEWAIT_NOMCAST_EXE) $(WEAVEUTIL_EXE) $(DOCKERTLSARGS_EXE) $(DOCKERPLUGIN_EXE) $(TEST_TLS_EXE) WEAVER_UPTODATE=.weaver.uptodate WEAVEEXEC_UPTODATE=.weaveexec.uptodate @@ -71,7 +70,7 @@ else endif $(NETGO_CHECK) -$(WEAVEUTIL_EXE) $(NETCHECK_EXE): common/*.go common/*/*.go net/*.go +$(WEAVEUTIL_EXE): common/*.go common/*/*.go net/*.go go get -tags netgo ./$(@D) go build $(BUILD_FLAGS) -o $@ ./$(@D) $(NETGO_CHECK) @@ -79,7 +78,6 @@ $(WEAVEUTIL_EXE) $(NETCHECK_EXE): common/*.go common/*/*.go net/*.go $(WEAVER_EXE): router/*.go mesh/*.go ipam/*.go ipam/*/*.go nameserver/*.go prog/weaver/*.go $(WEAVEPROXY_EXE): proxy/*.go prog/weaveproxy/*.go $(WEAVEUTIL_EXE): prog/weaveutil/*.go -$(NETCHECK_EXE): prog/netcheck/*.go # These next programs need separate rules as they fail the netgo check in # the main build stanza due to not importing net package @@ -108,7 +106,7 @@ $(WEAVER_UPTODATE): prog/weaver/Dockerfile $(WEAVER_EXE) $(SUDO) DOCKER_HOST=$(DOCKER_HOST) docker build -t $(WEAVER_IMAGE) prog/weaver touch $@ -$(WEAVEEXEC_UPTODATE): prog/weaveexec/Dockerfile prog/weaveexec/symlink $(DOCKER_DISTRIB) weave $(SIGPROXY_EXE) $(WEAVEPROXY_EXE) $(WEAVEWAIT_EXE) $(WEAVEWAIT_NOOP_EXE) $(WEAVEWAIT_NOMCAST_EXE) $(WEAVEUTIL_EXE) $(NETCHECK_EXE) $(DOCKERTLSARGS_EXE) +$(WEAVEEXEC_UPTODATE): prog/weaveexec/Dockerfile prog/weaveexec/symlink $(DOCKER_DISTRIB) weave $(SIGPROXY_EXE) $(WEAVEPROXY_EXE) $(WEAVEWAIT_EXE) $(WEAVEWAIT_NOOP_EXE) $(WEAVEWAIT_NOMCAST_EXE) $(WEAVEUTIL_EXE) $(DOCKERTLSARGS_EXE) cp weave prog/weaveexec/weave cp $(SIGPROXY_EXE) prog/weaveexec/sigproxy cp $(WEAVEPROXY_EXE) prog/weaveexec/weaveproxy @@ -116,7 +114,6 @@ $(WEAVEEXEC_UPTODATE): prog/weaveexec/Dockerfile prog/weaveexec/symlink $(DOCKER cp $(WEAVEWAIT_NOOP_EXE) prog/weaveexec/weavewait_noop cp $(WEAVEWAIT_NOMCAST_EXE) prog/weaveexec/weavewait_nomcast cp $(WEAVEUTIL_EXE) prog/weaveexec/weaveutil - cp $(NETCHECK_EXE) prog/weaveexec/netcheck cp $(DOCKERTLSARGS_EXE) prog/weaveexec/docker_tls_args cp $(DOCKER_DISTRIB) prog/weaveexec/docker.tgz $(SUDO) DOCKER_HOST=$(DOCKER_HOST) docker build -t $(WEAVEEXEC_IMAGE) prog/weaveexec diff --git a/prog/netcheck/main.go b/prog/netcheck/main.go deleted file mode 100644 index fe822f2e..00000000 --- a/prog/netcheck/main.go +++ /dev/null @@ -1,54 +0,0 @@ -/* netcheck: check whether a given network or address overlaps with any existing routes */ -package main - -import ( - "fmt" - "net" - "os" - - "github.com/docker/docker/pkg/mflag" - weavenet "github.com/weaveworks/weave/net" -) - -func fatal(err error) { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) -} - -type stringList map[string]struct{} - -func (ss *stringList) Set(value string) error { - (*ss)[value] = struct{}{} - return nil -} - -func (ss *stringList) String() string { - return fmt.Sprintf("%v", *ss) -} - -func main() { - ignoreIfaceNames := make(stringList) - - mflag.Var(&ignoreIfaceNames, []string{"-ignore-iface"}, "name of interface to ignore)") - mflag.Parse() - - if len(mflag.Args()) < 1 { - fmt.Fprintln(os.Stderr, "usage: netcheck [--ignore-iface ] network-cidr") - os.Exit(1) - } - - cidrStr := mflag.Args()[0] - addr, ipnet, err := net.ParseCIDR(cidrStr) - if err != nil { - fatal(err) - } - if ipnet.IP.Equal(addr) { - err = weavenet.CheckNetworkFree(ipnet, ignoreIfaceNames) - } else { - err = weavenet.CheckAddressOverlap(addr, ignoreIfaceNames) - } - if err != nil { - fatal(err) - } - os.Exit(0) -} diff --git a/prog/weaveexec/Dockerfile b/prog/weaveexec/Dockerfile index fd367dcd..353018f2 100644 --- a/prog/weaveexec/Dockerfile +++ b/prog/weaveexec/Dockerfile @@ -20,7 +20,7 @@ RUN apk add --update \ && rm -rf /var/cache/apk/* ADD ./weave ./sigproxy ./weaveproxy ./symlink /home/weave/ -ADD ./weaveutil ./netcheck ./docker_tls_args /usr/bin/ +ADD ./weaveutil ./docker_tls_args /usr/bin/ ADD ./weavewait /w/w ADD ./weavewait_noop /w-noop/w ADD ./weavewait_nomcast /w-nomcast/w diff --git a/prog/weaveutil/main.go b/prog/weaveutil/main.go index be58423e..0fe4b4d1 100644 --- a/prog/weaveutil/main.go +++ b/prog/weaveutil/main.go @@ -4,17 +4,14 @@ package main import ( "fmt" "os" - - weavenet "github.com/weaveworks/weave/net" ) -var f = weavenet.EnsureInterface // placeholder to force inclusion of 'net' - var commands map[string]func([]string) error func init() { commands = map[string]func([]string) error{ - "help": help, + "help": help, + "netcheck": netcheck, } } diff --git a/prog/weaveutil/netcheck.go b/prog/weaveutil/netcheck.go new file mode 100644 index 00000000..843fab22 --- /dev/null +++ b/prog/weaveutil/netcheck.go @@ -0,0 +1,28 @@ +/* netcheck: check whether a given network or address overlaps with any existing routes */ +package main + +import ( + "net" + + weavenet "github.com/weaveworks/weave/net" +) + +func netcheck(args []string) error { + if len(args) < 1 { + cmdUsage("netcheck", " [ ...]") + } + addr, ipnet, err := net.ParseCIDR(args[0]) + if err != nil { + return err + } + ignoreIfaceNames := make(map[string]struct{}) + for _, ifName := range args[1:] { + ignoreIfaceNames[ifName] = struct{}{} + } + if ipnet.IP.Equal(addr) { + err = weavenet.CheckNetworkFree(ipnet, ignoreIfaceNames) + } else { + err = weavenet.CheckAddressOverlap(addr, ignoreIfaceNames) + } + return err +} diff --git a/weave b/weave index 089b0153..ffe8571b 100755 --- a/weave +++ b/weave @@ -1251,7 +1251,7 @@ collect_dns_add_remove_args() { ###################################################################### check_overlap() { - ! command_exists netcheck || netcheck --ignore-iface=$BRIDGE $1 + ! command_exists weaveutil || weaveutil netcheck $1 $BRIDGE } # Claim addresses for a container in IPAM. Expects to be called from From 4ebcd355f652d3c45bfc34c7c8dc72290351b37a Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sat, 2 Jan 2016 11:15:32 +0000 Subject: [PATCH 3/5] move docker_tls_args into weaveutil and also give users a clue what went wrong when docker isn't running --- .gitignore | 2 -- Makefile | 9 +++----- prog/weaveexec/Dockerfile | 2 +- .../main.go => weaveutil/docker_tls_args.go} | 21 ++++++++----------- prog/weaveutil/main.go | 5 +++-- weave | 4 ++-- 6 files changed, 18 insertions(+), 25 deletions(-) rename prog/{docker_tls_args/main.go => weaveutil/docker_tls_args.go} (88%) diff --git a/.gitignore b/.gitignore index 8277a2f7..9a5aa837 100644 --- a/.gitignore +++ b/.gitignore @@ -42,7 +42,6 @@ prog/weavewait/weavewait prog/weavewait/weavewait_noop prog/weavewait/weavewait_nomcast prog/weaveutil/weaveutil -prog/docker_tls_args/docker_tls_args prog/plugin/plugin testing/cover/cover testing/runner/runner @@ -60,7 +59,6 @@ prog/weaveexec/weavewait_noop prog/weaveexec/weavewait_nomcast prog/weaveexec/sigproxy prog/weaveexec/weaveutil -prog/weaveexec/docker_tls_args prog/weaveexec/docker*.tgz Vagrantfile.local test/tls/tls diff --git a/Makefile b/Makefile index 321a6740..57e1fffb 100644 --- a/Makefile +++ b/Makefile @@ -16,12 +16,11 @@ WEAVEWAIT_EXE=prog/weavewait/weavewait WEAVEWAIT_NOOP_EXE=prog/weavewait/weavewait_noop WEAVEWAIT_NOMCAST_EXE=prog/weavewait/weavewait_nomcast WEAVEUTIL_EXE=prog/weaveutil/weaveutil -DOCKERTLSARGS_EXE=prog/docker_tls_args/docker_tls_args DOCKERPLUGIN_EXE=prog/plugin/plugin RUNNER_EXE=tools/runner/runner TEST_TLS_EXE=test/tls/tls -EXES=$(WEAVER_EXE) $(SIGPROXY_EXE) $(WEAVEPROXY_EXE) $(WEAVEWAIT_EXE) $(WEAVEWAIT_NOOP_EXE) $(WEAVEWAIT_NOMCAST_EXE) $(WEAVEUTIL_EXE) $(DOCKERTLSARGS_EXE) $(DOCKERPLUGIN_EXE) $(TEST_TLS_EXE) +EXES=$(WEAVER_EXE) $(SIGPROXY_EXE) $(WEAVEPROXY_EXE) $(WEAVEWAIT_EXE) $(WEAVEWAIT_NOOP_EXE) $(WEAVEWAIT_NOMCAST_EXE) $(WEAVEUTIL_EXE) $(DOCKERPLUGIN_EXE) $(TEST_TLS_EXE) WEAVER_UPTODATE=.weaver.uptodate WEAVEEXEC_UPTODATE=.weaveexec.uptodate @@ -82,11 +81,10 @@ $(WEAVEUTIL_EXE): prog/weaveutil/*.go # These next programs need separate rules as they fail the netgo check in # the main build stanza due to not importing net package $(SIGPROXY_EXE): prog/sigproxy/*.go -$(DOCKERTLSARGS_EXE): prog/docker_tls_args/*.go $(DOCKERPLUGIN_EXE): prog/plugin/*.go plugin/net/*.go plugin/ipam/*.go plugin/skel/*.go api/*.go common/docker/*.go $(TEST_TLS_EXE): test/tls/*.go -$(SIGPROXY_EXE) $(DOCKERTLSARGS_EXE) $(DOCKERPLUGIN_EXE) $(TEST_TLS_EXE): +$(SIGPROXY_EXE) $(DOCKERPLUGIN_EXE) $(TEST_TLS_EXE): go get -tags netgo ./$(@D) go build $(BUILD_FLAGS) -o $@ ./$(@D) @@ -106,7 +104,7 @@ $(WEAVER_UPTODATE): prog/weaver/Dockerfile $(WEAVER_EXE) $(SUDO) DOCKER_HOST=$(DOCKER_HOST) docker build -t $(WEAVER_IMAGE) prog/weaver touch $@ -$(WEAVEEXEC_UPTODATE): prog/weaveexec/Dockerfile prog/weaveexec/symlink $(DOCKER_DISTRIB) weave $(SIGPROXY_EXE) $(WEAVEPROXY_EXE) $(WEAVEWAIT_EXE) $(WEAVEWAIT_NOOP_EXE) $(WEAVEWAIT_NOMCAST_EXE) $(WEAVEUTIL_EXE) $(DOCKERTLSARGS_EXE) +$(WEAVEEXEC_UPTODATE): prog/weaveexec/Dockerfile prog/weaveexec/symlink $(DOCKER_DISTRIB) weave $(SIGPROXY_EXE) $(WEAVEPROXY_EXE) $(WEAVEWAIT_EXE) $(WEAVEWAIT_NOOP_EXE) $(WEAVEWAIT_NOMCAST_EXE) $(WEAVEUTIL_EXE) cp weave prog/weaveexec/weave cp $(SIGPROXY_EXE) prog/weaveexec/sigproxy cp $(WEAVEPROXY_EXE) prog/weaveexec/weaveproxy @@ -114,7 +112,6 @@ $(WEAVEEXEC_UPTODATE): prog/weaveexec/Dockerfile prog/weaveexec/symlink $(DOCKER cp $(WEAVEWAIT_NOOP_EXE) prog/weaveexec/weavewait_noop cp $(WEAVEWAIT_NOMCAST_EXE) prog/weaveexec/weavewait_nomcast cp $(WEAVEUTIL_EXE) prog/weaveexec/weaveutil - cp $(DOCKERTLSARGS_EXE) prog/weaveexec/docker_tls_args cp $(DOCKER_DISTRIB) prog/weaveexec/docker.tgz $(SUDO) DOCKER_HOST=$(DOCKER_HOST) docker build -t $(WEAVEEXEC_IMAGE) prog/weaveexec touch $@ diff --git a/prog/weaveexec/Dockerfile b/prog/weaveexec/Dockerfile index 353018f2..1e916e4c 100644 --- a/prog/weaveexec/Dockerfile +++ b/prog/weaveexec/Dockerfile @@ -20,7 +20,7 @@ RUN apk add --update \ && rm -rf /var/cache/apk/* ADD ./weave ./sigproxy ./weaveproxy ./symlink /home/weave/ -ADD ./weaveutil ./docker_tls_args /usr/bin/ +ADD ./weaveutil /usr/bin/ ADD ./weavewait /w/w ADD ./weavewait_noop /w-noop/w ADD ./weavewait_nomcast /w-nomcast/w diff --git a/prog/docker_tls_args/main.go b/prog/weaveutil/docker_tls_args.go similarity index 88% rename from prog/docker_tls_args/main.go rename to prog/weaveutil/docker_tls_args.go index 37c747a5..a61ab8ce 100644 --- a/prog/docker_tls_args/main.go +++ b/prog/weaveutil/docker_tls_args.go @@ -13,14 +13,18 @@ import ( "strings" ) -func main() { +func dockerTLSArgs(args []string) error { + if len(args) > 0 { + cmdUsage("docker-tls-args", "") + } procRoot := os.Getenv("PROCFS") if procRoot == "" { procRoot = "/proc" } - dirEntries, err := ioutil.ReadDir(procRoot) - checkErr(err) + if err != nil { + return err + } for _, dirEntry := range dirEntries { dirName := dirEntry.Name() @@ -63,15 +67,8 @@ func main() { } fmt.Println(strings.Join(tlsArgs, " ")) - os.Exit(0) + return nil } - os.Exit(1) -} - -func checkErr(err error) { - if err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } + return fmt.Errorf("cannot locate running docker daemon") } diff --git a/prog/weaveutil/main.go b/prog/weaveutil/main.go index 0fe4b4d1..2d1aed8c 100644 --- a/prog/weaveutil/main.go +++ b/prog/weaveutil/main.go @@ -10,8 +10,9 @@ var commands map[string]func([]string) error func init() { commands = map[string]func([]string) error{ - "help": help, - "netcheck": netcheck, + "help": help, + "netcheck": netcheck, + "docker-tls-args": dockerTLSArgs, } } diff --git a/weave b/weave index ffe8571b..7dda1a26 100755 --- a/weave +++ b/weave @@ -1434,8 +1434,8 @@ proxy_args() { PROXY_HOST="" proxy_parse_args "$@" - if [ -z "$PROXY_TLS_ENABLED" -a -z "$PROXY_TLS_DETECTION_DISABLED" ] && command_exists docker_tls_args ; then - if ! DOCKER_TLS_ARGS=$(docker_tls_args) ; then + if [ -z "$PROXY_TLS_ENABLED" -a -z "$PROXY_TLS_DETECTION_DISABLED" ] && command_exists weaveutil ; then + if ! DOCKER_TLS_ARGS=$(weaveutil docker-tls-args) ; then echo "Unable to auto-detect proxy TLS configuration; you must launch the proxy with" >&2 echo "'weave launch-proxy' and supply '--no-detect-tls' or TLS options." >&2 exit 1 From 419f2ff71bb4bf5fc00ae5a45ec599f8fbc13e6d Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sat, 2 Jan 2016 13:40:07 +0000 Subject: [PATCH 4/5] move fastdp helpers into weaveutil so the weave script can invoke them w/o having to run a container --- prog/weaver/main.go | 39 ++------------------------------------ prog/weaveutil/datapath.go | 39 ++++++++++++++++++++++++++++++++++++++ prog/weaveutil/main.go | 9 ++++++--- weave | 8 ++++++-- 4 files changed, 53 insertions(+), 42 deletions(-) create mode 100644 prog/weaveutil/datapath.go diff --git a/prog/weaver/main.go b/prog/weaver/main.go index a1a81a8c..a50eda64 100644 --- a/prog/weaver/main.go +++ b/prog/weaver/main.go @@ -16,7 +16,6 @@ import ( . "github.com/weaveworks/weave/common" "github.com/weaveworks/weave/common/docker" - "github.com/weaveworks/weave/common/odp" "github.com/weaveworks/weave/ipam" "github.com/weaveworks/weave/mesh" "github.com/weaveworks/weave/nameserver" @@ -37,12 +36,7 @@ func main() { runtime.GOMAXPROCS(procs) var ( - // flags that cause immediate exit - justVersion bool - createDatapath bool - deleteDatapath bool - addDatapathInterface string - + justVersion bool config mesh.Config networkConfig weave.NetworkConfig protocolMinVersion int @@ -79,10 +73,6 @@ func main() { } mflag.BoolVar(&justVersion, []string{"#version", "-version"}, false, "print version and exit") - mflag.BoolVar(&createDatapath, []string{"-create-datapath"}, false, "create ODP datapath and exit") - mflag.BoolVar(&deleteDatapath, []string{"-delete-datapath"}, false, "delete ODP datapath and exit") - mflag.StringVar(&addDatapathInterface, []string{"-add-datapath-iface"}, "", "add a network interface to the ODP datapath and exit") - mflag.IntVar(&config.Port, []string{"#port", "-port"}, mesh.Port, "router port") mflag.IntVar(&protocolMinVersion, []string{"-min-protocol-version"}, mesh.ProtocolMinVersion, "minimum weave protocol version") mflag.StringVar(&ifaceName, []string{"#iface", "-iface"}, "", "name of interface to capture/inject from (disabled if blank)") @@ -124,34 +114,9 @@ func main() { SetLogLevel(logLevel) - switch { - case justVersion: + if justVersion { fmt.Printf("weave router %s\n", version) os.Exit(0) - - case createDatapath: - odpSupported, err := odp.CreateDatapath(datapathName) - if !odpSupported { - if err != nil { - Log.Error(err) - } - - // When the kernel lacks ODP support, exit - // with a special status to distinguish it for - // the weave script. - os.Exit(17) - } - - checkFatal(err) - os.Exit(0) - - case deleteDatapath: - checkFatal(odp.DeleteDatapath(datapathName)) - os.Exit(0) - - case addDatapathInterface != "": - checkFatal(odp.AddDatapathInterface(datapathName, addDatapathInterface)) - os.Exit(0) } Log.Println("Command line options:", options()) diff --git a/prog/weaveutil/datapath.go b/prog/weaveutil/datapath.go new file mode 100644 index 00000000..f4494967 --- /dev/null +++ b/prog/weaveutil/datapath.go @@ -0,0 +1,39 @@ +// various fastdp operations +package main + +import ( + "fmt" + "os" + + "github.com/weaveworks/weave/common/odp" +) + +func createDatapath(args []string) error { + if len(args) != 1 { + cmdUsage("create-datapath", "") + } + odpSupported, err := odp.CreateDatapath(args[0]) + if !odpSupported { + if err != nil { + fmt.Fprintln(os.Stderr, err) + } + // When the kernel lacks ODP support, exit with a special + // status to distinguish it for the weave script. + os.Exit(17) + } + return err +} + +func deleteDatapath(args []string) error { + if len(args) != 1 { + cmdUsage("delete-datapath", "") + } + return odp.DeleteDatapath(args[0]) +} + +func addDatapathInterface(args []string) error { + if len(args) != 2 { + cmdUsage("add-datapath-interface", " ") + } + return odp.AddDatapathInterface(args[0], args[1]) +} diff --git a/prog/weaveutil/main.go b/prog/weaveutil/main.go index 2d1aed8c..539e5c89 100644 --- a/prog/weaveutil/main.go +++ b/prog/weaveutil/main.go @@ -10,9 +10,12 @@ var commands map[string]func([]string) error func init() { commands = map[string]func([]string) error{ - "help": help, - "netcheck": netcheck, - "docker-tls-args": dockerTLSArgs, + "help": help, + "netcheck": netcheck, + "docker-tls-args": dockerTLSArgs, + "create-datapath": createDatapath, + "delete-datapath": deleteDatapath, + "add-datapath-interface": addDatapathInterface, } } diff --git a/weave b/weave index 7dda1a26..f86595f7 100755 --- a/weave +++ b/weave @@ -445,7 +445,11 @@ random_mac() { ###################################################################### fastdp_op() { - docker run --rm --privileged --net=host $IMAGE $COVERAGE_ARGS --$1 --datapath=$2 + if command_exists weaveutil ; then + weaveutil "$@" + else + docker run --rm --privileged --net=host --entrypoint=/usr/bin/weaveutil $EXEC_IMAGE "$@" + fi } # Detect the current bridge/datapath state. When invoked, the values of @@ -764,7 +768,7 @@ connect_container_to_bridge() { } add_iface_fastdp() { - fastdp_op add-datapath-iface=$1 $DATAPATH + fastdp_op add-datapath-interface $DATAPATH $1 } add_iface_bridge() { From d010000583b4ec8f3f742ae1e12c13e5dbb647df Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sat, 2 Jan 2016 12:05:29 +0000 Subject: [PATCH 5/5] fall back to invoking weaveutil in a container As a result, `weave --local ...` now runs both netcheck and docker-tls-args. --- weave | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/weave b/weave index f86595f7..465f8094 100755 --- a/weave +++ b/weave @@ -444,11 +444,12 @@ random_mac() { # weave and docker specific helpers ###################################################################### -fastdp_op() { +util_op() { if command_exists weaveutil ; then weaveutil "$@" else - docker run --rm --privileged --net=host --entrypoint=/usr/bin/weaveutil $EXEC_IMAGE "$@" + docker run --rm --privileged --net=host -v /proc:/hostproc -e PROCFS=/hostproc \ + --entrypoint=/usr/bin/weaveutil $EXEC_IMAGE "$@" fi } @@ -493,7 +494,7 @@ create_bridge() { # The datapath is the bridge when there is no intermediary DATAPATH="$BRIDGE" fi - if fastdp_op create-datapath $DATAPATH ; then + if util_op create-datapath $DATAPATH ; then : # ODP datapath created successfully elif [ $? = 17 ] ; then # Exit status of 17 means the kernel doesn't have ODP @@ -619,7 +620,7 @@ init_bridged_fastdp() { ip link del $BRIDGE >/dev/null 2>&1 || true ip link del $DATAPATH_IFNAME >/dev/null 2>&1 || true ip link del $BRIDGE_IFNAME >/dev/null 2>&1 || true - fastdp_op delete-datapath $DATAPATH >/dev/null 2>&1 || true + util_op delete-datapath $DATAPATH >/dev/null 2>&1 || true return 1 fi @@ -649,7 +650,7 @@ destroy_bridge() { if [ -d /sys/class/net/$NETDEV/bridge ] ; then ip link del $NETDEV else - fastdp_op delete-datapath $NETDEV + util_op delete-datapath $NETDEV fi fi done @@ -768,7 +769,7 @@ connect_container_to_bridge() { } add_iface_fastdp() { - fastdp_op add-datapath-interface $DATAPATH $1 + util_op add-datapath-interface $DATAPATH $1 } add_iface_bridge() { @@ -1255,7 +1256,7 @@ collect_dns_add_remove_args() { ###################################################################### check_overlap() { - ! command_exists weaveutil || weaveutil netcheck $1 $BRIDGE + util_op netcheck $1 $BRIDGE } # Claim addresses for a container in IPAM. Expects to be called from @@ -1438,8 +1439,8 @@ proxy_args() { PROXY_HOST="" proxy_parse_args "$@" - if [ -z "$PROXY_TLS_ENABLED" -a -z "$PROXY_TLS_DETECTION_DISABLED" ] && command_exists weaveutil ; then - if ! DOCKER_TLS_ARGS=$(weaveutil docker-tls-args) ; then + if [ -z "$PROXY_TLS_ENABLED" -a -z "$PROXY_TLS_DETECTION_DISABLED" ] ; then + if ! DOCKER_TLS_ARGS=$(util_op docker-tls-args) ; then echo "Unable to auto-detect proxy TLS configuration; you must launch the proxy with" >&2 echo "'weave launch-proxy' and supply '--no-detect-tls' or TLS options." >&2 exit 1