Skip to content

Commit 9aeba20

Browse files
committed
[ws-daemon] Make sure to cleanup all workspace state for rejected pods
1 parent ac1c86b commit 9aeba20

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

components/ws-daemon/pkg/controller/workspace_controller.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,25 @@ func (wsc *WorkspaceController) handleWorkspaceStop(ctx context.Context, ws *wor
227227
span, ctx := opentracing.StartSpanFromContext(ctx, "handleWorkspaceStop")
228228
defer tracing.FinishSpan(span, &err)
229229

230+
if ws.IsConditionTrue(workspacev1.WorkspaceConditionPodRejected) {
231+
// in this case we are not interested in any backups, but instead are concerned with completely wiping all state that might be dangling somewhere
232+
log.Info("handling workspace stop - wiping mode")
233+
err = wsc.operations.DeleteWorkspace(ctx, ws.Name)
234+
if err != nil {
235+
wsc.emitEvent(ws, "Wiping", fmt.Errorf("failed to wipe workspace: %w", err))
236+
return ctrl.Result{}, fmt.Errorf("failed to wipe workspace: %w", err)
237+
}
238+
239+
return ctrl.Result{}, nil
240+
}
241+
242+
// regular case
243+
return wsc.doWorkspaceContentBackup(ctx, span, ws, req)
244+
}
245+
246+
func (wsc *WorkspaceController) doWorkspaceContentBackup(ctx context.Context, span opentracing.Span, ws *workspacev1.Workspace, req ctrl.Request) (result ctrl.Result, err error) {
247+
log := log.FromContext(ctx)
248+
230249
if c := wsk8s.GetCondition(ws.Status.Conditions, string(workspacev1.WorkspaceConditionContentReady)); c == nil || c.Status == metav1.ConditionFalse {
231250
return ctrl.Result{}, fmt.Errorf("workspace content was never ready")
232251
}

components/ws-manager-mk2/controllers/workspace_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ func (r *WorkspaceReconciler) actOnStatus(ctx context.Context, workspace *worksp
224224
workspace.Status.SetCondition(workspacev1.NewWorkspaceConditionPodRejected(fmt.Sprintf("Pod reached maximum recreations %d, failing", workspace.Status.PodRecreated), metav1.ConditionFalse))
225225
return ctrl.Result{Requeue: true}, nil // requeue so we end up in the "Stopped" case below
226226
}
227+
log.WithValues("PodStarts", workspace.Status.PodStarts, "PodRecreated", workspace.Status.PodRecreated, "Phase", workspace.Status.Phase).Info("trigger pod recreation")
227228

228229
// Must persist the modification pod starts, and ensure we retry on conflict.
229230
// If we fail to persist this value, it's possible that the Pod gets recreated endlessly

0 commit comments

Comments
 (0)