From 320d620991a7e14de4de90c302dcc95f4e189b09 Mon Sep 17 00:00:00 2001 From: Donnie Adams Date: Thu, 16 Jan 2025 11:36:12 -0500 Subject: [PATCH 1/3] chore: bump kinm and nah to pick up data fixes Signed-off-by: Donnie Adams --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 7b3193d1d..33865b7be 100644 --- a/go.mod +++ b/go.mod @@ -24,8 +24,8 @@ require ( github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de github.com/mhale/smtpd v0.8.3 github.com/oauth2-proxy/oauth2-proxy/v7 v7.0.0-00010101000000-000000000000 - github.com/obot-platform/kinm v0.0.0-20250110042456-3848b881955b - github.com/obot-platform/nah v0.0.0-20241217120500-e9169e4a999f + github.com/obot-platform/kinm v0.0.0-20250116162656-270198b40c6d + github.com/obot-platform/nah v0.0.0-20250116162537-3bafada8cfb4 github.com/obot-platform/namegenerator v0.0.0-20241217121223-fc58bdb7dca2 github.com/obot-platform/obot/apiclient v0.0.0-00010101000000-000000000000 github.com/obot-platform/obot/logger v0.0.0-20241217130503-4004a5c69f32 diff --git a/go.sum b/go.sum index 4488568b1..cbcf12077 100644 --- a/go.sum +++ b/go.sum @@ -521,10 +521,10 @@ github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY= github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc= github.com/oauth2-proxy/mockoidc v0.0.0-20240214162133-caebfff84d25 h1:9bCMuD3TcnjeqjPT2gSlha4asp8NvgcFRYExCaikCxk= github.com/oauth2-proxy/mockoidc v0.0.0-20240214162133-caebfff84d25/go.mod h1:eDjgYHYDJbPLBLsyZ6qRaugP0mX8vePOhZ5id1fdzJw= -github.com/obot-platform/kinm v0.0.0-20250110042456-3848b881955b h1:1OzOajUTN+OQcffpFmr11e2NB4sjT/u4mSGYYzUs/D8= -github.com/obot-platform/kinm v0.0.0-20250110042456-3848b881955b/go.mod h1:RzrH0geIlbiTHDGZ8bpCk5k1hwdU9uu3l4zJn9n0pZU= -github.com/obot-platform/nah v0.0.0-20241217120500-e9169e4a999f h1:yyexIHgaPtNrfaPLxDx+xbnibJTKKJK05jDDlIqXC04= -github.com/obot-platform/nah v0.0.0-20241217120500-e9169e4a999f/go.mod h1:KG1jLO9FeYvCPGI0iDqe5oqDqOFLd3/dt/iwuMianmI= +github.com/obot-platform/kinm v0.0.0-20250116162656-270198b40c6d h1:GzMvRkssr4jAa2YvQiv9eXhjuNpaZVab3GajE7+cQ3s= +github.com/obot-platform/kinm v0.0.0-20250116162656-270198b40c6d/go.mod h1:RzrH0geIlbiTHDGZ8bpCk5k1hwdU9uu3l4zJn9n0pZU= +github.com/obot-platform/nah v0.0.0-20250116162537-3bafada8cfb4 h1:T5m+KSIXx0wTL1HdWngu1I6sCWI3tdfcJ+4Ud/vkHu4= +github.com/obot-platform/nah v0.0.0-20250116162537-3bafada8cfb4/go.mod h1:KG1jLO9FeYvCPGI0iDqe5oqDqOFLd3/dt/iwuMianmI= github.com/obot-platform/namegenerator v0.0.0-20241217121223-fc58bdb7dca2 h1:jiyBM/TYxU6UNVS9ff8Y8n55DOKDYohKkIZjfHpjfTY= github.com/obot-platform/namegenerator v0.0.0-20241217121223-fc58bdb7dca2/go.mod h1:isbKX6EfvvG/ojjFB2ZLyz27+2xoG3yRmpTSE+ytWEs= github.com/obot-platform/oauth2-proxy/v7 v7.0.0-20241008204315-265dabe17f43 h1:mlwIf3/uOo0ISweKuyFHhvPzSut4oQeWWpTkzsmTPgE= From 40edb2c271fb57679e2e9548685c2e73117f7b90 Mon Sep 17 00:00:00 2001 From: Donnie Adams Date: Thu, 16 Jan 2025 11:40:18 -0500 Subject: [PATCH 2/3] fix: stop considering passed-in time in next tick cron calculations Considering the passed-in time would create situations where, for a second, we would create as many workflows as we could make. Instead, don't consider the passed-in time and we will only create one. Signed-off-by: Donnie Adams --- pkg/api/handlers/cronjob.go | 2 +- pkg/controller/handlers/cronjob/cronjob.go | 2 +- pkg/controller/handlers/knowledgesource/reschedule.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/api/handlers/cronjob.go b/pkg/api/handlers/cronjob.go index d57cacbfa..8e7809f6d 100644 --- a/pkg/api/handlers/cronjob.go +++ b/pkg/api/handlers/cronjob.go @@ -134,7 +134,7 @@ func (a *CronJobHandler) Execute(req api.Context) error { func convertCronJob(cronJob v1.CronJob) types.CronJob { var nextRunAt *time.Time - if next, err := gronx.NextTick(cronjob.GetSchedule(cronJob), true); err == nil { + if next, err := gronx.NextTick(cronjob.GetSchedule(cronJob), false); err == nil { nextRunAt = &next } diff --git a/pkg/controller/handlers/cronjob/cronjob.go b/pkg/controller/handlers/cronjob/cronjob.go index 390c7db0d..784b6fc13 100644 --- a/pkg/controller/handlers/cronjob/cronjob.go +++ b/pkg/controller/handlers/cronjob/cronjob.go @@ -48,7 +48,7 @@ func (h *Handler) Run(req router.Request, resp router.Response) error { lastRun = &cj.CreationTimestamp } - next, err := gronx.NextTickAfter(GetSchedule(*cj), lastRun.Time, true) + next, err := gronx.NextTickAfter(GetSchedule(*cj), lastRun.Time, false) if err != nil { return fmt.Errorf("failed to parse schedule: %w", err) } diff --git a/pkg/controller/handlers/knowledgesource/reschedule.go b/pkg/controller/handlers/knowledgesource/reschedule.go index 2f100cf20..20dd96cf9 100644 --- a/pkg/controller/handlers/knowledgesource/reschedule.go +++ b/pkg/controller/handlers/knowledgesource/reschedule.go @@ -35,7 +35,7 @@ func (k *Handler) Reschedule(req router.Request, _ router.Response) error { return nil } - tick, err := gronx.NextTickAfter(source.Spec.Manifest.SyncSchedule, source.Status.LastSyncStartTime.Time, true) + tick, err := gronx.NextTickAfter(source.Spec.Manifest.SyncSchedule, source.Status.LastSyncStartTime.Time, false) if err != nil { source.Status.Error = fmt.Sprintf("failed to calculate next sync time: %v", err) source.Status.SyncState = types.KnowledgeSourceStateError From 196063424fefea24c130850dac36f17bc8326c92 Mon Sep 17 00:00:00 2001 From: Donnie Adams Date: Thu, 16 Jan 2025 11:41:02 -0500 Subject: [PATCH 3/3] fix: stop waiting for dependent workspace IDs Instead of waiting, which could create long delays, return no error and the handler will be triggered again when the dependent object changes. Signed-off-by: Donnie Adams --- .../handlers/workspace/workspace.go | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/pkg/controller/handlers/workspace/workspace.go b/pkg/controller/handlers/workspace/workspace.go index 8473a186c..474868f02 100644 --- a/pkg/controller/handlers/workspace/workspace.go +++ b/pkg/controller/handlers/workspace/workspace.go @@ -6,8 +6,6 @@ import ( "github.com/gptscript-ai/go-gptscript" "github.com/obot-platform/nah/pkg/router" v1 "github.com/obot-platform/obot/pkg/storage/apis/obot.obot.ai/v1" - "github.com/obot-platform/obot/pkg/wait" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" kclient "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -23,23 +21,19 @@ func New(gClient *gptscript.GPTScript, wp string) *Handler { } } -func getWorkspaceIDs(ctx context.Context, c kclient.WithWatch, ws *v1.Workspace) (wsIDs []string, _ error) { +func getWorkspaceIDs(ctx context.Context, c kclient.WithWatch, ws *v1.Workspace) ([]string, bool, error) { + var ( + wsIDs []string + dependentWS v1.Workspace + ) for _, wsName := range ws.Spec.FromWorkspaceNames { - ws, err := wait.For(ctx, c, &v1.Workspace{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: ws.Namespace, - Name: wsName, - }, - }, func(ws *v1.Workspace) (bool, error) { - return ws.Status.WorkspaceID != "", nil - }) - if err != nil { - return nil, err + if err := c.Get(ctx, router.Key(ws.Namespace, wsName), &dependentWS); err != nil || dependentWS.Status.WorkspaceID == "" { + return nil, false, err } wsIDs = append(wsIDs, ws.Status.WorkspaceID) } - return + return wsIDs, true, nil } func (a *Handler) CreateWorkspace(req router.Request, _ router.Response) error { @@ -49,8 +43,8 @@ func (a *Handler) CreateWorkspace(req router.Request, _ router.Response) error { } providerType := a.workspaceProvider - wsIDs, err := getWorkspaceIDs(req.Ctx, req.Client, ws) - if err != nil { + wsIDs, allReady, err := getWorkspaceIDs(req.Ctx, req.Client, ws) + if err != nil || !allReady { return err }