[proxy] refactor weaveCIDRsFromConfig slightly

This commit is contained in:
Paul Bellamy committed 2015-06-17 14:51:12 +01:00
1 parent ca681bce13
commit 6c26a55b5a
5 files changed
+16 -16

No files matched your search

-13
View File
@@ -8,7 +8,6 @@ import (
"net/http"
"os/exec"
"regexp"
"strings"
"github.com/fsouza/go-dockerclient"
. "github.com/weaveworks/weave/common"
@@ -28,18 +27,6 @@ func callWeave(args ...string) ([]byte, error) {
return out, err
}
func weaveCIDRsFromConfig(config *docker.Config, noDefaultIPAM bool) ([]string, bool) {
for _, e := range config.Env {
if strings.HasPrefix(e, "WEAVE_CIDR=") {
if e[11:] == "none" {
return nil, false
}
return strings.Fields(e[11:]), true
}
}
return nil, !noDefaultIPAM
}
func marshalRequestBody(r *http.Request, body interface{}) error {
newBody, err := json.Marshal(body)
if err != nil {
+1 -1
View File
@@ -33,7 +33,7 @@ func (i *createContainerInterceptor) InterceptRequest(r *http.Request) error {
return err
}
if cidrs, ok := weaveCIDRsFromConfig(container.Config, i.proxy.NoDefaultIPAM); ok {
if cidrs, ok := i.proxy.weaveCIDRsFromConfig(container.Config); ok {
Info.Printf("Creating container with WEAVE_CIDR \"%s\"", strings.Join(cidrs, " "))
if container.HostConfig == nil {
container.HostConfig = &docker.HostConfig{}
+1 -1
View File
@@ -29,7 +29,7 @@ func (i *createExecInterceptor) InterceptRequest(r *http.Request) error {
return err
}
if cidrs, ok := weaveCIDRsFromConfig(container.Config, i.proxy.NoDefaultIPAM); ok {
if cidrs, ok := i.proxy.weaveCIDRsFromConfig(container.Config); ok {
Info.Printf("Exec in container %s with WEAVE_CIDR \"%s\"", container.ID, strings.Join(cidrs, " "))
cmd := append(weaveWaitEntrypoint, "-s")
options.Cmd = append(cmd, options.Cmd...)
+13
View File
@@ -6,6 +6,7 @@ import (
"net/http"
"net/url"
"regexp"
"strings"
"github.com/fsouza/go-dockerclient"
. "github.com/weaveworks/weave/common"
@@ -113,3 +114,15 @@ func (proxy *Proxy) ListenAndServe() error {
return (&http.Server{Handler: proxy}).Serve(listener)
}
func (proxy *Proxy) weaveCIDRsFromConfig(config *docker.Config) ([]string, bool) {
for _, e := range config.Env {
if strings.HasPrefix(e, "WEAVE_CIDR=") {
if e[11:] == "none" {
return nil, false
}
return strings.Fields(e[11:]), true
}
}
return nil, !proxy.NoDefaultIPAM
}
+1 -1
View File
@@ -21,7 +21,7 @@ func (i *startContainerInterceptor) InterceptResponse(r *http.Response) error {
return err
}
cidrs, ok := weaveCIDRsFromConfig(container.Config, i.proxy.NoDefaultIPAM)
cidrs, ok := i.proxy.weaveCIDRsFromConfig(container.Config)
if !ok {
Debug.Print("No Weave CIDR, ignoring")
return nil