diff --git a/driver/config/provider_test.go b/driver/config/provider_test.go index e5eadb24cf..8cb366e35a 100644 --- a/driver/config/provider_test.go +++ b/driver/config/provider_test.go @@ -205,7 +205,10 @@ func TestProviderCookieSameSiteMode(t *testing.T) { func TestProviderValidates(t *testing.T) { ctx := t.Context() - c := newProvider(t, configx.WithConfigFiles("../../internal/.hydra.yaml")) + c := newProvider(t, + configx.WithConfigFiles("../../internal/.hydra.yaml"), + configx.DisableFileWatching(), + ) // log assert.Equal(t, "debug", c.Source(ctx).String(KeyLogLevel)) diff --git a/oryx/configx/options.go b/oryx/configx/options.go index 6a51797f0d..3de253b88f 100644 --- a/oryx/configx/options.go +++ b/oryx/configx/options.go @@ -74,6 +74,13 @@ func DisableEnvLoading() OptionModifier { } } +// DisableFileWatching loads configured files once without watching them for changes. +func DisableFileWatching() OptionModifier { + return func(p *Provider) { + p.disableFileWatching = true + } +} + func WithValue(key string, value interface{}) OptionModifier { return func(p *Provider) { p.forcedValues = append(p.forcedValues, tuple{Key: key, Value: value}) diff --git a/oryx/configx/provider.go b/oryx/configx/provider.go index 2580b312ce..5c3deff54a 100644 --- a/oryx/configx/provider.go +++ b/oryx/configx/provider.go @@ -49,8 +49,9 @@ type Provider struct { baseValues []tuple files []string - skipValidation bool - disableEnvLoading bool + skipValidation bool + disableEnvLoading bool + disableFileWatching bool logger *logrusx.Logger @@ -142,7 +143,7 @@ func (p *Provider) createProviders(ctx context.Context) (providers []koanf.Provi c := make(watcherx.EventChannel) defer func() { - if err == nil && len(paths) > 0 { + if err == nil && len(paths) > 0 && !p.disableFileWatching { go p.watchForFileChanges(ctx, c) } }() @@ -152,8 +153,10 @@ func (p *Provider) createProviders(ctx context.Context) (providers []koanf.Provi return nil, err } - if _, err := fp.WatchChannel(ctx, c); err != nil { - return nil, err + if !p.disableFileWatching { + if _, err := fp.WatchChannel(ctx, c); err != nil { + return nil, err + } } providers = append(providers, fp)