diff --git a/config/config_source.go b/config/config_source.go index 2a77d6e87..bb82b13e9 100644 --- a/config/config_source.go +++ b/config/config_source.go @@ -2,7 +2,6 @@ package config import ( "crypto/sha256" - "encoding/hex" "io/ioutil" "sync" @@ -124,7 +123,6 @@ type FileWatcherSource struct { mu sync.RWMutex computedConfig *Config - version string ChangeDispatcher } @@ -183,16 +181,11 @@ func (src *FileWatcherSource) check(cfg *Config) { } } - version := hex.EncodeToString(h.Sum(nil)) - if src.version != version { - src.version = version + // update the computed config + src.computedConfig = cfg.Clone() + src.computedConfig.Options.Certificates = nil + _ = src.computedConfig.Options.Validate() - // update the computed config - src.computedConfig = cfg.Clone() - src.computedConfig.Options.Certificates = nil - _ = src.computedConfig.Options.Validate() - - // trigger a change - src.Trigger(src.computedConfig) - } + // trigger a change + src.Trigger(src.computedConfig) } diff --git a/config/config_source_test.go b/config/config_source_test.go index 692a62e50..1a107c15a 100644 --- a/config/config_source_test.go +++ b/config/config_source_test.go @@ -24,11 +24,13 @@ func TestFileWatcherSource(t *testing.T) { return } - src := NewFileWatcherSource(NewStaticSource(&Config{ + ssrc := NewStaticSource(&Config{ Options: &Options{ CAFile: filepath.Join(tmpdir, "example.txt"), }, - })) + }) + + src := NewFileWatcherSource(ssrc) var closeOnce sync.Once ch := make(chan struct{}) src.OnConfigChange(func(cfg *Config) { @@ -47,4 +49,16 @@ func TestFileWatcherSource(t *testing.T) { case <-time.After(time.Second): t.Error("expected OnConfigChange to be fired after modifying a file") } + + ssrc.SetConfig(&Config{ + Options: &Options{ + CAFile: filepath.Join(tmpdir, "example.txt"), + }, + }) + + select { + case <-ch: + case <-time.After(time.Second): + t.Error("expected OnConfigChange to be fired after triggering a change to the underlying source") + } }