Repository navigation
fix: complete job and mark workspace as deleted when no provisioners are available - #18465
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR ensures that when an orphan-delete request finds no active provisioners, the builder marks the provisioner job as completed and the workspace as deleted. It also adds the UI hook for orphan deletion, updates in-memory DB behavior, and expands tests to cover the new orphan scenarios.
- Add
canOrphanflag and checkbox in the workspace delete dialog - Implement orphan-delete fallback in wsbuilder (complete job + delete workspace)
- Expand unit and integration tests to cover orphan-delete paths
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| site/src/modules/workspaces/WorkspaceMoreActions/WorkspaceDeleteDialog.tsx | Extract canOrphan and render orphan checkbox with updated text |
| coderd/wsbuilder/wsbuilder.go | Orphan-delete logic: complete provisioner job and mark workspace deleted when no provisioners available |
| coderd/wsbuilder/wsbuilder_test.go | New tests for orphan-delete with and without available provisioners |
| coderd/workspacebuilds.go | Use qpr variable to pass provisioner job info into conversion |
| coderd/workspacebuilds_test.go | Import dbfake and add subtests for orphan build errors and permissions |
| coderd/database/dbmem/dbmem.go | Return empty slice instead of sql.ErrNoRows for no provisioner daemons |
| cli/delete_test.go | Update CLI delete test to cover --orphan behavior and status codes |
Comments suppressed due to low confidence (2)
site/src/modules/workspaces/WorkspaceMoreActions/WorkspaceDeleteDialog.tsx:53
- [nitpick] Add frontend tests to verify that the "Orphan Resources" checkbox appears only when
canOrphanis true and is hidden otherwise.
const canOrphan =
coderd/wsbuilder/wsbuilder.go:495
- Implement or remove the TODO for audit baggage so that delete transitions are properly logged in the audit system.
// TODO: audit baggage?
| client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true}) | ||
| first := coderdtest.CreateFirstUser(t, client) | ||
|
|
||
| ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) | ||
| defer cancel() |
There was a problem hiding this comment.
review: refactored to use dbfake instead
| _, err = client.Workspace(ctx, workspace.ID) | ||
| require.Error(t, err) | ||
| require.Equal(t, http.StatusGone, coderdtest.SDKError(t, err).StatusCode()) |
There was a problem hiding this comment.
review: moved this check to the relevant CLI test
dannykopping
left a comment
There was a problem hiding this comment.
A few nits but LGTM
| @@ -484,7 +486,7 @@ func (b *Builder) buildTx(authFunc func(action policy.Action, object rbac.Object | |||
| // nolint: gocritic // At this moment, we are pretending to be provisionerd. | |||
| if err := store.UpdateProvisionerJobWithCompleteWithStartedAtByID(dbauthz.AsProvisionerd(b.ctx), database.UpdateProvisionerJobWithCompleteWithStartedAtByIDParams{ | |||
There was a problem hiding this comment.
Can we please log that this has occurred?
There was a problem hiding this comment.
Logging in the API handler where we do the auditing.
|
Follow-up issue: coder/internal#740 |
Alternate fix for #18080
Modifies wsbuilder to complete the provisioner job and mark the workspace as deleted if it is clear that no provisioner will be able to pick up the delete build.
This has a significant advantage of not deviating too much from the current semantics of
POST /api/v2/workspacebuilds. #18460 ends up returning a 204 on orphan delete due to no build being created.Downside is that we have to duplicate some responsibilities of provisionerdserver in wsbuilder.
There is a slight gotcha to this approach though: if you stop a provisioner and then immediately try to orphan-delete, the job will still be created because of the provisioner heartbeat interval. However you can cancel it and try again.