mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
## Description This PR ensures that prebuilt workspaces are properly excluded from the lifecycle executor and treated as a separate class of workspaces, fully managed by the prebuild reconciliation loop. It introduces two lifecycle guarantees: * When a prebuilt workspace is created (i.e., when the workspace build completes), all lifecycle-related fields are unset, ensuring the workspace does not participate in TTL, autostop, autostart, dormancy, or auto-deletion logic. * When a prebuilt workspace is claimed, it transitions into a regular user workspace. At this point, all lifecycle fields are correctly populated according to template-level configurations, allowing the workspace to be managed by the lifecycle executor as expected. ## Changes * Prebuilt workspaces now have all lifecycle-relevant fields unset during creation * When a prebuild is claimed: * Lifecycle fields are set based on template and workspace level configurations. This ensures a clean transition into the standard workspace lifecycle flow. * Updated lifecycle-related SQL update queries to explicitly exclude prebuilt workspaces. ## Relates Related issue: https://github.com/coder/coder/issues/18898 To reduce the scope of this PR and make the review process more manageable, the original implementation has been split into the following focused PRs: * https://github.com/coder/coder/pull/19259 * https://github.com/coder/coder/pull/19263 * https://github.com/coder/coder/pull/19264 * https://github.com/coder/coder/pull/19265 These PRs should be considered in conjunction with this one to understand the complete set of lifecycle separation changes for prebuilt workspaces.
43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
package prebuilds
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/coder/coder/v2/coderd/database"
|
|
sdkproto "github.com/coder/coder/v2/provisionersdk/proto"
|
|
)
|
|
|
|
type NoopReconciler struct{}
|
|
|
|
func (NoopReconciler) Run(context.Context) {}
|
|
func (NoopReconciler) Stop(context.Context, error) {}
|
|
func (NoopReconciler) TrackResourceReplacement(context.Context, uuid.UUID, uuid.UUID, []*sdkproto.ResourceReplacement) {
|
|
}
|
|
func (NoopReconciler) ReconcileAll(context.Context) error { return nil }
|
|
func (NoopReconciler) SnapshotState(context.Context, database.Store) (*GlobalSnapshot, error) {
|
|
return &GlobalSnapshot{}, nil
|
|
}
|
|
func (NoopReconciler) ReconcilePreset(context.Context, PresetSnapshot) error { return nil }
|
|
func (NoopReconciler) CalculateActions(context.Context, PresetSnapshot) (*ReconciliationActions, error) {
|
|
return &ReconciliationActions{}, nil
|
|
}
|
|
|
|
var DefaultReconciler ReconciliationOrchestrator = NoopReconciler{}
|
|
|
|
type NoopClaimer struct{}
|
|
|
|
func (NoopClaimer) Claim(context.Context, time.Time, uuid.UUID, string, uuid.UUID, sql.NullString, sql.NullTime, sql.NullInt64) (*uuid.UUID, error) {
|
|
// Not entitled to claim prebuilds in AGPL version.
|
|
return nil, ErrAGPLDoesNotSupportPrebuiltWorkspaces
|
|
}
|
|
|
|
func (NoopClaimer) Initiator() uuid.UUID {
|
|
return uuid.Nil
|
|
}
|
|
|
|
var DefaultClaimer Claimer = NoopClaimer{}
|