From 3b01488c8d98f358fe774edb76574b33bde7184a Mon Sep 17 00:00:00 2001 From: Thomas Krzero Date: Tue, 27 Nov 2018 17:44:04 +0100 Subject: [PATCH] [docker backend] - Add config flag to set refreshSeconds for swarmmode ticker --- cmd/configuration.go | 1 + docs/configuration/backends/docker.md | 7 +++++++ old/provider/docker/docker.go | 22 +++++++++++----------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/cmd/configuration.go b/cmd/configuration.go index 23b9137ec..9571652f4 100644 --- a/cmd/configuration.go +++ b/cmd/configuration.go @@ -154,6 +154,7 @@ func NewTraefikDefaultPointersConfiguration() *TraefikConfiguration { defaultDocker.ExposedByDefault = true defaultDocker.Endpoint = "unix:///var/run/docker.sock" defaultDocker.SwarmMode = false + defaultDocker.SwarmModeRefreshSeconds = 15 // default Rest var defaultRest rest.Provider diff --git a/docs/configuration/backends/docker.md b/docs/configuration/backends/docker.md index 68e5d019d..ffd132773 100644 --- a/docs/configuration/backends/docker.md +++ b/docs/configuration/backends/docker.md @@ -73,6 +73,13 @@ usebindportip = true # 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. # Can be overridden by the traefik.docker.network label. # diff --git a/old/provider/docker/docker.go b/old/provider/docker/docker.go index 84449ef1d..532299818 100644 --- a/old/provider/docker/docker.go +++ b/old/provider/docker/docker.go @@ -30,22 +30,21 @@ import ( const ( // SwarmAPIVersion is a constant holding the version of the Provider API traefik will use SwarmAPIVersion = "1.24" - // SwarmDefaultWatchTime is the duration of the interval when polling docker - SwarmDefaultWatchTime = 15 * time.Second ) var _ provider.Provider = (*Provider)(nil) // Provider holds configurations of the provider. type Provider struct { - provider.BaseProvider `mapstructure:",squash" export:"true"` - Endpoint string `description:"Docker server endpoint. Can be a tcp or a unix socket endpoint"` - Domain string `description:"Default domain used"` - TLS *types.ClientTLS `description:"Enable Docker TLS support" export:"true"` - ExposedByDefault bool `description:"Expose containers by default" 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"` - Network string `description:"Default Docker network used" export:"true"` + provider.BaseProvider `mapstructure:",squash" export:"true"` + Endpoint string `description:"Docker server endpoint. Can be a tcp or a unix socket endpoint"` + Domain string `description:"Default domain used"` + TLS *types.ClientTLS `description:"Enable Docker TLS support" export:"true"` + ExposedByDefault bool `description:"Expose containers by default" 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"` + Network string `description:"Default Docker network used" export:"true"` + SwarmModeRefreshSeconds int `description:"Polling interval for swarm mode (in seconds)" export:"true"` } // Init the provider @@ -97,6 +96,7 @@ func (p *Provider) createClient() (client.APIClient, error) { if err != nil { return nil, err } + if err := sockets.ConfigureTransport(tr, hostURL.Scheme, hostURL.Host); err != nil { return nil, err } @@ -164,7 +164,7 @@ func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *s if p.SwarmMode { errChan := make(chan error) // 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) { defer close(errChan) for {