mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: exclude prebuilt workspaces from lifecycle executor (#18762)
## Description This PR updates the lifecycle executor to explicitly exclude prebuilt workspaces from being considered for lifecycle operations such as `autostart`, `autostop`, `dormancy`, `default TTL` and `failure TTL`. Prebuilt workspaces (i.e., those owned by the prebuild system user) are handled separately by the prebuild reconciliation loop. Including them in the lifecycle executor could lead to unintended behavior such as incorrect scheduling or state transitions. ## Changes * Updated the lifecycle executor query `GetWorkspacesEligibleForTransition` to exclude workspaces with `owner_id = 'c42fdf75-3097-471c-8c33-fb52454d81c0'` (prebuilds). * Added tests to verify prebuilt workspaces are not considered in: * Autostop * Autostart * Default TTL * Dormancy * Failure TTL Fixes: https://github.com/coder/coder/issues/18740 Related to: https://github.com/coder/coder/issues/18658
This commit is contained in:
@@ -204,6 +204,17 @@ func WorkspaceAgent(t testing.TB, db database.Store, orig database.WorkspaceAgen
|
||||
require.NoError(t, err, "update workspace agent first connected at")
|
||||
}
|
||||
|
||||
// If the lifecycle state is "ready", update the agent with the corresponding timestamps
|
||||
if orig.LifecycleState == database.WorkspaceAgentLifecycleStateReady && orig.StartedAt.Valid && orig.ReadyAt.Valid {
|
||||
err := db.UpdateWorkspaceAgentLifecycleStateByID(genCtx, database.UpdateWorkspaceAgentLifecycleStateByIDParams{
|
||||
ID: agt.ID,
|
||||
LifecycleState: orig.LifecycleState,
|
||||
StartedAt: orig.StartedAt,
|
||||
ReadyAt: orig.ReadyAt,
|
||||
})
|
||||
require.NoError(t, err, "update workspace agent lifecycle state")
|
||||
}
|
||||
|
||||
if orig.ParentID.UUID == uuid.Nil {
|
||||
// Add a test antagonist. For every agent we add a deleted sub agent
|
||||
// to discover cases where deletion should be handled.
|
||||
@@ -1352,6 +1363,17 @@ func PresetParameter(t testing.TB, db database.Store, seed database.InsertPreset
|
||||
return parameters
|
||||
}
|
||||
|
||||
func ClaimPrebuild(t testing.TB, db database.Store, newUserID uuid.UUID, newName string, presetID uuid.UUID) database.ClaimPrebuiltWorkspaceRow {
|
||||
claimedWorkspace, err := db.ClaimPrebuiltWorkspace(genCtx, database.ClaimPrebuiltWorkspaceParams{
|
||||
NewUserID: newUserID,
|
||||
NewName: newName,
|
||||
PresetID: presetID,
|
||||
})
|
||||
require.NoError(t, err, "claim prebuilt workspace")
|
||||
|
||||
return claimedWorkspace
|
||||
}
|
||||
|
||||
func provisionerJobTiming(t testing.TB, db database.Store, seed database.ProvisionerJobTiming) database.ProvisionerJobTiming {
|
||||
timing, err := db.InsertProvisionerJobTimings(genCtx, database.InsertProvisionerJobTimingsParams{
|
||||
JobID: takeFirst(seed.JobID, uuid.New()),
|
||||
|
||||
@@ -19971,7 +19971,12 @@ WHERE
|
||||
provisioner_jobs.completed_at IS NOT NULL AND
|
||||
($1 :: timestamptz) - provisioner_jobs.completed_at > (INTERVAL '1 millisecond' * (templates.failure_ttl / 1000000))
|
||||
)
|
||||
) AND workspaces.deleted = 'false'
|
||||
)
|
||||
AND workspaces.deleted = 'false'
|
||||
-- Prebuilt workspaces (identified by having the prebuilds system user as owner_id)
|
||||
-- should not be considered by the lifecycle executor, as they are handled by the
|
||||
-- prebuilds reconciliation loop.
|
||||
AND workspaces.owner_id != 'c42fdf75-3097-471c-8c33-fb52454d81c0'::UUID
|
||||
`
|
||||
|
||||
type GetWorkspacesEligibleForTransitionRow struct {
|
||||
|
||||
@@ -758,7 +758,12 @@ WHERE
|
||||
provisioner_jobs.completed_at IS NOT NULL AND
|
||||
(@now :: timestamptz) - provisioner_jobs.completed_at > (INTERVAL '1 millisecond' * (templates.failure_ttl / 1000000))
|
||||
)
|
||||
) AND workspaces.deleted = 'false';
|
||||
)
|
||||
AND workspaces.deleted = 'false'
|
||||
-- Prebuilt workspaces (identified by having the prebuilds system user as owner_id)
|
||||
-- should not be considered by the lifecycle executor, as they are handled by the
|
||||
-- prebuilds reconciliation loop.
|
||||
AND workspaces.owner_id != 'c42fdf75-3097-471c-8c33-fb52454d81c0'::UUID;
|
||||
|
||||
-- name: UpdateWorkspaceDormantDeletingAt :one
|
||||
UPDATE
|
||||
|
||||
Reference in New Issue
Block a user