fixed reload bug

This commit is contained in:
ston1th 2021-04-10 14:32:45 +02:00
commit ec57e1174c

View file

@ -27,6 +27,7 @@ type HAProxyManager struct {
svc ServiceManager svc ServiceManager
template *template.Template template *template.Template
hash []byte hash []byte
reload bool
} }
func NewHAProxyManager(configFile, service string) (ha *HAProxyManager, err error) { func NewHAProxyManager(configFile, service string) (ha *HAProxyManager, err error) {
@ -69,8 +70,10 @@ func (ha *HAProxyManager) updateConfig(ctx context.Context, lbs Config) error {
return err return err
} }
if bytes.Equal(ha.hash, hash) { if bytes.Equal(ha.hash, hash) {
ha.reload = false
return nil return nil
} }
ha.reload = true
file, err := os.OpenFile(ha.configFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) file, err := os.OpenFile(ha.configFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil { if err != nil {
return err return err
@ -92,7 +95,10 @@ func (ha *HAProxyManager) UpdateConfig(ctx context.Context, lbs Config) error {
if err != nil { if err != nil {
return err return err
} }
return ha.svc.Reload(ctx) if ha.reload {
return ha.svc.Reload(ctx)
}
return nil
} }
func (ha *HAProxyManager) Start(ctx context.Context) error { func (ha *HAProxyManager) Start(ctx context.Context) error {