Replace Delay by RefreshSecond in Eureka

This commit is contained in:
Ludovic Fernandez 2018-03-07 10:46:04 +01:00 committed by Traefiker Bot
parent c4529820f2
commit 3a2b421566
5 changed files with 36 additions and 25 deletions

View file

@ -434,6 +434,7 @@ func TestDo_globalConfiguration(t *testing.T) {
}, },
Endpoint: "eureka Endpoint", Endpoint: "eureka Endpoint",
Delay: flaeg.Duration(30 * time.Second), Delay: flaeg.Duration(30 * time.Second),
RefreshSeconds: flaeg.Duration(30 * time.Second),
} }
config.ECS = &ecs.Provider{ config.ECS = &ecs.Provider{
BaseProvider: provider.BaseProvider{ BaseProvider: provider.BaseProvider{

View file

@ -166,7 +166,7 @@ func NewTraefikDefaultPointersConfiguration() *TraefikConfiguration {
// default Eureka // default Eureka
var defaultEureka eureka.Provider var defaultEureka eureka.Provider
defaultEureka.Delay = flaeg.Duration(30 * time.Second) defaultEureka.RefreshSeconds = flaeg.Duration(30 * time.Second)
// default ServiceFabric // default ServiceFabric
var defaultServiceFabric servicefabric.Provider var defaultServiceFabric servicefabric.Provider

View file

@ -201,6 +201,13 @@ func (gc *GlobalConfiguration) SetEffectiveConfiguration(configFile string) {
gc.LifeCycle.GraceTimeOut = gc.GraceTimeOut gc.LifeCycle.GraceTimeOut = gc.GraceTimeOut
} }
if gc.Eureka != nil {
if gc.Eureka.Delay != 0 {
log.Warn("Delay has been deprecated -- please use RefreshSeconds")
gc.Eureka.RefreshSeconds = gc.Eureka.Delay
}
}
if gc.Rancher != nil { if gc.Rancher != nil {
// Ensure backwards compatibility for now // Ensure backwards compatibility for now
if len(gc.Rancher.AccessKey) > 0 || if len(gc.Rancher.AccessKey) > 0 ||

View file

@ -21,7 +21,7 @@ endpoint = "http://my.eureka.server/eureka"
# Optional # Optional
# Default: 30s # Default: 30s
# #
delay = "1m" refreshSeconds = "1m"
# Override default configuration template. # Override default configuration template.
# For advanced users :) # For advanced users :)

View file

@ -18,7 +18,8 @@ import (
type Provider struct { type Provider struct {
provider.BaseProvider `mapstructure:",squash" export:"true"` provider.BaseProvider `mapstructure:",squash" export:"true"`
Endpoint string `description:"Eureka server endpoint"` Endpoint string `description:"Eureka server endpoint"`
Delay flaeg.Duration `description:"Override default configuration time between refresh" export:"true"` Delay flaeg.Duration `description:"Override default configuration time between refresh (Deprecated)" export:"true"` // Deprecated
RefreshSeconds flaeg.Duration `description:"Override default configuration time between refresh" export:"true"`
} }
// Provide allows the eureka provider to provide configurations to traefik // Provide allows the eureka provider to provide configurations to traefik
@ -46,27 +47,29 @@ func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *s
Configuration: configuration, Configuration: configuration,
} }
ticker := time.NewTicker(time.Duration(p.Delay)) ticker := time.NewTicker(time.Duration(p.RefreshSeconds))
safe.Go(func() { pool.Go(func(stop chan bool) {
for t := range ticker.C { for {
select {
case t := <-ticker.C:
log.Debugf("Refreshing Provider %s", t.String()) log.Debugf("Refreshing Provider %s", t.String())
applications, err := client.GetApplications() applications, err := client.GetApplications()
if err != nil { if err != nil {
log.Errorf("Failed to retrieve applications, error: %s", err) log.Errorf("Failed to retrieve applications, error: %s", err)
continue continue
} }
configuration, err := p.buildConfiguration(applications) configuration, err := p.buildConfiguration(applications)
if err != nil { if err != nil {
log.Errorf("Failed to refresh Provider configuration, error: %s", err) log.Errorf("Failed to refresh Provider configuration, error: %s", err)
continue continue
} }
configurationChan <- types.ConfigMessage{ configurationChan <- types.ConfigMessage{
ProviderName: "eureka", ProviderName: "eureka",
Configuration: configuration, Configuration: configuration,
} }
case <-stop:
return
}
} }
}) })
return nil return nil