Merge remote-tracking branch 'upstream/bboreham-67_attach' into 67_attach

This commit is contained in:
Bryan Boreham committed 2014-09-23 16:05:45 +01:00
commit a21860689a
8 files changed
+81 -72

No files matched your search

+33 -32
View File
@@ -185,6 +185,35 @@ each other but not the containers of our first application...
This isolation-through-subnets scheme is an example of carrying over a This isolation-through-subnets scheme is an example of carrying over a
well-known technique from the 'on metal' days to containers. well-known technique from the 'on metal' days to containers.
### Dynamic network attachment
In some scenarios containers are started independently, e.g. via some
existing tool chain, or require more complex startup sequences than
provided by `weave run`. And sometimes the decision which application
network a container should be part of is made post startup. For these
situation, weave allows an existing, running container to be attached
to the weave network. To illustrate, we can achieve the same effect as
the first example with
host1# C=$(docker run -d -t -i ubuntu)
host1# weave attach 10.0.1.1/24 $C
There is a matching `weave detach` command:
host1# weave detach 10.0.1.1/24 $C
You can detach a container from one application network and attach it
to another:
host1# weave detach 10.0.1.1/24 $C
host1# weave attach 10.0.2.1/24 $C
or attach a container to multiple application networks, effectively
sharing it between applications:
host1# weave attach 10.0.1.1/24 $C
host1# weave attach 10.0.2.1/24 $C
### Security ### Security
In order to connect containers across untrusted networks, weave peers In order to connect containers across untrusted networks, weave peers
@@ -221,30 +250,6 @@ will work. And, more interestingly,
will work too, which is talking to a container that resides on $HOST1. will work too, which is talking to a container that resides on $HOST1.
### Attach to already-running containers
If you don't want to start containers via the `weave` script, e.g. because
you are controlling them as part of some larger orchestration scheme, you can
attach the weave network to an already-running container. To illustrate, we
can achieve the same effect as the first example like this:
host1# C=$(docker run -d -t -i ubuntu)
host1# weave attach 10.0.1.1/24 $C
There is a matching `weave detach` command:
host1# weave detach 10.0.1.1/24 $C
You can detach a container from one subnet and re-attach it to another:
host1# weave detach 10.0.1.1/24 $C
host1# weave attach 10.0.2.1/24 $C
or attach a container to multiple subnets:
host1# weave attach 10.0.1.1/24 $C
host1# weave attach 10.0.2.1/24 $C
### Service export ### Service export
Services running in containers on a weave network can be made Services running in containers on a weave network can be made
@@ -419,13 +424,8 @@ quickly enough.
## Troubleshooting ## Troubleshooting
Check what version of weave you are running: Make sure you are running the latest version - you can download it
with
weave version
and compare against
https://registry.hub.docker.com/u/zettio/weave/tags/manage/. If you
do not have the latest released version you can download it with:
docker pull zettio/weave docker pull zettio/weave
@@ -537,7 +537,8 @@ More details on the inner workings of weave can be found in the
Found a bug, want to suggest a feature, or have a question? Found a bug, want to suggest a feature, or have a question?
[File an issue](https://github.com/zettio/weave/issues), or email [File an issue](https://github.com/zettio/weave/issues), or email
weave@zett.io. weave@zett.io. When reporting a bug, please include what version of
weave you are running, as shown by `weave version`.
Follow weave on Twitter: Follow weave on Twitter:
[@weavenetwork](https://twitter.com/weavenetwork). [@weavenetwork](https://twitter.com/weavenetwork).
+5 -5
View File
@@ -182,14 +182,14 @@ func (conn *LocalConnection) queryLoop(queryChan <-chan *ConnectionInteraction,
if !ok { if !ok {
break break
} }
switch { switch query.code {
case query.code == CShutdown: case CShutdown:
terminate = true terminate = true
case query.code == CSetEstablished: case CSetEstablished:
err = conn.handleSetEstablished() err = conn.handleSetEstablished()
case query.code == CSetRemoteUDPAddr: case CSetRemoteUDPAddr:
err = conn.handleSetRemoteUDPAddr(query.payload.(*net.UDPAddr)) err = conn.handleSetRemoteUDPAddr(query.payload.(*net.UDPAddr))
case query.code == CSendTCP: case CSendTCP:
err = conn.handleSendTCP(query.payload.([]byte)) err = conn.handleSendTCP(query.payload.([]byte))
} }
} }
+29 -23
View File
@@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"log" "log"
"math"
"math/rand" "math/rand"
"net" "net"
"time" "time"
@@ -16,8 +17,9 @@ const (
const ( const (
CMInitiate = iota CMInitiate = iota
CMStatus = iota
CMTerminated = iota CMTerminated = iota
CMRefresh = iota
CMStatus = iota
) )
func StartConnectionMaker(router *Router) *ConnectionMaker { func StartConnectionMaker(router *Router) *ConnectionMaker {
@@ -43,6 +45,11 @@ func (cm *ConnectionMaker) ConnectionTerminated(address string) {
address: address} address: address}
} }
func (cm *ConnectionMaker) Refresh() {
cm.queryChan <- &ConnectionMakerInteraction{
Interaction: Interaction{code: CMRefresh}}
}
func (cm *ConnectionMaker) String() string { func (cm *ConnectionMaker) String() string {
resultChan := make(chan interface{}, 0) resultChan := make(chan interface{}, 0)
cm.queryChan <- &ConnectionMakerInteraction{ cm.queryChan <- &ConnectionMakerInteraction{
@@ -52,44 +59,38 @@ func (cm *ConnectionMaker) String() string {
} }
func (cm *ConnectionMaker) queryLoop(queryChan <-chan *ConnectionMakerInteraction) { func (cm *ConnectionMaker) queryLoop(queryChan <-chan *ConnectionMakerInteraction) {
var tick <-chan time.Time timer := time.NewTimer(math.MaxInt64)
maybeTick := func() { run := func() { timer.Reset(cm.checkStateAndAttemptConnections()) }
// would be nice to optimise this to stop ticking when there is nothing worth trying
if tick == nil {
tick = time.After(5 * time.Second)
}
}
for { for {
select { select {
case query, ok := <-queryChan: case query, ok := <-queryChan:
if !ok { if !ok {
return return
} }
switch { switch query.code {
case query.code == CMInitiate: case CMInitiate:
cm.cmdLineAddress[NormalisePeerAddr(query.address)] = true cm.cmdLineAddress[NormalisePeerAddr(query.address)] = true
cm.checkStateAndAttemptConnections(time.Now()) run()
maybeTick() case CMTerminated:
case query.code == CMStatus:
query.resultChan <- cm.status()
case query.code == CMTerminated:
if target, found := cm.targets[query.address]; found { if target, found := cm.targets[query.address]; found {
target.attempting = false target.attempting = false
target.tryAfter, target.tryInterval = tryAfter(target.tryInterval) target.tryAfter, target.tryInterval = tryAfter(target.tryInterval)
maybeTick()
} }
run()
case CMRefresh:
run()
case CMStatus:
query.resultChan <- cm.status()
default: default:
log.Fatal("Unexpected connection maker query:", query) log.Fatal("Unexpected connection maker query:", query)
} }
case now := <-tick: case <-timer.C:
cm.checkStateAndAttemptConnections(now) run()
tick = nil
maybeTick()
} }
} }
} }
func (cm *ConnectionMaker) checkStateAndAttemptConnections(now time.Time) { func (cm *ConnectionMaker) checkStateAndAttemptConnections() time.Duration {
ourself := cm.router.Ourself ourself := cm.router.Ourself
validTarget := make(map[string]bool) validTarget := make(map[string]bool)
@@ -129,7 +130,8 @@ func (cm *ConnectionMaker) checkStateAndAttemptConnections(now time.Time) {
}) })
}) })
now = time.Now() // make sure we catch items just added now := time.Now() // make sure we catch items just added
after := time.Duration(math.MaxInt64)
for address, target := range cm.targets { for address, target := range cm.targets {
if our_connected_targets[address] { if our_connected_targets[address] {
delete(cm.targets, address) delete(cm.targets, address)
@@ -142,11 +144,15 @@ func (cm *ConnectionMaker) checkStateAndAttemptConnections(now time.Time) {
delete(cm.targets, address) delete(cm.targets, address)
continue continue
} }
if now.After(target.tryAfter) { switch duration := target.tryAfter.Sub(now); {
case duration <= 0:
target.attempting = true target.attempting = true
go cm.attemptConnection(address, cm.cmdLineAddress[address]) go cm.attemptConnection(address, cm.cmdLineAddress[address])
case duration < after:
after = duration
} }
} }
return after
} }
func (cm *ConnectionMaker) addTarget(address string) { func (cm *ConnectionMaker) addTarget(address string) {
-3
View File
@@ -40,9 +40,6 @@ func newPcapIO(ifName string, promisc bool, snaplen int, bufSz int) (handle *Pca
if err = inactive.SetSnapLen(snaplen); err != nil { if err = inactive.SetSnapLen(snaplen); err != nil {
return return
} }
if err = inactive.SetTimeout(-1); err != nil {
return
}
if err = inactive.SetImmediateMode(true); err != nil { if err = inactive.SetImmediateMode(true); err != nil {
return return
} }
+5 -5
View File
@@ -259,15 +259,15 @@ func (peer *Peer) queryLoop(queryChan <-chan *PeerInteraction) {
if !ok { if !ok {
return return
} }
switch { switch query.code {
case query.code == PAddConnection: case PAddConnection:
peer.handleAddConnection(query.payload.(*LocalConnection)) peer.handleAddConnection(query.payload.(*LocalConnection))
case query.code == PDeleteConnection: case PDeleteConnection:
peer.handleDeleteConnection(query.payload.(*LocalConnection)) peer.handleDeleteConnection(query.payload.(*LocalConnection))
query.resultChan <- nil query.resultChan <- nil
case query.code == PConnectionEstablished: case PConnectionEstablished:
peer.handleConnectionEstablished(query.payload.(*LocalConnection)) peer.handleConnectionEstablished(query.payload.(*LocalConnection))
case query.code == PBroadcastTCP: case PBroadcastTCP:
peer.handleBroadcastTCP(query.payload.([]byte)) peer.handleBroadcastTCP(query.payload.([]byte))
} }
} }
+4
View File
@@ -77,6 +77,10 @@ func (cache *PeerCache) ApplyUpdate(update []byte, router *Router) ([]byte, erro
// Don't need to hold cache lock any longer // Don't need to hold cache lock any longer
cache.Unlock() cache.Unlock()
if len(newUpdate) > 0 {
router.ConnectionMaker.Refresh()
}
return encodePeersMap(newUpdate), nil return encodePeersMap(newUpdate), nil
} }
+3 -3
View File
@@ -81,15 +81,15 @@ func (topo *Topology) queryLoop(queryChan <-chan *Interaction) {
if !ok { if !ok {
return return
} }
switch { switch query.code {
case query.code == TRebuildRoutes: case TRebuildRoutes:
unicast := topo.buildUnicastRoutes() unicast := topo.buildUnicastRoutes()
broadcast := topo.buildBroadcastRoutes() broadcast := topo.buildBroadcastRoutes()
topo.Lock() topo.Lock()
topo.unicast = unicast topo.unicast = unicast
topo.broadcast = broadcast topo.broadcast = broadcast
topo.Unlock() topo.Unlock()
case query.code == TFetchAll: case TFetchAll:
query.resultChan <- topo.router.Peers.EncodeAllPeers() query.resultChan <- topo.router.Peers.EncodeAllPeers()
default: default:
log.Fatal("Unexpected topology query:", query) log.Fatal("Unexpected topology query:", query)
+2 -1
View File
@@ -15,7 +15,8 @@ docker-image: /tmp/weave.tar
publish: docker-image publish: docker-image
sudo docker tag zettio/weave zettio/weave:git-`git rev-parse --short=12 HEAD` sudo docker tag zettio/weave zettio/weave:git-`git rev-parse --short=12 HEAD`
sudo docker push zettio/weave sudo docker push zettio/weave:latest
sudo docker push zettio/weave:git-`git rev-parse --short=12 HEAD`
clean: clean:
-sudo docker rmi zettio/weave -sudo docker rmi zettio/weave