Support configuring a HTTP client timeout in the Docker provider
This commit is contained in:
parent
3db47f0adc
commit
29bd6faa18
9 changed files with 43 additions and 1 deletions
|
@ -491,6 +491,30 @@ providers:
|
||||||
|
|
||||||
Defines the polling interval (in seconds) in Swarm Mode.
|
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`
|
### `watch`
|
||||||
|
|
||||||
_Optional, Default=true_
|
_Optional, Default=true_
|
||||||
|
|
|
@ -402,6 +402,9 @@ Docker server endpoint. Can be a tcp or a unix socket endpoint. (Default: ```uni
|
||||||
`--providers.docker.exposedbydefault`:
|
`--providers.docker.exposedbydefault`:
|
||||||
Expose containers by default. (Default: ```true```)
|
Expose containers by default. (Default: ```true```)
|
||||||
|
|
||||||
|
`--providers.docker.httpclienttimeout`:
|
||||||
|
Client timeout for HTTP connections. (Default: ```32```)
|
||||||
|
|
||||||
`--providers.docker.network`:
|
`--providers.docker.network`:
|
||||||
Default Docker network used.
|
Default Docker network used.
|
||||||
|
|
||||||
|
|
|
@ -402,6 +402,9 @@ Docker server endpoint. Can be a tcp or a unix socket endpoint. (Default: ```uni
|
||||||
`TRAEFIK_PROVIDERS_DOCKER_EXPOSEDBYDEFAULT`:
|
`TRAEFIK_PROVIDERS_DOCKER_EXPOSEDBYDEFAULT`:
|
||||||
Expose containers by default. (Default: ```true```)
|
Expose containers by default. (Default: ```true```)
|
||||||
|
|
||||||
|
`TRAEFIK_PROVIDERS_DOCKER_HTTPCLIENTTIMEOUT`:
|
||||||
|
Client timeout for HTTP connections. (Default: ```32```)
|
||||||
|
|
||||||
`TRAEFIK_PROVIDERS_DOCKER_NETWORK`:
|
`TRAEFIK_PROVIDERS_DOCKER_NETWORK`:
|
||||||
Default Docker network used.
|
Default Docker network used.
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,7 @@
|
||||||
swarmMode = true
|
swarmMode = true
|
||||||
network = "foobar"
|
network = "foobar"
|
||||||
swarmModeRefreshSeconds = 42
|
swarmModeRefreshSeconds = 42
|
||||||
|
httpClientTimeout = 42
|
||||||
[providers.docker.tls]
|
[providers.docker.tls]
|
||||||
ca = "foobar"
|
ca = "foobar"
|
||||||
caOptional = true
|
caOptional = true
|
||||||
|
|
|
@ -72,6 +72,7 @@ providers:
|
||||||
swarmMode: true
|
swarmMode: true
|
||||||
network: foobar
|
network: foobar
|
||||||
swarmModeRefreshSeconds: 42
|
swarmModeRefreshSeconds: 42
|
||||||
|
httpClientTimeout: 42
|
||||||
file:
|
file:
|
||||||
directory: foobar
|
directory: foobar
|
||||||
watch: true
|
watch: true
|
||||||
|
|
|
@ -157,6 +157,7 @@ func TestDo_globalConfiguration(t *testing.T) {
|
||||||
SwarmMode: true,
|
SwarmMode: true,
|
||||||
Network: "MyNetwork",
|
Network: "MyNetwork",
|
||||||
SwarmModeRefreshSeconds: 42,
|
SwarmModeRefreshSeconds: 42,
|
||||||
|
HTTPClientTimeout: 42,
|
||||||
}
|
}
|
||||||
|
|
||||||
config.Providers.KubernetesIngress = &ingress.Provider{
|
config.Providers.KubernetesIngress = &ingress.Provider{
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
swarmMode = true
|
swarmMode = true
|
||||||
network = "foobar"
|
network = "foobar"
|
||||||
swarmModeRefreshSeconds = 42
|
swarmModeRefreshSeconds = 42
|
||||||
|
httpClientTimeout = 42
|
||||||
[providers.docker.tls]
|
[providers.docker.tls]
|
||||||
ca = "foobar"
|
ca = "foobar"
|
||||||
caOptional = true
|
caOptional = true
|
||||||
|
|
|
@ -210,6 +210,10 @@ func (c *Configuration) SetEffectiveConfiguration() {
|
||||||
if c.Providers.Docker.SwarmModeRefreshSeconds <= 0 {
|
if c.Providers.Docker.SwarmModeRefreshSeconds <= 0 {
|
||||||
c.Providers.Docker.SwarmModeRefreshSeconds = ptypes.Duration(15 * time.Second)
|
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 {
|
if c.Providers.Rancher != nil {
|
||||||
|
|
|
@ -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"`
|
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"`
|
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"`
|
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
|
defaultRuleTpl *template.Template
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,6 +68,7 @@ func (p *Provider) SetDefaults() {
|
||||||
p.Endpoint = "unix:///var/run/docker.sock"
|
p.Endpoint = "unix:///var/run/docker.sock"
|
||||||
p.SwarmMode = false
|
p.SwarmMode = false
|
||||||
p.SwarmModeRefreshSeconds = ptypes.Duration(15 * time.Second)
|
p.SwarmModeRefreshSeconds = ptypes.Duration(15 * time.Second)
|
||||||
|
p.HTTPClientTimeout = ptypes.Duration(32 * time.Second)
|
||||||
p.DefaultRule = DefaultTemplateRule
|
p.DefaultRule = DefaultTemplateRule
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,6 +149,7 @@ func (p *Provider) getClientOpts() ([]client.Opt, error) {
|
||||||
|
|
||||||
return []client.Opt{
|
return []client.Opt{
|
||||||
client.WithHTTPClient(httpClient),
|
client.WithHTTPClient(httpClient),
|
||||||
|
client.WithTimeout(time.Duration(p.HTTPClientTimeout)),
|
||||||
client.WithHost(helper.Host), // To avoid 400 Bad Request: malformed Host header daemon error
|
client.WithHost(helper.Host), // To avoid 400 Bad Request: malformed Host header daemon error
|
||||||
client.WithDialContext(helper.Dialer),
|
client.WithDialContext(helper.Dialer),
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -154,6 +157,7 @@ func (p *Provider) getClientOpts() ([]client.Opt, error) {
|
||||||
|
|
||||||
opts := []client.Opt{
|
opts := []client.Opt{
|
||||||
client.WithHost(p.Endpoint),
|
client.WithHost(p.Endpoint),
|
||||||
|
client.WithTimeout(time.Duration(p.HTTPClientTimeout)),
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.TLS != nil {
|
if p.TLS != nil {
|
||||||
|
@ -177,7 +181,7 @@ func (p *Provider) getClientOpts() ([]client.Opt, error) {
|
||||||
return nil, err
|
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
|
return opts, nil
|
||||||
|
|
Loading…
Reference in a new issue