Merge pull request #1951 from weaveworks/issues/1940-remove-proxy-dockerbridgeip-dep
Use netlink instead of shelling out to `weave docker-bridge-ip`
This commit is contained in:
commit
ed3c50f43e
3 files changed
+20
-21
No files matched your search
+13
-17
@@ -12,16 +12,21 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
version = "(unreleased version)"
|
version = "(unreleased version)"
|
||||||
defaultDockerHost = "unix:///var/run/docker.sock"
|
|
||||||
defaultProcPath = "/proc"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func getenv(key, defaultVal string) string {
|
||||||
|
if v := os.Getenv(key); v != "" {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
return defaultVal
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var (
|
var (
|
||||||
justVersion bool
|
justVersion bool
|
||||||
logLevel = "info"
|
logLevel = "info"
|
||||||
c = proxy.Config{Image: "weaveworks/weaveexec"}
|
c proxy.Config
|
||||||
withDNS bool
|
withDNS bool
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -53,10 +58,6 @@ func main() {
|
|||||||
|
|
||||||
SetLogLevel(logLevel)
|
SetLogLevel(logLevel)
|
||||||
|
|
||||||
if image := os.Getenv("EXEC_IMAGE"); image != "" {
|
|
||||||
c.Image = image
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.Infoln("weave proxy", version)
|
Log.Infoln("weave proxy", version)
|
||||||
Log.Infoln("Command line arguments:", strings.Join(os.Args[1:], " "))
|
Log.Infoln("Command line arguments:", strings.Join(os.Args[1:], " "))
|
||||||
|
|
||||||
@@ -64,15 +65,10 @@ func main() {
|
|||||||
Log.Warning("--with-dns option has been removed; DNS is on by default")
|
Log.Warning("--with-dns option has been removed; DNS is on by default")
|
||||||
}
|
}
|
||||||
|
|
||||||
c.DockerHost = defaultDockerHost
|
c.Image = getenv("EXEC_IMAGE", "weaveworks/weaveexec")
|
||||||
if dockerHost := os.Getenv("DOCKER_HOST"); dockerHost != "" {
|
c.DockerBridge = getenv("DOCKER_BRIDGE", "docker0")
|
||||||
c.DockerHost = dockerHost
|
c.DockerHost = getenv("DOCKER_HOST", "unix:///var/run/docker.sock")
|
||||||
}
|
c.ProcPath = getenv("PROCFS", "/proc")
|
||||||
|
|
||||||
c.ProcPath = defaultProcPath
|
|
||||||
if procPath := os.Getenv("PROCFS"); procPath != "" {
|
|
||||||
c.ProcPath = procPath
|
|
||||||
}
|
|
||||||
|
|
||||||
p, err := proxy.NewProxy(c)
|
p, err := proxy.NewProxy(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ func callWeave(args ...string) ([]byte, []byte, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
propagateEnv("DOCKER_BRIDGE")
|
|
||||||
propagateEnv("DOCKER_HOST")
|
propagateEnv("DOCKER_HOST")
|
||||||
|
|
||||||
// Propagate WEAVE_DEBUG, to make debugging easier.
|
// Propagate WEAVE_DEBUG, to make debugging easier.
|
||||||
|
|||||||
+7
-3
@@ -62,6 +62,7 @@ type Config struct {
|
|||||||
Version string
|
Version string
|
||||||
WithoutDNS bool
|
WithoutDNS bool
|
||||||
NoMulticastRoute bool
|
NoMulticastRoute bool
|
||||||
|
DockerBridge string
|
||||||
DockerHost string
|
DockerHost string
|
||||||
ProcPath string
|
ProcPath string
|
||||||
}
|
}
|
||||||
@@ -152,11 +153,14 @@ func NewProxy(c Config) (*Proxy, error) {
|
|||||||
p.client = client.Client
|
p.client = client.Client
|
||||||
|
|
||||||
if !p.WithoutDNS {
|
if !p.WithoutDNS {
|
||||||
dockerBridgeIP, stderr, err := callWeave("docker-bridge-ip")
|
netDevs, err := GetBridgeNetDev(c.ProcPath, c.DockerBridge)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf(string(stderr))
|
return nil, err
|
||||||
}
|
}
|
||||||
p.dockerBridgeIP = string(dockerBridgeIP)
|
if len(netDevs) != 1 || len(netDevs[0].CIDRs) != 1 {
|
||||||
|
return nil, fmt.Errorf("Could not obtain address of %s", c.DockerBridge)
|
||||||
|
}
|
||||||
|
p.dockerBridgeIP = netDevs[0].CIDRs[0].IP.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
p.hostnameMatchRegexp, err = regexp.Compile(c.HostnameMatch)
|
p.hostnameMatchRegexp, err = regexp.Compile(c.HostnameMatch)
|
||||||
|
|||||||
Reference in new issue
Block a user