Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Honor DOCKER_* env variables in probe and app #2649

Merged
merged 1 commit into from
Jun 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 4 additions & 4 deletions probe/overlay/weave.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ type DockerClient interface {
InspectContainer(id string) (*docker_client.Container, error)
}

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

// Weave represents a single Weave router, presumably on the same host
Expand Down Expand Up @@ -181,8 +181,8 @@ type Weave struct {

// NewWeave returns a new Weave tagger based on the Weave router at
// address. The address should be an IP or FQDN, no port.
func NewWeave(hostID string, client weave.Client, dockerEndpoint string) (*Weave, error) {
dockerClient, err := NewDockerClientStub(dockerEndpoint)
func NewWeave(hostID string, client weave.Client) (*Weave, error) {
dockerClient, err := NewDockerClientStub()
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions probe/overlay/weave_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ var mockWeaveContainers = map[string]*docker_client.Container{
func runTest(t *testing.T, f func(*overlay.Weave)) {
// Place and restore docker client
origNewDockerClientStub := overlay.NewDockerClientStub
overlay.NewDockerClientStub = func(string) (overlay.DockerClient, error) {
overlay.NewDockerClientStub = func() (overlay.DockerClient, error) {
return &mockDockerClient{containers: mockWeaveContainers}, nil
}
defer func() { overlay.NewDockerClientStub = origNewDockerClientStub }()

w, err := overlay.NewWeave(mockHostID, weave.MockClient{}, "")
w, err := overlay.NewWeave(mockHostID, weave.MockClient{})
if err != nil {
t.Fatal(err)
}
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)

This comment was marked as abuse.

}
}

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