Skip to content

Commit

Permalink
Avoid logging error from updating status of a deleted workspace
Browse files Browse the repository at this point in the history
When the last finalizer on a DevWorkspace is cleared, the cluster may
garbage-collect that workspace immediately, which can result in the
object being deleted before we reach the point of attempting to update
the workspace's status. This results in logging a harmless but confusing
error, so we don't try to update the status for terminating workspaces
with no finalizers.

Signed-off-by: Angel Misevski <[email protected]>
  • Loading branch information
amisevsk committed Jul 4, 2022
1 parent 8865f7f commit e3805fb
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions controllers/workspace/finalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ func (r *DevWorkspaceReconciler) finalize(ctx context.Context, log logr.Logger,
finalizeStatus := &currentStatus{phase: devworkspacePhaseTerminating}
finalizeStatus.setConditionTrue(conditions.Started, "Cleaning up resources for deletion")
defer func() (reconcile.Result, error) {
if len(workspace.Finalizers) == 0 {
// If there are no finalizers on the workspace, the workspace may be garbage collected before we get to update
// its status. This avoids potentially logging a confusing error due to trying to set the status on a deleted
// workspace. This check has to be in the deferred function since updateWorkspaceStatus will be called after the
// client.Update() call that removes the last finalizer.
return finalizeResult, finalizeErr
}
return r.updateWorkspaceStatus(workspace, log, finalizeStatus, finalizeResult, finalizeErr)
}()

Expand Down

0 comments on commit e3805fb

Please sign in to comment.