fix: wait for file and internal before applying configurations

Co-authored-by: Ludovic Fernandez <ldez@users.noreply.github.com>
This commit is contained in:
Julien Salleyron 2021-02-25 17:20:04 +01:00 committed by GitHub
parent 32500773b8
commit dd0701dd16
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 17 deletions

View file

@ -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)
}
}
}