@@ -188,12 +188,7 @@ func (r *WorkspaceReconciler) actOnStatus(ctx context.Context, workspace *worksp
188
188
switch {
189
189
// if there is a pod, and it's failed, delete it
190
190
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" )
197
192
198
193
// if the pod was stopped by request, delete it
199
194
case wsk8s .ConditionPresentAndTrue (workspace .Status .Conditions , string (workspacev1 .WorkspaceConditionStoppedByRequest )) && ! isPodBeingDeleted (pod ):
@@ -215,31 +210,14 @@ func (r *WorkspaceReconciler) actOnStatus(ctx context.Context, workspace *worksp
215
210
216
211
// if the workspace timed out, delete it
217
212
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" )
224
214
225
215
// if the content initialization failed, delete the pod
226
216
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" )
233
218
234
219
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" )
243
221
244
222
case workspace .Status .Headless && workspace .Status .Phase == workspacev1 .WorkspacePhaseStopped && ! isPodBeingDeleted (pod ):
245
223
// Workspace was requested to be deleted, propagate by deleting the Pod.
@@ -315,6 +293,22 @@ func (r *WorkspaceReconciler) updateMetrics(ctx context.Context, workspace *work
315
293
r .metrics .rememberWorkspace (workspace )
316
294
}
317
295
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
+
318
312
var (
319
313
wsOwnerKey = ".metadata.controller"
320
314
apiGVStr = workspacev1 .GroupVersion .String ()
0 commit comments