From 1adcafd4526386616c5e658b72928525fe42bc0c Mon Sep 17 00:00:00 2001 From: Sam Lucidi Date: Thu, 20 Jun 2024 16:11:36 -0400 Subject: [PATCH] Load discovery tasks when Hub inits Signed-off-by: Sam Lucidi --- cmd/main.go | 10 +++++++++- settings/hub.go | 13 +++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 57cafed08..e2efc041e 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -33,7 +33,14 @@ var Settings = &settings.Settings var log = logr.WithName("hub") func init() { - _ = Settings.Load() + err := Settings.Load() + if err != nil { + panic(liberr.Wrap(err)) + } + err = Settings.FindDiscoveryTasks() + if err != nil { + panic(liberr.Wrap(err)) + } } // Setup the DB and models. @@ -129,6 +136,7 @@ func main() { err = liberr.Wrap(err) return } + // // Auth if settings.Settings.Auth.Required { diff --git a/settings/hub.go b/settings/hub.go index 8befc0aff..a4db24c5d 100644 --- a/settings/hub.go +++ b/settings/hub.go @@ -285,19 +285,16 @@ func (r *Hub) Load() (err error) { } else { r.Discovery.Enabled = true } - if r.Discovery.Enabled { - r.Discovery.Tasks, err = r.discoveryTasks() - if err != nil { - return err - } - } } return } // discoveryTasks finds discovery tasks by their label -func (r *Hub) discoveryTasks() (tasks []string, err error) { +func (r *Hub) FindDiscoveryTasks() (err error) { + if !r.Discovery.Enabled { + return + } cfg, _ := config.GetConfig() client, err := k8sclient.New( cfg, @@ -326,7 +323,7 @@ func (r *Hub) discoveryTasks() (tasks []string, err error) { } for i := range list.Items { t := &list.Items[i] - tasks = append(tasks, t.Name) + r.Discovery.Tasks = append(r.Discovery.Tasks, t.Name) } return }