Skip to content

Commit

Permalink
Load discovery tasks when Hub inits
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Lucidi <[email protected]>
  • Loading branch information
mansam committed Jun 20, 2024
1 parent 1cb6d19 commit 1adcafd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
10 changes: 9 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -129,6 +136,7 @@ func main() {
err = liberr.Wrap(err)
return
}

//
// Auth
if settings.Settings.Auth.Required {
Expand Down
13 changes: 5 additions & 8 deletions settings/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 1adcafd

Please sign in to comment.