Skip to content

Commit d25b09d

Browse files
authored
fix: move workflow migration back to the controller (#1795)
Signed-off-by: Grant Linville <[email protected]>
1 parent 36385e3 commit d25b09d

File tree

4 files changed

+26
-36
lines changed

4 files changed

+26
-36
lines changed

pkg/controller/controller.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"github.com/obot-platform/nah/pkg/router"
88
"github.com/obot-platform/obot/pkg/controller/data"
99
"github.com/obot-platform/obot/pkg/controller/handlers/toolreference"
10-
"github.com/obot-platform/obot/pkg/controller/handlers/workflow"
1110
"github.com/obot-platform/obot/pkg/services"
1211
kclient "sigs.k8s.io/controller-runtime/pkg/client"
1312

@@ -44,9 +43,6 @@ func (c *Controller) PreStart(ctx context.Context) error {
4443
if err := toolreference.MigrateToolNames(ctx, c.services.StorageClient); err != nil {
4544
return fmt.Errorf("failed to migrate tool names: %w", err)
4645
}
47-
if err := workflow.SetAdditionalCredentialContexts(ctx, c.services.StorageClient); err != nil {
48-
return fmt.Errorf("failed to set workflow additional credential contexts: %w", err)
49-
}
5046
return nil
5147
}
5248

pkg/controller/handlers/workflow/migration.go

Lines changed: 0 additions & 32 deletions
This file was deleted.

pkg/controller/migrations.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/obot-platform/nah/pkg/apply"
77
"github.com/obot-platform/nah/pkg/router"
88
v1 "github.com/obot-platform/obot/pkg/storage/apis/obot.obot.ai/v1"
9+
kclient "sigs.k8s.io/controller-runtime/pkg/client"
910
)
1011

1112
func removeOldFinalizers(req router.Request, _ router.Response) error {
@@ -56,3 +57,27 @@ func changeWorkflowStepOwnerGVK(req router.Request, _ router.Response) error {
5657
}
5758
return nil
5859
}
60+
61+
func setWorkflowAdditionalCredentialContexts(req router.Request, _ router.Response) error {
62+
wf := req.Object.(*v1.Workflow)
63+
64+
if len(wf.Spec.AdditionalCredentialContexts) != 0 || wf.Spec.ThreadName == "" {
65+
return nil
66+
}
67+
68+
var thread v1.Thread
69+
if err := req.Client.Get(req.Ctx, kclient.ObjectKey{Namespace: wf.Namespace, Name: wf.Spec.ThreadName}, &thread); err != nil {
70+
return err
71+
}
72+
73+
if thread.Spec.AgentName == "" {
74+
return nil
75+
}
76+
77+
wf.Spec.AdditionalCredentialContexts = []string{thread.Spec.AgentName}
78+
if err := req.Client.Update(req.Ctx, wf); err != nil {
79+
return err
80+
}
81+
82+
return nil
83+
}

pkg/controller/routes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func (c *Controller) setupRoutes() error {
7979
root.Type(&v1.Workflow{}).HandlerFunc(toolInfo.SetToolInfoStatus)
8080
root.Type(&v1.Workflow{}).HandlerFunc(toolInfo.RemoveUnneededCredentials)
8181
root.Type(&v1.Workflow{}).HandlerFunc(generationed.UpdateObservedGeneration)
82+
root.Type(&v1.Workflow{}).HandlerFunc(setWorkflowAdditionalCredentialContexts)
8283
root.Type(&v1.Workflow{}).FinalizeFunc(v1.WorkflowFinalizer, credentialCleanup.Remove)
8384

8485
// WorkflowExecutions

0 commit comments

Comments
 (0)