Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: weaveworks/weave
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f132eacae9f2ab08c1bb7c87db8ccbc162e84b6b
Choose a base ref
..
head repository: weaveworks/weave
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 10f5b761454cf323ba8ff675f92d8f7659110d94
Choose a head ref
39 changes: 22 additions & 17 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
@@ -89,6 +89,9 @@ func (proxy *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {

func (proxy *Proxy) ListenAndServe() {
errs := make(chan error)
for _, addr := range proxy.ListenAddrs {
Info.Println("proxy listening on", addr)
}
for _, addr := range proxy.ListenAddrs {
go func(addr string) {
errs <- proxy.listenAndServe(addr)
@@ -123,21 +126,24 @@ func copyOwnerAndPermissions(from, to string) error {
return nil
}

func (proxy *Proxy) listenAndServe(addr string) error {
protoAddrParts := strings.SplitN(addr, "://", 2)
if len(protoAddrParts) != 2 {
Error.Fatalf("Invalid protocol format: %q", addr)
return nil
}

func (proxy *Proxy) listenAndServe(protoAndAddr string) error {
var (
listener net.Listener
err error
listener net.Listener
err error
proto, addr string
)

switch protoAddrParts[0] {
if protoAddrParts := strings.SplitN(protoAndAddr, "://", 2); len(protoAddrParts) == 2 {
proto, addr = protoAddrParts[0], protoAddrParts[1]
} else if strings.HasPrefix(protoAndAddr, "/") {
proto, addr = "unix", protoAndAddr
} else {
proto, addr = "tcp", protoAndAddr
}

switch proto {
case "tcp":
listener, err = net.Listen(protoAddrParts[0], protoAddrParts[1])
listener, err = net.Listen(proto, addr)
if err != nil {
return err
}
@@ -146,21 +152,20 @@ func (proxy *Proxy) listenAndServe(addr string) error {
}

case "unix":
os.Remove(protoAddrParts[1]) // remove socket from last invocation
listener, err = net.Listen(protoAddrParts[0], protoAddrParts[1])
os.Remove(addr) // remove socket from last invocation
listener, err = net.Listen(proto, addr)
if err != nil {
return err
}
defer os.Remove(protoAddrParts[1])
if err = copyOwnerAndPermissions(dockerSock, protoAddrParts[1]); err != nil {
defer os.Remove(addr)
if err = copyOwnerAndPermissions(dockerSock, addr); err != nil {
return err
}

default:
Error.Fatalf("Invalid protocol format: %q", protoAddrParts[0])
Error.Fatalf("Invalid protocol format: %q", proto)
}

Info.Println("proxy listening on", addr)
return (&http.Server{Handler: proxy}).Serve(listener)
}

2 changes: 0 additions & 2 deletions site/features.md
Original file line number Diff line number Diff line change
@@ -141,10 +141,8 @@ Let's begin by configuring weave's allocator to manage multiple
subnets:

host1$ weave launch -iprange 10.2.0.0/16 -ipsubnet 10.2.1.0/24
host1$ weave launch-dns && weave launch-proxy
host1$ eval $(weave proxy-env)
host2$ weave launch -iprange 10.2.0.0/16 -ipsubnet 10.2.1.0/24 $HOST1
host2$ weave launch-dns && weave launch-proxy
host2$ eval $(weave proxy-env)

This delegates the entire 10.2.0.0/16 subnet to weave, and instructs
21 changes: 15 additions & 6 deletions site/proxy.md
Original file line number Diff line number Diff line change
@@ -23,14 +23,21 @@ instead of `weave run`.
## <a name="setup"></a>Setup

The proxy sits between the Docker client (command line or API) and the
Docker daemon, intercepting the communication between the two.
Docker daemon, intercepting the communication between the two. You can
start it simultaneously with the router and weaveDNS via `launch`:

To start the proxy, run
host1$ weave launch

host1$ weave launch-proxy
or independently via `launch-proxy`:

By default, the proxy listens on port 12375, on all network
interfaces. This can be adjusted with the `-H` argument, e.g.
host1$ weave launch-router && weave launch-dns && weave launch-proxy

The first form is more convenient, however you can only pass proxy
related configuration arguments to `launch-proxy` so if you need to
modify the default behaviour you will have to use the latter.

By default, the proxy listens on /var/run/weave.sock and port 12375, on
all network interfaces. This can be adjusted with the `-H` argument, e.g.

host1$ weave launch-proxy -H tcp://127.0.0.1:9999

@@ -49,10 +56,12 @@ Alternatively, the proxy host can be set on a per-command basis with

host1$ docker $(weave proxy-config) ps

The proxy can be stopped with
The proxy can be stopped independently with

host1$ weave stop-proxy

or in conjunction with the router and weaveDNS via `stop`.

If you set your `DOCKER_HOST` to point at the proxy, remember to
revert to the original setting.

24 changes: 19 additions & 5 deletions site/weavedns.md
Original file line number Diff line number Diff line change
@@ -28,13 +28,23 @@ hosts.

WeaveDNS is deployed as a set of containers that communicate with each
other over the weave network. One such container needs to be started
on every weave host, by invoking the weave script command
`launch-dns`:
on every weave host, either simultaneously with the router and proxy
via `launch`:

```bash
host1$ weave launch && weave launch-dns && weave launch-proxy
host1$ weave launch
host1$ eval $(weave proxy-env)
```
or independently via `launch-dns`:

```bash
host1$ weave launch-router && weave launch-dns && weave launch-proxy
host1$ eval $(weave proxy-env)
```

The first form is more convenient, however you can only pass weaveDNS
related configuration arguments to `launch-dns` so if you need to
modify the default behaviour you will have to use the latter.

Application containers will use weaveDNS automatically if it is
running at the point when they are started. They will use it for name
@@ -67,7 +77,11 @@ however specify an address in CIDR format manually. In this case you
are responsible for ensuring that the IP addresses specified are
uniquely allocated and not in use by any other container.

Finally, WeaveDNS containers can be stopped with `stop-dns`.
Finally, weaveDNS can be stopped independently with

host1$ weave stop-dns

or in conjunction with the router and proxy via `stop`.

## <a name="how-it-works"></a>How it works

@@ -112,7 +126,7 @@ Returning to our earlier example, let us start an additional `pingme`
container, this time on the 2nd host, and then run some ping tests...

```bash
host2$ weave launch && weave launch-dns && weave launch-proxy
host2$ weave launch
host2$ eval $(weave proxy-env)
host2$ docker run -dti --name=pingme ubuntu

8 changes: 4 additions & 4 deletions test/150_connect_forget_test.sh
Original file line number Diff line number Diff line change
@@ -15,8 +15,8 @@ assert_peers() {

start_suite "Connecting and forgetting routers after launch"

weave_on $HOST1 launch
weave_on $HOST2 launch
weave_on $HOST1 launch-router
weave_on $HOST2 launch-router

start_container $HOST1 $C1/24 --name=c1
start_container $HOST2 $C2/24 --name=c2
@@ -33,8 +33,8 @@ assert_raises "exec_on $HOST1 c1 $PING $C2"

# Forget everyone and disonnect
assert_raises "weave_on $HOST2 forget $HOST1 $HOST2"
assert_raises "weave_on $HOST1 stop"
assert_raises "weave_on $HOST1 launch"
assert_raises "weave_on $HOST1 stop-router"
assert_raises "weave_on $HOST1 launch-router"
assert_peers $HOST2 ""
assert_raises "exec_on $HOST1 c1 sh -c '! $PING $C2'"

4 changes: 2 additions & 2 deletions test/210_dns_multicast_test.sh
Original file line number Diff line number Diff line change
@@ -29,8 +29,8 @@ check() {

start_suite "Resolve names across hosts (with and without IPAM), and repopulate on restart"

weave_on $HOST1 launch -iprange $UNIVERSE
weave_on $HOST2 launch -iprange $UNIVERSE $HOST1
weave_on $HOST1 launch-router -iprange $UNIVERSE
weave_on $HOST2 launch-router -iprange $UNIVERSE $HOST1

start_container $HOST2 $C2/24 --name=c2 -h $NAME2
start_container_with_dns $HOST1 $C1/24 --name=c1
2 changes: 1 addition & 1 deletion test/280_with_or_without_dns_test.sh
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ assert_resolution() {

start_suite "With or without DNS test"

weave_on $HOST1 launch
weave_on $HOST1 launch-router

DNS_IP=$(weave_on $HOST1 docker-bridge-ip)

2 changes: 1 addition & 1 deletion test/500_weave_multi_cidr_test.sh
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ start_suite "Weave run/start/attach/detach/expose/hide with multiple cidr argume
# specific address, i.e. we are assuming that IPAM always returns the
# lowest available address in the subnet

weave_on $HOST1 launch -debug -iprange 10.2.3.0/24
weave_on $HOST1 launch-router -debug -iprange 10.2.3.0/24
launch_dns_on $HOST1 10.254.254.254/24

# Run container with three cidrs
2 changes: 1 addition & 1 deletion test/620_proxy_entrypoint_command_test.sh
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ run_container "grep ^1$ /sys/class/net/ethwe/carrier"
build_image false '["/bin/false"]' ''
run_container "--entrypoint='grep' false ^1$ /sys/class/net/ethwe/carrier"

weave_on $HOST1 launch -iprange 10.2.2.0/24
weave_on $HOST1 launch-router -iprange 10.2.2.0/24
docker_on $HOST1 kill weaveproxy
weave_on $HOST1 launch-proxy

2 changes: 1 addition & 1 deletion test/650_proxy_env_test.sh
Original file line number Diff line number Diff line change
@@ -13,6 +13,6 @@ assert_raises "docker $(weave_on $HOST1 proxy-config) $CMD"
# Check we can use the weave script through the proxy
assert_raises "eval '$(weave_on $HOST1 proxy-env)' ; $WEAVE version"
assert_raises "eval '$(weave_on $HOST1 proxy-env)' ; $WEAVE ps"
assert_raises "eval '$(weave_on $HOST1 proxy-env)' ; $WEAVE launch"
assert_raises "eval '$(weave_on $HOST1 proxy-env)' ; $WEAVE launch-router"

end_suite
4 changes: 2 additions & 2 deletions test/660_proxy_ipam_test.sh
Original file line number Diff line number Diff line change
@@ -17,8 +17,8 @@ assert_no_ethwe() {

start_suite "Ping proxied containers over cross-host weave network (with IPAM)"

weave_on $HOST1 launch -iprange $UNIVERSE
weave_on $HOST2 launch -iprange $UNIVERSE $HOST1
weave_on $HOST1 launch-router -iprange $UNIVERSE
weave_on $HOST2 launch-router -iprange $UNIVERSE $HOST1
weave_on $HOST1 launch-proxy
weave_on $HOST2 launch-proxy --no-default-ipam

2 changes: 1 addition & 1 deletion test/670_proxy_tls_test.sh
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ start_suite "Boot the proxy with TLS-enabled Docker support"

PWD=$($SSH $HOST1 pwd)

weave_on $HOST1 launch
weave_on $HOST1 launch-router
weave_on $HOST1 launch-proxy \
--tlsverify \
--tlscacert $PWD/tls/ca.pem \
Loading