extract docker-bridge-ip fetching from proxy into bash script
This commit is contained in:
1 parent
96a69d2303
commit
bedc20c7c1
3 files changed
+25
-35
No files matched your search
@@ -3,17 +3,16 @@ package proxy
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/fsouza/go-dockerclient"
|
||||
)
|
||||
|
||||
type createContainerInterceptor struct {
|
||||
client *docker.Client
|
||||
withDNS bool
|
||||
client *docker.Client
|
||||
withDNS bool
|
||||
dockerBridgeIP string
|
||||
}
|
||||
|
||||
type createContainerRequestBody struct {
|
||||
@@ -97,11 +96,7 @@ func (i *createContainerInterceptor) setWeaveDNS(container *createContainerReque
|
||||
return nil
|
||||
}
|
||||
|
||||
dockerBridgeIP, err := getDockerBridgeIP()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
container.HostConfig.DNS = append(container.HostConfig.DNS, dockerBridgeIP)
|
||||
container.HostConfig.DNS = append(container.HostConfig.DNS, i.dockerBridgeIP)
|
||||
|
||||
if len(container.HostConfig.DNSSearch) == 0 {
|
||||
container.HostConfig.DNSSearch = []string{"."}
|
||||
@@ -109,26 +104,6 @@ func (i *createContainerInterceptor) setWeaveDNS(container *createContainerReque
|
||||
return nil
|
||||
}
|
||||
|
||||
func getDockerBridgeIP() (string, error) {
|
||||
out, err := callWeave("dns-args")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Error fetching weave dns-args: %s", err)
|
||||
}
|
||||
|
||||
var dockerBridgeIP string
|
||||
segments := strings.Split(string(out), " ")
|
||||
for i := 0; i < len(segments)-1; i++ {
|
||||
if segments[i] == "--dns" {
|
||||
dockerBridgeIP = segments[i+1]
|
||||
}
|
||||
}
|
||||
|
||||
if dockerBridgeIP == "" {
|
||||
return "", fmt.Errorf("Docker bridge IP not found in weave output: %s", string(out))
|
||||
}
|
||||
return dockerBridgeIP, nil
|
||||
}
|
||||
|
||||
func (i *createContainerInterceptor) InterceptResponse(res *http.Response) (*http.Response, error) {
|
||||
return res, nil
|
||||
}
|
||||
+17
-6
@@ -12,9 +12,10 @@ import (
|
||||
)
|
||||
|
||||
type Proxy struct {
|
||||
Dial func() (net.Conn, error)
|
||||
client *docker.Client
|
||||
withDNS bool
|
||||
Dial func() (net.Conn, error)
|
||||
client *docker.Client
|
||||
withDNS bool
|
||||
dockerBridgeIP string
|
||||
}
|
||||
|
||||
func NewProxy(targetURL string, withDNS bool) (*Proxy, error) {
|
||||
@@ -22,6 +23,15 @@ func NewProxy(targetURL string, withDNS bool) (*Proxy, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var dockerBridgeIP []byte
|
||||
if withDNS {
|
||||
dockerBridgeIP, err = callWeave("docker-bridge-ip")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
client, err := docker.NewClient(targetURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -30,8 +40,9 @@ func NewProxy(targetURL string, withDNS bool) (*Proxy, error) {
|
||||
Dial: func() (net.Conn, error) {
|
||||
return net.Dial(targetNetwork(u), targetAddress(u))
|
||||
},
|
||||
client: client,
|
||||
withDNS: withDNS,
|
||||
client: client,
|
||||
withDNS: withDNS,
|
||||
dockerBridgeIP: string(dockerBridgeIP),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -82,7 +93,7 @@ func (proxy *Proxy) weaveStatus(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (proxy *Proxy) createContainer(w http.ResponseWriter, r *http.Request) {
|
||||
newClient(proxy.Dial, &createContainerInterceptor{proxy.client, proxy.withDNS}).ServeHTTP(w, r)
|
||||
newClient(proxy.Dial, &createContainerInterceptor{proxy.client, proxy.withDNS, proxy.dockerBridgeIP}).ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
func (proxy *Proxy) startContainer(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in new issue
Block a user