mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-23 11:39:32 +02:00
config: fix hot-reloading (#1820)
This commit is contained in:
parent
19d78cb844
commit
979e8f9cec
2 changed files with 22 additions and 15 deletions
|
@ -2,7 +2,6 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
@ -124,7 +123,6 @@ type FileWatcherSource struct {
|
||||||
|
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
computedConfig *Config
|
computedConfig *Config
|
||||||
version string
|
|
||||||
|
|
||||||
ChangeDispatcher
|
ChangeDispatcher
|
||||||
}
|
}
|
||||||
|
@ -183,16 +181,11 @@ func (src *FileWatcherSource) check(cfg *Config) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
version := hex.EncodeToString(h.Sum(nil))
|
// update the computed config
|
||||||
if src.version != version {
|
src.computedConfig = cfg.Clone()
|
||||||
src.version = version
|
src.computedConfig.Options.Certificates = nil
|
||||||
|
_ = src.computedConfig.Options.Validate()
|
||||||
|
|
||||||
// update the computed config
|
// trigger a change
|
||||||
src.computedConfig = cfg.Clone()
|
src.Trigger(src.computedConfig)
|
||||||
src.computedConfig.Options.Certificates = nil
|
|
||||||
_ = src.computedConfig.Options.Validate()
|
|
||||||
|
|
||||||
// trigger a change
|
|
||||||
src.Trigger(src.computedConfig)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,11 +24,13 @@ func TestFileWatcherSource(t *testing.T) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
src := NewFileWatcherSource(NewStaticSource(&Config{
|
ssrc := NewStaticSource(&Config{
|
||||||
Options: &Options{
|
Options: &Options{
|
||||||
CAFile: filepath.Join(tmpdir, "example.txt"),
|
CAFile: filepath.Join(tmpdir, "example.txt"),
|
||||||
},
|
},
|
||||||
}))
|
})
|
||||||
|
|
||||||
|
src := NewFileWatcherSource(ssrc)
|
||||||
var closeOnce sync.Once
|
var closeOnce sync.Once
|
||||||
ch := make(chan struct{})
|
ch := make(chan struct{})
|
||||||
src.OnConfigChange(func(cfg *Config) {
|
src.OnConfigChange(func(cfg *Config) {
|
||||||
|
@ -47,4 +49,16 @@ func TestFileWatcherSource(t *testing.T) {
|
||||||
case <-time.After(time.Second):
|
case <-time.After(time.Second):
|
||||||
t.Error("expected OnConfigChange to be fired after modifying a file")
|
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")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue