Merge pull request #1518 from weaveworks/401-reattach-weave2

Get proxy to re-attach weave router if it restarts
This commit is contained in:
Adam Harrison committed 2015-10-20 15:31:13 +01:00
commit c5f5d4543e
4 files changed
+61 -10

No files matched your search

+1
View File
@@ -20,6 +20,7 @@ import (
var (
containerIDRegexp = regexp.MustCompile("^(/v[0-9\\.]*)?/containers/([^/]*)/.*")
weaveWaitEntrypoint = []string{"/w/w"}
weaveEntrypoint = "/home/weave/weaver"
)
func callWeave(args ...string) ([]byte, []byte, error) {
+18
View File
@@ -305,6 +305,8 @@ func (proxy *Proxy) ContainerStarted(ident string) {
// If this was a container we modified the entrypoint for, attach it to the network
if containerShouldAttach(container) {
proxy.attach(container, true)
} else if containerIsWeaveRouter(container) {
proxy.attachRouter(container)
}
proxy.notifyWaiters(container.ID)
}
@@ -313,6 +315,10 @@ func containerShouldAttach(container *docker.Container) bool {
return len(container.Config.Entrypoint) > 0 && container.Config.Entrypoint[0] == weaveWaitEntrypoint[0]
}
func containerIsWeaveRouter(container *docker.Container) bool {
return len(container.Config.Entrypoint) > 0 && container.Config.Entrypoint[0] == weaveEntrypoint
}
func (proxy *Proxy) createWait(r *http.Request, ident string) {
proxy.Lock()
ch := make(chan struct{})
@@ -386,6 +392,18 @@ func (proxy *Proxy) attach(container *docker.Container, orDie bool) error {
return nil
}
func (proxy *Proxy) attachRouter(container *docker.Container) error {
Log.Infof("Attaching weave router container: %s", container.ID)
args := []string{"attach-router"}
if _, stderr, err := callWeave(args...); err != nil {
Log.Warningf("Attaching container %s to weave network failed: %s", container.ID, string(stderr))
return errors.New(string(stderr))
} else if len(stderr) > 0 {
Log.Warningf("Attaching container %s to weave network: %s", container.ID, string(stderr))
}
return nil
}
func (proxy *Proxy) weaveCIDRs(networkMode string, env []string) ([]string, error) {
if networkMode == "host" || strings.HasPrefix(networkMode, "container:") {
return nil, fmt.Errorf("the container was created with the '--net=%s'", networkMode)