outposts: reload on signal USR1, fix display of reload offset

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-11-24 22:41:55 +01:00
parent 8cf9661e08
commit c7681dde32
1 changed files with 20 additions and 1 deletions

View File

@ -6,6 +6,9 @@ import (
"math/rand"
"net/http"
"net/url"
"os"
"os/signal"
"syscall"
"time"
"github.com/go-openapi/strfmt"
@ -87,8 +90,9 @@ func NewAPIController(akURL url.URL, token string) *APIController {
instanceUUID: uuid.New(),
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.configureRefreshSignal()
return ac
}
@ -107,6 +111,21 @@ func (a *APIController) Start() error {
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 {
// 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