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
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue