outpost: update global outpost config on refresh

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-09-10 12:18:19 +02:00
parent 6c805bcf32
commit ba023a3bba
2 changed files with 19 additions and 3 deletions

View File

@ -107,8 +107,24 @@ func (a *APIController) Start() error {
return nil
}
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
outposts, _, err := a.Client.OutpostsApi.OutpostsInstancesList(context.Background()).Execute()
if err != nil {
log.WithError(err).Error("Failed to fetch outpost configuration")
return err
}
outpost := outposts.Results[0]
doGlobalSetup(outpost.Config)
log.WithField("name", outpost.Name).Debug("Fetched outpost configuration")
return a.Server.Refresh()
}
func (a *APIController) StartBackgorundTasks() error {
err := a.Server.Refresh()
err := a.OnRefresh()
if err != nil {
return errors.Wrap(err, "failed to run initial refresh")
}

View File

@ -82,7 +82,7 @@ func (ac *APIController) startWSHandler() {
if wsMsg.Instruction == WebsocketInstructionTriggerUpdate {
time.Sleep(ac.reloadOffset)
logger.Debug("Got update trigger...")
err := ac.Server.Refresh()
err := ac.OnRefresh()
if err != nil {
logger.WithError(err).Debug("Failed to update")
}
@ -118,7 +118,7 @@ func (ac *APIController) startIntervalUpdater() {
logger := ac.logger.WithField("loop", "interval-updater")
ticker := time.NewTicker(5 * time.Minute)
for ; true; <-ticker.C {
err := ac.Server.Refresh()
err := ac.OnRefresh()
if err != nil {
logger.WithError(err).Debug("Failed to update")
}