Skip to content

Commit

Permalink
Propagate Task CR data to discovery tasks
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Lucidi <slucidi@redhat.com>
  • Loading branch information
mansam committed Jun 21, 2024
1 parent 39580bd commit 36fe05c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 22 deletions.
18 changes: 12 additions & 6 deletions api/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -1079,12 +1079,18 @@ func (h ApplicationHandler) discover(ctx *gin.Context, application *model.Applic
rtx := WithContext(ctx)
db := h.DB(ctx)
for _, kind := range Settings.Hub.Discovery.Tasks {
t := model.Task{}
task := tasking.Task{Task: &t}
task.Kind = kind
task.Name = fmt.Sprintf("%s-%s", application.Name, kind)
task.ApplicationID = &application.ID
task.State = tasking.Ready
t := Task{}
t.Kind = kind
t.Name = fmt.Sprintf("%s-%s", application.Name, kind)
ref := Ref{ID: application.ID}
t.Application = &ref
t.State = tasking.Ready
taskHandler := TaskHandler{}
err = taskHandler.FindRefs(rtx.Client, &t)
if err != nil {
return
}
task := tasking.Task{Task: t.Model()}
err = rtx.TaskManager.Create(db, &task)
if err != nil {
return
Expand Down
9 changes: 4 additions & 5 deletions api/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,15 @@ func (h TaskHandler) Create(ctx *gin.Context) {
_ = ctx.Error(err)
return
}
err = h.findRefs(ctx, r)
rtx := WithContext(ctx)
err = h.FindRefs(rtx.Client, r)
if err != nil {
_ = ctx.Error(err)
return
}
task := &tasking.Task{}
task.With(r.Model())
task.CreateUser = h.BaseHandler.CurrentUser(ctx)
rtx := WithContext(ctx)
err = rtx.TaskManager.Create(h.DB(ctx), task)
if err != nil {
_ = ctx.Error(err)
Expand Down Expand Up @@ -617,14 +617,13 @@ func (h TaskHandler) GetAttached(ctx *gin.Context) {
}
}

// findRefs find referenced resources.
// FindRefs find referenced resources.
// - addon
// - extensions
// - kind
// - priority
// The priority is defaulted to the kind as needed.
func (h *TaskHandler) findRefs(ctx *gin.Context, r *Task) (err error) {
client := h.Client(ctx)
func (h *TaskHandler) FindRefs(client k8sclient.Client, r *Task) (err error) {
if r.Addon != "" {
addon := &crd.Addon{}
name := r.Addon
Expand Down
5 changes: 3 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ func main() {
//
// Application import.
importManager := importer.Manager{
DB: db,
Tasking: &taskManager,
DB: db,
TaskManager: &taskManager,
Client: client,
}
importManager.Run(context.Background())
//
Expand Down
26 changes: 17 additions & 9 deletions importer/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/konveyor/tackle2-hub/settings"
tasking "github.com/konveyor/tackle2-hub/task"
"gorm.io/gorm"
k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
)

var (
Expand All @@ -24,8 +25,9 @@ var (
// Manager for processing application imports.
type Manager struct {
// DB
DB *gorm.DB
Tasking *tasking.Manager
DB *gorm.DB
TaskManager *tasking.Manager
Client k8sclient.Client
}

// Run the manager.
Expand Down Expand Up @@ -354,13 +356,19 @@ func (m *Manager) createApplication(imp *model.Import) (ok bool) {

func (m *Manager) discover(application *model.Application) (err error) {
for _, kind := range Settings.Hub.Discovery.Tasks {
t := model.Task{}
task := tasking.Task{Task: &t}
task.Kind = kind
task.Name = fmt.Sprintf("%s-%s", application.Name, kind)
task.ApplicationID = &application.ID
task.State = tasking.Ready
err = m.Tasking.Create(m.DB, &task)
t := api.Task{}
t.Kind = kind
t.Name = fmt.Sprintf("%s-%s", application.Name, kind)
ref := api.Ref{ID: application.ID}
t.Application = &ref
t.State = tasking.Ready
taskHandler := api.TaskHandler{}
err = taskHandler.FindRefs(m.Client, &t)
if err != nil {
return
}
task := tasking.Task{Task: t.Model()}
err = m.TaskManager.Create(m.DB, &task)
if err != nil {
return
}
Expand Down

0 comments on commit 36fe05c

Please sign in to comment.