Skip to content

Commit

Permalink
fix: copy parent project manifest to children
Browse files Browse the repository at this point in the history
Signed-off-by: Donnie Adams <[email protected]>
  • Loading branch information
thedadams authored Mar 8, 2025
1 parent 8659129 commit a65593d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
32 changes: 32 additions & 0 deletions pkg/controller/handlers/projects/projects.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package projects

import (
"github.com/obot-platform/nah/pkg/router"
v1 "github.com/obot-platform/obot/pkg/storage/apis/obot.obot.ai/v1"
"k8s.io/apimachinery/pkg/api/equality"
)

type Handler struct{}

func NewHandler() *Handler {
return &Handler{}
}

func (h *Handler) CopyProjectInfo(req router.Request, _ router.Response) error {
projectThread := req.Object.(*v1.Thread)
if !projectThread.Spec.Project || projectThread.Spec.ParentThreadName == "" {
return nil
}

var parentThread v1.Thread
if err := req.Get(&parentThread, projectThread.Namespace, projectThread.Spec.ParentThreadName); err != nil {
return err
}

if !equality.Semantic.DeepEqual(projectThread.Spec.Manifest, parentThread.Spec.Manifest) {
projectThread.Spec.Manifest = parentThread.Spec.Manifest
return req.Client.Update(req.Ctx, projectThread)
}

return nil
}
3 changes: 3 additions & 0 deletions pkg/controller/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/obot-platform/obot/pkg/controller/handlers/knowledgesource"
"github.com/obot-platform/obot/pkg/controller/handlers/knowledgesummary"
"github.com/obot-platform/obot/pkg/controller/handlers/oauthapp"
"github.com/obot-platform/obot/pkg/controller/handlers/projects"
"github.com/obot-platform/obot/pkg/controller/handlers/runs"
"github.com/obot-platform/obot/pkg/controller/handlers/threads"
"github.com/obot-platform/obot/pkg/controller/handlers/threadshare"
Expand Down Expand Up @@ -48,6 +49,7 @@ func (c *Controller) setupRoutes() error {
toolInfo := toolinfo.New(c.services.GPTClient)
threads := threads.NewHandler(c.services.GPTClient, c.services.Invoker)
credentialCleanup := cleanup.NewCredentials(c.services.GPTClient)
projects := projects.NewHandler()

// Runs
root.Type(&v1.Run{}).FinalizeFunc(v1.RunFinalizer, runs.DeleteRunState)
Expand All @@ -68,6 +70,7 @@ func (c *Controller) setupRoutes() error {
root.Type(&v1.Thread{}).HandlerFunc(threads.CleanupEphemeralThreads)
root.Type(&v1.Thread{}).HandlerFunc(threads.SetCreated)
root.Type(&v1.Thread{}).HandlerFunc(threads.GenerateName)
root.Type(&v1.Thread{}).HandlerFunc(projects.CopyProjectInfo)
root.Type(&v1.Thread{}).FinalizeFunc(v1.ThreadFinalizer, credentialCleanup.Remove)
root.Type(&v1.Thread{}).FinalizeFunc(v1.ThreadFinalizer+"-child-cleanup", threads.ActivateRuns)

Expand Down

0 comments on commit a65593d

Please sign in to comment.