Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert 1ed16ce... change: use cleanup handler for runstate instead of finalizer on a run (#661) #782

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 12 additions & 19 deletions pkg/controller/handlers/runs/runs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package runs

import (
"fmt"
"slices"
"time"

"github.com/gptscript-ai/go-gptscript"
Expand All @@ -11,6 +10,8 @@ import (
"github.com/otto8-ai/otto8/pkg/invoke"
v1 "github.com/otto8-ai/otto8/pkg/storage/apis/otto.otto8.ai/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

var log = logger.Package()
Expand All @@ -23,6 +24,16 @@ func New(invoker *invoke.Invoker) *Handler {
return &Handler{invoker: invoker}
}

func (*Handler) DeleteRunState(req router.Request, resp router.Response) error {
run := req.Object.(*v1.Run)
return client.IgnoreNotFound(req.Delete(&v1.RunState{
ObjectMeta: metav1.ObjectMeta{
Name: run.Name,
Namespace: run.Namespace,
},
}))
}

func (h *Handler) Resume(req router.Request, _ router.Response) error {
run := req.Object.(*v1.Run)
var thread v1.Thread
Expand Down Expand Up @@ -75,21 +86,3 @@ func (h *Handler) DeleteFinished(req router.Request, _ router.Response) error {
}
return nil
}

// MigrateRemoveRunFinalizer (to be removed) removes the run finalizer from the run object which was used to cascade delete the run state,
// which was moved to its own cleanup handler.
func (h *Handler) MigrateRemoveRunFinalizer(req router.Request, _ router.Response) error {
run := req.Object.(*v1.Run)
changed := false
run.Finalizers = slices.DeleteFunc(run.ObjectMeta.Finalizers, func(i string) bool {
if i == v1.RunFinalizer {
changed = true
return true
}
return false
})
if changed {
return req.Client.Update(req.Ctx, run)
}
return nil
}
5 changes: 1 addition & 4 deletions pkg/controller/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,11 @@ func (c *Controller) setupRoutes() error {
oauthLogins := oauthapp.NewLogin(c.services.Invoker, c.services.ServerURL)

// Runs
root.Type(&v1.Run{}).HandlerFunc(runs.MigrateRemoveRunFinalizer) // to be removed
root.Type(&v1.Run{}).FinalizeFunc(v1.RunFinalizer, runs.DeleteRunState)
root.Type(&v1.Run{}).HandlerFunc(runs.DeleteFinished)
root.Type(&v1.Run{}).HandlerFunc(cleanup.Cleanup)
root.Type(&v1.Run{}).HandlerFunc(runs.Resume)

// RunStates
root.Type(&v1.RunState{}).HandlerFunc(cleanup.Cleanup)

// Threads
root.Type(&v1.Thread{}).HandlerFunc(cleanup.Cleanup)
root.Type(&v1.Thread{}).HandlerFunc(threads.CreateWorkspaces)
Expand Down
1 change: 1 addition & 0 deletions pkg/invoke/invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ func (i *Invoker) createRun(ctx context.Context, c kclient.WithWatch, thread *v1
ObjectMeta: metav1.ObjectMeta{
GenerateName: system.RunPrefix,
Namespace: thread.Namespace,
Finalizers: []string{v1.RunFinalizer},
},
Spec: v1.RunSpec{
Synchronous: opts.Synchronous,
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/apis/otto.otto8.ai/v1/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

const (
RunFinalizer = "otto.otto8.ai/run" // to be removed
RunFinalizer = "otto.otto8.ai/run"
KnowledgeFileFinalizer = "otto.otto8.ai/knowledge-file"
WorkspaceFinalizer = "otto.otto8.ai/workspace"
KnowledgeSetFinalizer = "otto.otto8.ai/knowledge-set"
Expand Down
4 changes: 1 addition & 3 deletions pkg/storage/apis/otto.otto8.ai/v1/runstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ type RunStateSpec struct {
}

func (in *RunState) DeleteRefs() []Ref {
return []Ref{
{ObjType: &Run{}, Name: in.Name, Namespace: in.Namespace},
}
return []Ref{}
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down