Support configuring a HTTP client timeout in the Docker provider

This commit is contained in:
Sune Keller 2020-08-28 10:02:03 +02:00 committed by GitHub
parent 3db47f0adc
commit 29bd6faa18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 43 additions and 1 deletions

View file

@ -491,6 +491,30 @@ providers:
Defines the polling interval (in seconds) in Swarm Mode.
### `httpClientTimeout`
_Optional, Default=32_
```toml tab="File (TOML)"
[providers.docker]
httpClientTimeout = 300
# ...
```
```yaml tab="File (YAML)"
providers:
docker:
httpClientTimeout: 300
# ...
```
```bash tab="CLI"
--providers.docker.httpClientTimeout=300
# ...
```
Client timeout for HTTP connections (in seconds).
### `watch`
_Optional, Default=true_

View file

@ -402,6 +402,9 @@ Docker server endpoint. Can be a tcp or a unix socket endpoint. (Default: ```uni
`--providers.docker.exposedbydefault`:
Expose containers by default. (Default: ```true```)
`--providers.docker.httpclienttimeout`:
Client timeout for HTTP connections. (Default: ```32```)
`--providers.docker.network`:
Default Docker network used.

View file

@ -402,6 +402,9 @@ Docker server endpoint. Can be a tcp or a unix socket endpoint. (Default: ```uni
`TRAEFIK_PROVIDERS_DOCKER_EXPOSEDBYDEFAULT`:
Expose containers by default. (Default: ```true```)
`TRAEFIK_PROVIDERS_DOCKER_HTTPCLIENTTIMEOUT`:
Client timeout for HTTP connections. (Default: ```32```)
`TRAEFIK_PROVIDERS_DOCKER_NETWORK`:
Default Docker network used.

View file

@ -60,6 +60,7 @@
swarmMode = true
network = "foobar"
swarmModeRefreshSeconds = 42
httpClientTimeout = 42
[providers.docker.tls]
ca = "foobar"
caOptional = true

View file

@ -72,6 +72,7 @@ providers:
swarmMode: true
network: foobar
swarmModeRefreshSeconds: 42
httpClientTimeout: 42
file:
directory: foobar
watch: true

View file

@ -157,6 +157,7 @@ func TestDo_globalConfiguration(t *testing.T) {
SwarmMode: true,
Network: "MyNetwork",
SwarmModeRefreshSeconds: 42,
HTTPClientTimeout: 42,
}
config.Providers.KubernetesIngress = &ingress.Provider{

View file

@ -41,6 +41,7 @@
swarmMode = true
network = "foobar"
swarmModeRefreshSeconds = 42
httpClientTimeout = 42
[providers.docker.tls]
ca = "foobar"
caOptional = true

View file

@ -210,6 +210,10 @@ func (c *Configuration) SetEffectiveConfiguration() {
if c.Providers.Docker.SwarmModeRefreshSeconds <= 0 {
c.Providers.Docker.SwarmModeRefreshSeconds = ptypes.Duration(15 * time.Second)
}
if c.Providers.Docker.HTTPClientTimeout <= 0 {
c.Providers.Docker.HTTPClientTimeout = ptypes.Duration(32 * time.Second)
}
}
if c.Providers.Rancher != nil {

View file

@ -57,6 +57,7 @@ type Provider struct {
SwarmMode bool `description:"Use Docker on Swarm Mode." json:"swarmMode,omitempty" toml:"swarmMode,omitempty" yaml:"swarmMode,omitempty" export:"true"`
Network string `description:"Default Docker network used." json:"network,omitempty" toml:"network,omitempty" yaml:"network,omitempty" export:"true"`
SwarmModeRefreshSeconds ptypes.Duration `description:"Polling interval for swarm mode." json:"swarmModeRefreshSeconds,omitempty" toml:"swarmModeRefreshSeconds,omitempty" yaml:"swarmModeRefreshSeconds,omitempty" export:"true"`
HTTPClientTimeout ptypes.Duration `description:"Client timeout for HTTP connections." json:"httpClientTimeout,omitempty" toml:"httpClientTimeout,omitempty" yaml:"httpClientTimeout,omitempty" export:"true"`
defaultRuleTpl *template.Template
}
@ -67,6 +68,7 @@ func (p *Provider) SetDefaults() {
p.Endpoint = "unix:///var/run/docker.sock"
p.SwarmMode = false
p.SwarmModeRefreshSeconds = ptypes.Duration(15 * time.Second)
p.HTTPClientTimeout = ptypes.Duration(32 * time.Second)
p.DefaultRule = DefaultTemplateRule
}
@ -147,6 +149,7 @@ func (p *Provider) getClientOpts() ([]client.Opt, error) {
return []client.Opt{
client.WithHTTPClient(httpClient),
client.WithTimeout(time.Duration(p.HTTPClientTimeout)),
client.WithHost(helper.Host), // To avoid 400 Bad Request: malformed Host header daemon error
client.WithDialContext(helper.Dialer),
}, nil
@ -154,6 +157,7 @@ func (p *Provider) getClientOpts() ([]client.Opt, error) {
opts := []client.Opt{
client.WithHost(p.Endpoint),
client.WithTimeout(time.Duration(p.HTTPClientTimeout)),
}
if p.TLS != nil {
@ -177,7 +181,7 @@ func (p *Provider) getClientOpts() ([]client.Opt, error) {
return nil, err
}
opts = append(opts, client.WithHTTPClient(&http.Client{Transport: tr}))
opts = append(opts, client.WithHTTPClient(&http.Client{Transport: tr, Timeout: time.Duration(p.HTTPClientTimeout)}))
}
return opts, nil