[docker backend] - Add config flag to set refreshSeconds for swarmmode ticker

This commit is contained in:
Thomas Krzero 2018-11-27 17:44:04 +01:00 committed by Traefiker Bot
parent 2f65572247
commit 3b01488c8d
3 changed files with 19 additions and 11 deletions

View file

@ -154,6 +154,7 @@ func NewTraefikDefaultPointersConfiguration() *TraefikConfiguration {
defaultDocker.ExposedByDefault = true defaultDocker.ExposedByDefault = true
defaultDocker.Endpoint = "unix:///var/run/docker.sock" defaultDocker.Endpoint = "unix:///var/run/docker.sock"
defaultDocker.SwarmMode = false defaultDocker.SwarmMode = false
defaultDocker.SwarmModeRefreshSeconds = 15
// default Rest // default Rest
var defaultRest rest.Provider var defaultRest rest.Provider

View file

@ -73,6 +73,13 @@ usebindportip = true
# #
swarmMode = false swarmMode = false
# Polling interval (in seconds) for Swarm Mode.
#
# Optional
# Default: 15
#
swarmModeRefreshSeconds = 15
# Define a default docker network to use for connections to all containers. # Define a default docker network to use for connections to all containers.
# Can be overridden by the traefik.docker.network label. # Can be overridden by the traefik.docker.network label.
# #

View file

@ -30,8 +30,6 @@ import (
const ( const (
// SwarmAPIVersion is a constant holding the version of the Provider API traefik will use // SwarmAPIVersion is a constant holding the version of the Provider API traefik will use
SwarmAPIVersion = "1.24" SwarmAPIVersion = "1.24"
// SwarmDefaultWatchTime is the duration of the interval when polling docker
SwarmDefaultWatchTime = 15 * time.Second
) )
var _ provider.Provider = (*Provider)(nil) var _ provider.Provider = (*Provider)(nil)
@ -46,6 +44,7 @@ type Provider struct {
UseBindPortIP bool `description:"Use the ip address from the bound port, rather than from the inner network" export:"true"` UseBindPortIP bool `description:"Use the ip address from the bound port, rather than from the inner network" export:"true"`
SwarmMode bool `description:"Use Docker on Swarm Mode" export:"true"` SwarmMode bool `description:"Use Docker on Swarm Mode" export:"true"`
Network string `description:"Default Docker network used" export:"true"` Network string `description:"Default Docker network used" export:"true"`
SwarmModeRefreshSeconds int `description:"Polling interval for swarm mode (in seconds)" export:"true"`
} }
// Init the provider // Init the provider
@ -97,6 +96,7 @@ func (p *Provider) createClient() (client.APIClient, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
if err := sockets.ConfigureTransport(tr, hostURL.Scheme, hostURL.Host); err != nil { if err := sockets.ConfigureTransport(tr, hostURL.Scheme, hostURL.Host); err != nil {
return nil, err return nil, err
} }
@ -164,7 +164,7 @@ func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *s
if p.SwarmMode { if p.SwarmMode {
errChan := make(chan error) errChan := make(chan error)
// TODO: This need to be change. Linked to Swarm events docker/docker#23827 // TODO: This need to be change. Linked to Swarm events docker/docker#23827
ticker := time.NewTicker(SwarmDefaultWatchTime) ticker := time.NewTicker(time.Second * time.Duration(p.SwarmModeRefreshSeconds))
pool.GoCtx(func(ctx context.Context) { pool.GoCtx(func(ctx context.Context) {
defer close(errChan) defer close(errChan)
for { for {