Skip to content

Commit

Permalink
Honor DOCKER_* env variables in probe and app
Browse files Browse the repository at this point in the history
Changed default for flag `-app.docker` to use the DOCKER_* env variables
instead of hardcoded /var/run/docker.sock; uses docker's default if
no DOCKER_HOST defined, for both probe and app.

Fixes #1975
  • Loading branch information
rndstr committed Jun 26, 2017
1 parent 286e481 commit 927bb25
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
7 changes: 3 additions & 4 deletions app/weave.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import (

// Default values for weave app integration
const (
DefaultHostname = "scope.weave.local."
DefaultWeaveURL = "http://127.0.0.1:6784"
DefaultContainerName = "weavescope"
DefaultDockerEndpoint = "unix:///var/run/docker.sock"
DefaultHostname = "scope.weave.local."
DefaultWeaveURL = "http://127.0.0.1:6784"
DefaultContainerName = "weavescope"
)

// WeavePublisher is a thing which periodically registers this app with WeaveDNS.
Expand Down
3 changes: 3 additions & 0 deletions probe/docker/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ type Client interface {
}

func newDockerClient(endpoint string) (Client, error) {
if endpoint == "" {
return docker_client.NewClientFromEnv()
}
return docker_client.NewClient(endpoint)
}

Expand Down
3 changes: 3 additions & 0 deletions probe/overlay/weave.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ type DockerClient interface {
}

func newDockerClient(endpoint string) (DockerClient, error) {
if endpoint == "" {
return docker_client.NewClientFromEnv()
}
return docker_client.NewClient(endpoint)
}

Expand Down
4 changes: 2 additions & 2 deletions prog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func setupFlags(flags *flags) {
flag.StringVar(&flags.app.weaveAddr, "app.weave.addr", app.DefaultWeaveURL, "Address on which to contact WeaveDNS")
flag.StringVar(&flags.app.weaveHostname, "app.weave.hostname", "", "Hostname to advertise in WeaveDNS")
flag.StringVar(&flags.app.containerName, "app.container.name", app.DefaultContainerName, "Name of this container (to lookup container ID)")
flag.StringVar(&flags.app.dockerEndpoint, "app.docker", app.DefaultDockerEndpoint, "Location of docker endpoint (to lookup container ID)")
flag.StringVar(&flags.app.dockerEndpoint, "app.docker", "", "Overwrite location of docker endpoint (to lookup container ID) (default \"$DOCKER_HOST\")")
flag.Var(&flags.containerLabelFilterFlags, "app.container-label-filter", "Add container label-based view filter, specified as title:label. Multiple flags are accepted. Example: --app.container-label-filter='Database Containers:role=db'")
flag.Var(&flags.containerLabelFilterFlagsExclude, "app.container-label-filter-exclude", "Add container label-based view filter that excludes containers with the given label, specified as title:label. Multiple flags are accepted. Example: --app.container-label-filter-exclude='Database Containers:role=db'")

Expand Down Expand Up @@ -394,7 +394,7 @@ func main() {
if flags.probe.httpListen != "" {
_, _, err := net.SplitHostPort(flags.probe.httpListen)
if err != nil {
log.Fatalf("Invalid value for -app.http.address: %v", err)
log.Fatalf("Invalid value for -probe.http.address: %v", err)
}
}

Expand Down
4 changes: 1 addition & 3 deletions prog/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const (

var (
pluginAPIVersion = "1"
dockerEndpoint = "unix:///var/run/docker.sock"
)

func checkNewScopeVersion(flags probeFlags) {
Expand Down Expand Up @@ -199,7 +198,6 @@ func probeMain(flags probeFlags, targets []appclient.Target) {
CollectStats: true,
HostID: hostID,
HandlerRegistry: handlerRegistry,
DockerEndpoint: dockerEndpoint,
NoCommandLineArguments: flags.noCommandLineArguments,
NoEnvironmentVariables: flags.noEnvironmentVariables,
}
Expand Down Expand Up @@ -236,7 +234,7 @@ func probeMain(flags probeFlags, targets []appclient.Target) {

if flags.weaveEnabled {
client := weave.NewClient(sanitize.URL("http://", 6784, "")(flags.weaveAddr))
weave, err := overlay.NewWeave(hostID, client, dockerEndpoint)
weave, err := overlay.NewWeave(hostID, client, "")
if err != nil {
log.Errorf("Weave: failed to start client: %v", err)
} else {
Expand Down

0 comments on commit 927bb25

Please sign in to comment.