MCPcopy Create free account
hub / github.com/coder/coder / provisionDelete

Method provisionDelete

enterprise/coderd/prebuilds/reconcile.go:954–973  ·  view source on GitHub ↗

provisionDelete provisions a delete transition for a prebuilt workspace. If mode is DeprovisionModeOrphan, the builder will not send Terraform state to the provisioner. This allows the workspace to be deleted even when no provisioners are available, and is safe when no Terraform resources were actu

(ctx context.Context, db database.Store, workspaceID uuid.UUID, templateID uuid.UUID, presetID uuid.UUID, mode DeprovisionMode)

Source from the content-addressed store, hash-verified

952// IMPORTANT: This function must be called within a database transaction. It does not create its own transaction.
953// The caller is responsible for managing the transaction boundary via db.InTx().
954func (c *StoreReconciler) provisionDelete(ctx context.Context, db database.Store, workspaceID uuid.UUID, templateID uuid.UUID, presetID uuid.UUID, mode DeprovisionMode) (*database.ProvisionerJob, error) {
955 workspace, err := db.GetWorkspaceByID(ctx, workspaceID)
956 if err != nil {
957 return nil, xerrors.Errorf("get workspace by ID: %w", err)
958 }
959
960 template, err := db.GetTemplateByID(ctx, templateID)
961 if err != nil {
962 return nil, xerrors.Errorf("failed to get template: %w", err)
963 }
964
965 if workspace.OwnerID != database.PrebuildsSystemUserID {
966 return nil, xerrors.Errorf("prebuilt workspace is not owned by prebuild user anymore, probably it was claimed")
967 }
968
969 c.logger.Info(ctx, "attempting to delete prebuild", slog.F("orphan", mode.String()),
970 slog.F("name", workspace.Name), slog.F("workspace_id", workspaceID.String()), slog.F("preset_id", presetID.String()))
971
972 return c.provision(ctx, db, workspaceID, template, presetID, database.WorkspaceTransitionDelete, workspace, mode)
973}
974
975// cancelAndOrphanDeletePendingPrebuilds cancels pending prebuild jobs from inactive template versions
976// and orphan-deletes their associated workspaces.

Calls 6

provisionMethod · 0.95
GetWorkspaceByIDMethod · 0.65
GetTemplateByIDMethod · 0.65
ErrorfMethod · 0.45
InfoMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected