forked from Ivasoft/traefik
fix: wait for file and internal before applying configurations
Co-authored-by: Ludovic Fernandez <ldez@users.noreply.github.com>
This commit is contained in:
@@ -28,6 +28,7 @@ type ConfigurationWatcher struct {
|
||||
configurationValidatedChan chan dynamic.Message
|
||||
providerConfigUpdateMap map[string]chan dynamic.Message
|
||||
|
||||
requiredProvider string
|
||||
configurationListeners []func(dynamic.Configuration)
|
||||
|
||||
routinesPool *safe.Pool
|
||||
@@ -39,6 +40,7 @@ func NewConfigurationWatcher(
|
||||
pvd provider.Provider,
|
||||
providersThrottleDuration time.Duration,
|
||||
defaultEntryPoints []string,
|
||||
requiredProvider string,
|
||||
) *ConfigurationWatcher {
|
||||
watcher := &ConfigurationWatcher{
|
||||
provider: pvd,
|
||||
@@ -48,6 +50,7 @@ func NewConfigurationWatcher(
|
||||
providersThrottleDuration: providersThrottleDuration,
|
||||
routinesPool: routinesPool,
|
||||
defaultEntryPoints: defaultEntryPoints,
|
||||
requiredProvider: requiredProvider,
|
||||
}
|
||||
|
||||
currentConfigurations := make(dynamic.Configurations)
|
||||
@@ -146,8 +149,11 @@ func (c *ConfigurationWatcher) loadMessage(configMsg dynamic.Message) {
|
||||
conf := mergeConfiguration(newConfigurations, c.defaultEntryPoints)
|
||||
conf = applyModel(conf)
|
||||
|
||||
for _, listener := range c.configurationListeners {
|
||||
listener(conf)
|
||||
// We wait for first configuration of the require provider before applying configurations.
|
||||
if _, ok := newConfigurations[c.requiredProvider]; c.requiredProvider == "" || ok {
|
||||
for _, listener := range c.configurationListeners {
|
||||
listener(conf)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ func TestNewConfigurationWatcher(t *testing.T) {
|
||||
}},
|
||||
}
|
||||
|
||||
watcher := NewConfigurationWatcher(routinesPool, pvd, time.Second, []string{})
|
||||
watcher := NewConfigurationWatcher(routinesPool, pvd, time.Second, []string{}, "")
|
||||
|
||||
run := make(chan struct{})
|
||||
|
||||
@@ -112,7 +112,7 @@ func TestListenProvidersThrottleProviderConfigReload(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
watcher := NewConfigurationWatcher(routinesPool, pvd, 30*time.Millisecond, []string{})
|
||||
watcher := NewConfigurationWatcher(routinesPool, pvd, 30*time.Millisecond, []string{}, "")
|
||||
|
||||
publishedConfigCount := 0
|
||||
watcher.AddListener(func(_ dynamic.Configuration) {
|
||||
@@ -136,7 +136,7 @@ func TestListenProvidersSkipsEmptyConfigs(t *testing.T) {
|
||||
messages: []dynamic.Message{{ProviderName: "mock"}},
|
||||
}
|
||||
|
||||
watcher := NewConfigurationWatcher(routinesPool, pvd, time.Second, []string{})
|
||||
watcher := NewConfigurationWatcher(routinesPool, pvd, time.Second, []string{}, "")
|
||||
watcher.AddListener(func(_ dynamic.Configuration) {
|
||||
t.Error("An empty configuration was published but it should not")
|
||||
})
|
||||
@@ -162,7 +162,7 @@ func TestListenProvidersSkipsSameConfigurationForProvider(t *testing.T) {
|
||||
messages: []dynamic.Message{message, message},
|
||||
}
|
||||
|
||||
watcher := NewConfigurationWatcher(routinesPool, pvd, 0, []string{})
|
||||
watcher := NewConfigurationWatcher(routinesPool, pvd, 0, []string{}, "")
|
||||
|
||||
alreadyCalled := false
|
||||
watcher.AddListener(func(_ dynamic.Configuration) {
|
||||
@@ -205,7 +205,7 @@ func TestListenProvidersDoesNotSkipFlappingConfiguration(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
watcher := NewConfigurationWatcher(routinesPool, pvd, 15*time.Millisecond, []string{"defaultEP"})
|
||||
watcher := NewConfigurationWatcher(routinesPool, pvd, 15*time.Millisecond, []string{"defaultEP"}, "")
|
||||
|
||||
var lastConfig dynamic.Configuration
|
||||
watcher.AddListener(func(conf dynamic.Configuration) {
|
||||
@@ -260,7 +260,7 @@ func TestListenProvidersPublishesConfigForEachProvider(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
watcher := NewConfigurationWatcher(routinesPool, pvd, 0, []string{"defaultEP"})
|
||||
watcher := NewConfigurationWatcher(routinesPool, pvd, 0, []string{"defaultEP"}, "")
|
||||
|
||||
var publishedProviderConfig dynamic.Configuration
|
||||
|
||||
@@ -327,7 +327,7 @@ func TestPublishConfigUpdatedByProvider(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
watcher := NewConfigurationWatcher(routinesPool, pvd, 30*time.Millisecond, []string{})
|
||||
watcher := NewConfigurationWatcher(routinesPool, pvd, 30*time.Millisecond, []string{}, "")
|
||||
|
||||
publishedConfigCount := 0
|
||||
watcher.AddListener(func(configuration dynamic.Configuration) {
|
||||
@@ -375,7 +375,7 @@ func TestPublishConfigUpdatedByConfigWatcherListener(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
watcher := NewConfigurationWatcher(routinesPool, pvd, 30*time.Millisecond, []string{})
|
||||
watcher := NewConfigurationWatcher(routinesPool, pvd, 30*time.Millisecond, []string{}, "")
|
||||
|
||||
publishedConfigCount := 0
|
||||
watcher.AddListener(func(configuration dynamic.Configuration) {
|
||||
|
||||
Reference in New Issue
Block a user