From e068ee09cabe18d0e69f103c6468334e903eac05 Mon Sep 17 00:00:00 2001 From: Bruce Lee Date: Wed, 5 Oct 2016 11:42:58 -0400 Subject: [PATCH] Allow specification of dialertimeout Address documentation comments --- configuration.go | 1 + docs/toml.md | 9 +++++++++ provider/marathon.go | 19 ++++++++++++------- traefik.sample.toml | 8 ++++++++ 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/configuration.go b/configuration.go index a0e1fab2a..754059854 100644 --- a/configuration.go +++ b/configuration.go @@ -325,6 +325,7 @@ func NewTraefikDefaultPointersConfiguration() *TraefikConfiguration { defaultMarathon.Endpoint = "http://127.0.0.1:8080" defaultMarathon.ExposedByDefault = true defaultMarathon.Constraints = []types.Constraint{} + defaultMarathon.DialerTimeout = 60 // default Consul var defaultConsul provider.Consul diff --git a/docs/toml.md b/docs/toml.md index 257ff0baf..9cd894763 100644 --- a/docs/toml.md +++ b/docs/toml.md @@ -836,6 +836,15 @@ domain = "marathon.localhost" # Optional # # dcosToken = "xxxxxx" + +# Override DialerTimeout +# Amount of time in seconds to allow the Marathon provider to wait to open a TCP +# connection to a Marathon master +# +# Optional +# Default: 60 +# dialerTimeout = 5 + ``` Labels can be used on containers to override default behaviour: diff --git a/provider/marathon.go b/provider/marathon.go index f2ec40918..117ac8158 100644 --- a/provider/marathon.go +++ b/provider/marathon.go @@ -2,6 +2,7 @@ package provider import ( "errors" + "net" "net/url" "sort" "strconv" @@ -26,13 +27,14 @@ var _ Provider = (*Marathon)(nil) // Marathon holds configuration of the Marathon provider. type Marathon struct { BaseProvider - Endpoint string `description:"Marathon server endpoint. You can also specify multiple endpoint for Marathon"` - Domain string `description:"Default domain used"` - ExposedByDefault bool `description:"Expose Marathon apps by default"` - GroupsAsSubDomains bool `description:"Convert Marathon groups to subdomains"` - DCOSToken string `description:"DCOSToken for DCOS environment, This will override the Authorization header"` - MarathonLBCompatibility bool `description:"Add compatibility with marathon-lb labels"` - TLS *ClientTLS `description:"Enable Docker TLS support"` + Endpoint string `description:"Marathon server endpoint. You can also specify multiple endpoint for Marathon"` + Domain string `description:"Default domain used"` + ExposedByDefault bool `description:"Expose Marathon apps by default"` + GroupsAsSubDomains bool `description:"Convert Marathon groups to subdomains"` + DCOSToken string `description:"DCOSToken for DCOS environment, This will override the Authorization header"` + MarathonLBCompatibility bool `description:"Add compatibility with marathon-lb labels"` + TLS *ClientTLS `description:"Enable Docker TLS support"` + DialerTimeout time.Duration `description:"Set a non-default connection timeout for Marathon"` Basic *MarathonBasic marathonClient marathon.Marathon } @@ -70,6 +72,9 @@ func (provider *Marathon) Provide(configurationChan chan<- types.ConfigMessage, config.HTTPClient = &http.Client{ Transport: &http.Transport{ TLSClientConfig: TLSConfig, + DialContext: (&net.Dialer{ + Timeout: time.Second * provider.DialerTimeout, + }).DialContext, }, } client, err := marathon.NewClient(config) diff --git a/traefik.sample.toml b/traefik.sample.toml index e0bc66eda..0ac52b7e7 100644 --- a/traefik.sample.toml +++ b/traefik.sample.toml @@ -487,6 +487,14 @@ # # groupsAsSubDomains = true +# Override DialerTimeout +# Amount of time in seconds to allow the Marathon provider to wait to open a TCP +# connection to a Marathon master +# +# Optional +# Default: 60 +# dialerTimeout = 5 + # Enable Marathon basic authentication # # Optional