@@ -188,12 +188,7 @@ func (r *WorkspaceReconciler) actOnStatus(ctx context.Context, workspace *worksp
188188 switch {
189189 // if there is a pod, and it's failed, delete it
190190 case wsk8s .ConditionPresentAndTrue (workspace .Status .Conditions , string (workspacev1 .WorkspaceConditionFailed )) && ! isPodBeingDeleted (pod ):
191- err := r .Client .Delete (ctx , pod )
192- if errors .IsNotFound (err ) {
193- // pod is gone - nothing to do here
194- } else {
195- return ctrl.Result {Requeue : true }, err
196- }
191+ return r .deleteWorkspacePod (ctx , pod , "workspace failed" )
197192
198193 // if the pod was stopped by request, delete it
199194 case wsk8s .ConditionPresentAndTrue (workspace .Status .Conditions , string (workspacev1 .WorkspaceConditionStoppedByRequest )) && ! isPodBeingDeleted (pod ):
@@ -215,31 +210,14 @@ func (r *WorkspaceReconciler) actOnStatus(ctx context.Context, workspace *worksp
215210
216211 // if the workspace timed out, delete it
217212 case wsk8s .ConditionPresentAndTrue (workspace .Status .Conditions , string (workspacev1 .WorkspaceConditionTimeout )) && ! isPodBeingDeleted (pod ):
218- err := r .Client .Delete (ctx , pod )
219- if errors .IsNotFound (err ) {
220- // pod is gone - nothing to do here
221- } else {
222- return ctrl.Result {Requeue : true }, err
223- }
213+ return r .deleteWorkspacePod (ctx , pod , "timed out" )
224214
225215 // if the content initialization failed, delete the pod
226216 case wsk8s .ConditionWithStatusAndReason (workspace .Status .Conditions , string (workspacev1 .WorkspaceConditionContentReady ), false , "InitializationFailure" ) && ! isPodBeingDeleted (pod ):
227- err := r .Client .Delete (ctx , pod )
228- if errors .IsNotFound (err ) {
229- // pod is gone - nothing to do here
230- } else {
231- return ctrl.Result {Requeue : true }, err
232- }
217+ return r .deleteWorkspacePod (ctx , pod , "init failed" )
233218
234219 case isWorkspaceBeingDeleted (workspace ) && ! isPodBeingDeleted (pod ):
235- // Workspace was requested to be deleted, propagate by deleting the Pod.
236- // The Pod deletion will then trigger workspace disposal steps.
237- err := r .Client .Delete (ctx , pod )
238- if errors .IsNotFound (err ) {
239- // pod is gone - nothing to do here
240- } else {
241- return ctrl.Result {Requeue : true }, err
242- }
220+ return r .deleteWorkspacePod (ctx , pod , "workspace deleted" )
243221
244222 case workspace .Status .Headless && workspace .Status .Phase == workspacev1 .WorkspacePhaseStopped && ! isPodBeingDeleted (pod ):
245223 // Workspace was requested to be deleted, propagate by deleting the Pod.
@@ -315,6 +293,22 @@ func (r *WorkspaceReconciler) updateMetrics(ctx context.Context, workspace *work
315293 r .metrics .rememberWorkspace (workspace )
316294}
317295
296+ func (r * WorkspaceReconciler ) deleteWorkspacePod (ctx context.Context , pod * corev1.Pod , reason string ) (ctrl.Result , error ) {
297+ log := log .FromContext (ctx ).WithValues ("workspace" , pod .Name , "reason" , reason )
298+ log .V (1 ).Info ("deleting workspace pod" )
299+
300+ // Workspace was requested to be deleted, propagate by deleting the Pod.
301+ // The Pod deletion will then trigger workspace disposal steps.
302+ err := r .Client .Delete (ctx , pod )
303+ if errors .IsNotFound (err ) {
304+ // pod is gone - nothing to do here
305+ } else {
306+ return ctrl.Result {Requeue : true }, err
307+ }
308+
309+ return ctrl.Result {}, nil
310+ }
311+
318312var (
319313 wsOwnerKey = ".metadata.controller"
320314 apiGVStr = workspacev1 .GroupVersion .String ()
0 commit comments