Skip to content

Commit d46f156

Browse files
committed
check daemon last seen at
1 parent 9d3ea6f commit d46f156

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

coderd/wsbuilder/wsbuilder.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,18 +472,27 @@ func (b *Builder) buildTx(authFunc func(action policy.Action, object rbac.Object
472472
// There are cases where tagged provisioner daemons have been decommissioned
473473
// without deleting the relevant workspaces, and without any provisioners
474474
// available these workspaces cannot be deleted.
475-
if b.state.orphan && len(provisionerDaemons) == 0 {
475+
hasActiveEligibleProvisioner := false
476+
for _, pd := range provisionerDaemons {
477+
age := now.Sub(pd.ProvisionerDaemon.LastSeenAt.Time)
478+
if age <= provisionerdserver.StaleInterval {
479+
hasActiveEligibleProvisioner = true
480+
break
481+
}
482+
}
483+
if b.state.orphan && !hasActiveEligibleProvisioner {
476484
// nolint: gocritic // At this moment, we are pretending to be provisionerd.
477485
if err := store.UpdateProvisionerJobWithCompleteWithStartedAtByID(dbauthz.AsProvisionerd(b.ctx), database.UpdateProvisionerJobWithCompleteWithStartedAtByIDParams{
478486
CompletedAt: sql.NullTime{Valid: true, Time: now},
479-
Error: sql.NullString{Valid: true, String: "No provisioners were available to handle the orphan-delete request. The workspace was marked as deleted, but no resources were destroyed."},
487+
Error: sql.NullString{Valid: true, String: "No provisioners were available to handle the request. The workspace has been deleted. No resources were destroyed."},
480488
ErrorCode: sql.NullString{Valid: false},
481489
ID: provisionerJob.ID,
482490
StartedAt: sql.NullTime{Valid: true, Time: now},
483491
UpdatedAt: now,
484492
}); err != nil {
485493
return BuildError{http.StatusInternalServerError, "mark orphan-delete provisioner job as completed", err}
486494
}
495+
// TODO: audit baggage?
487496

488497
if err := store.UpdateWorkspaceDeletedByID(b.ctx, database.UpdateWorkspaceDeletedByIDParams{
489498
ID: b.workspace.ID,

coderd/wsbuilder/wsbuilder_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,8 +861,10 @@ func TestWorkspaceBuildDeleteOrphan(t *testing.T) {
861861
withRichParameters(nil),
862862
withWorkspaceTags(inactiveVersionID, nil),
863863
withProvisionerDaemons([]database.GetEligibleProvisionerDaemonsByProvisionerJobIDsRow{{
864-
JobID: inactiveJobID,
865-
ProvisionerDaemon: database.ProvisionerDaemon{},
864+
JobID: inactiveJobID,
865+
ProvisionerDaemon: database.ProvisionerDaemon{
866+
LastSeenAt: sql.NullTime{Valid: true, Time: dbtime.Now()},
867+
},
866868
}}),
867869

868870
// Outputs

0 commit comments

Comments
 (0)