mirror of
https://github.com/containous/traefik.git
synced 2025-01-25 06:03:49 +03:00
fix: consulcatalog to update before the first interval
This commit is contained in:
parent
0fcccd35ff
commit
52eeff9f9f
@ -108,27 +108,28 @@ func (p *Provider) Provide(configurationChan chan<- dynamic.Message, pool *safe.
|
|||||||
|
|
||||||
p.client, err = createClient(p.Endpoint)
|
p.client, err = createClient(p.Endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error create consul client, %w", err)
|
return fmt.Errorf("unable to create consul client: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get configuration at the provider's startup.
|
||||||
|
err = p.loadConfiguration(routineCtx, configurationChan)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to get consul catalog data: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Periodic refreshes.
|
||||||
ticker := time.NewTicker(time.Duration(p.RefreshInterval))
|
ticker := time.NewTicker(time.Duration(p.RefreshInterval))
|
||||||
|
defer ticker.Stop()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
data, err := p.getConsulServicesData(routineCtx)
|
err = p.loadConfiguration(routineCtx, configurationChan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("error get consul catalog data, %v", err)
|
return fmt.Errorf("failed to refresh consul catalog data: %w", err)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
configuration := p.buildConfiguration(routineCtx, data)
|
|
||||||
configurationChan <- dynamic.Message{
|
|
||||||
ProviderName: "consulcatalog",
|
|
||||||
Configuration: configuration,
|
|
||||||
}
|
|
||||||
case <-routineCtx.Done():
|
case <-routineCtx.Done():
|
||||||
ticker.Stop()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,6 +148,20 @@ func (p *Provider) Provide(configurationChan chan<- dynamic.Message, pool *safe.
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Provider) loadConfiguration(ctx context.Context, configurationChan chan<- dynamic.Message) error {
|
||||||
|
data, err := p.getConsulServicesData(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
configurationChan <- dynamic.Message{
|
||||||
|
ProviderName: "consulcatalog",
|
||||||
|
Configuration: p.buildConfiguration(ctx, data),
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Provider) getConsulServicesData(ctx context.Context) ([]itemData, error) {
|
func (p *Provider) getConsulServicesData(ctx context.Context) ([]itemData, error) {
|
||||||
consulServiceNames, err := p.fetchServices(ctx)
|
consulServiceNames, err := p.fetchServices(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user