outpost: update global outpost config on refresh
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
f1dc2b4d2a
commit
2428d5f1c2
|
@ -114,8 +114,24 @@ func (a *APIController) Start() error {
|
||||||
return nil
|
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 {
|
func (a *APIController) StartBackgorundTasks() error {
|
||||||
err := a.Server.Refresh()
|
err := a.OnRefresh()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to run initial refresh")
|
return errors.Wrap(err, "failed to run initial refresh")
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -91,7 +91,7 @@ func (ac *APIController) startWSHandler() {
|
||||||
if wsMsg.Instruction == WebsocketInstructionTriggerUpdate {
|
if wsMsg.Instruction == WebsocketInstructionTriggerUpdate {
|
||||||
time.Sleep(ac.reloadOffset)
|
time.Sleep(ac.reloadOffset)
|
||||||
logger.Debug("Got update trigger...")
|
logger.Debug("Got update trigger...")
|
||||||
err := ac.Server.Refresh()
|
err := ac.OnRefresh()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.WithError(err).Debug("Failed to update")
|
logger.WithError(err).Debug("Failed to update")
|
||||||
} else {
|
} else {
|
||||||
|
@ -139,7 +139,7 @@ func (ac *APIController) startIntervalUpdater() {
|
||||||
logger := ac.logger.WithField("loop", "interval-updater")
|
logger := ac.logger.WithField("loop", "interval-updater")
|
||||||
ticker := time.NewTicker(5 * time.Minute)
|
ticker := time.NewTicker(5 * time.Minute)
|
||||||
for ; true; <-ticker.C {
|
for ; true; <-ticker.C {
|
||||||
err := ac.Server.Refresh()
|
err := ac.OnRefresh()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.WithError(err).Debug("Failed to update")
|
logger.WithError(err).Debug("Failed to update")
|
||||||
} else {
|
} else {
|
||||||
|
|
Reference in New Issue