outposts: reload on signal USR1, fix display of reload offset
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
8cf9661e08
commit
c7681dde32
|
@ -6,6 +6,9 @@ import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-openapi/strfmt"
|
"github.com/go-openapi/strfmt"
|
||||||
|
@ -87,8 +90,9 @@ func NewAPIController(akURL url.URL, token string) *APIController {
|
||||||
instanceUUID: uuid.New(),
|
instanceUUID: uuid.New(),
|
||||||
Outpost: outpost,
|
Outpost: outpost,
|
||||||
}
|
}
|
||||||
ac.logger.WithField("offset", ac.reloadOffset).Debug("HA Reload offset")
|
ac.logger.WithField("offset", ac.reloadOffset.String()).Debug("HA Reload offset")
|
||||||
ac.initWS(akURL, strfmt.UUID(outpost.Pk))
|
ac.initWS(akURL, strfmt.UUID(outpost.Pk))
|
||||||
|
ac.configureRefreshSignal()
|
||||||
return ac
|
return ac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,6 +111,21 @@ func (a *APIController) Start() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *APIController) configureRefreshSignal() {
|
||||||
|
s := make(chan os.Signal, 1)
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
<-s
|
||||||
|
err := a.OnRefresh()
|
||||||
|
if err != nil {
|
||||||
|
a.logger.WithError(err).Warning("failed to refresh")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
signal.Notify(s, syscall.SIGUSR1)
|
||||||
|
a.logger.Debug("Enabled USR1 hook to reload")
|
||||||
|
}
|
||||||
|
|
||||||
func (a *APIController) OnRefresh() error {
|
func (a *APIController) OnRefresh() error {
|
||||||
// Because we don't know the outpost UUID, we simply do a list and pick the first
|
// Because we don't know the outpost UUID, we simply do a list and pick the first
|
||||||
// The service account this token belongs to should only have access to a single outpost
|
// The service account this token belongs to should only have access to a single outpost
|
||||||
|
|
Reference in a new issue