From c7681dde321eab94474ec8397ac67e6fa7c96fe8 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 24 Nov 2021 22:41:55 +0100 Subject: [PATCH] outposts: reload on signal USR1, fix display of reload offset Signed-off-by: Jens Langhammer --- internal/outpost/ak/api.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/internal/outpost/ak/api.go b/internal/outpost/ak/api.go index 271f00b00..198d14946 100644 --- a/internal/outpost/ak/api.go +++ b/internal/outpost/ak/api.go @@ -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