Skip to content

Commit c828d41

Browse files
authored
[ws-manager-mk2] Remember existing workspaces after a restart (#17066)
1 parent 7ecc196 commit c828d41

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,9 @@ func (wsc *WorkspaceController) handleWorkspaceStop(ctx context.Context, ws *wor
302302
wsc.metrics.recordFinalizeTime(time.Since(disposeStart).Seconds(), ws)
303303
}
304304

305-
wsc.emitEvent(ws, "Backup", fmt.Errorf("failed to backup workspace: %w", disposeErr))
305+
if disposeErr != nil {
306+
wsc.emitEvent(ws, "Backup", fmt.Errorf("failed to backup workspace: %w", disposeErr))
307+
}
306308

307309
err = wsc.operations.DeleteWorkspace(ctx, ws.Name)
308310
if err != nil {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ func (m *controllerMetrics) countTotalRestoreFailures(log *logr.Logger, ws *work
186186
counter.Inc()
187187
}
188188

189+
func (m *controllerMetrics) containsWorkspace(ws *workspacev1.Workspace) bool {
190+
return m.cache.Contains(ws.Name)
191+
}
192+
189193
func (m *controllerMetrics) rememberWorkspace(ws *workspacev1.Workspace, state *metricState) {
190194
var s metricState
191195
if state != nil {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ func (r *WorkspaceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
148148
func (r *WorkspaceReconciler) actOnStatus(ctx context.Context, workspace *workspacev1.Workspace, workspacePods corev1.PodList) (ctrl.Result, error) {
149149
log := log.FromContext(ctx)
150150

151+
if workspace.Status.Phase != workspacev1.WorkspacePhaseStopped && !r.metrics.containsWorkspace(workspace) {
152+
// If the workspace hasn't stopped yet, and we don't know about this workspace yet, remember it.
153+
r.metrics.rememberWorkspace(workspace, nil)
154+
}
155+
151156
if len(workspacePods.Items) == 0 {
152157
// if there isn't a workspace pod and we're not currently deleting this workspace,// create one.
153158
switch {
@@ -193,7 +198,6 @@ func (r *WorkspaceReconciler) actOnStatus(ctx context.Context, workspace *worksp
193198

194199
r.Recorder.Event(workspace, corev1.EventTypeNormal, "Creating", "")
195200
}
196-
r.metrics.rememberWorkspace(workspace, nil)
197201

198202
case workspace.Status.Phase == workspacev1.WorkspacePhaseStopped:
199203
if err := r.deleteWorkspaceSecrets(ctx, workspace); err != nil {

0 commit comments

Comments
 (0)