Skip to content

Commit e83d563

Browse files
committed
[ws-daemon] Review comments
1 parent 10bea8a commit e83d563

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,6 @@ func (wsc *WorkspaceController) Reconcile(ctx context.Context, req ctrl.Request)
123123
return ctrl.Result{}, client.IgnoreNotFound(err)
124124
}
125125

126-
if !wsc.latestWorkspace(ctx, &workspace) {
127-
return ctrl.Result{Requeue: true}, nil
128-
}
129-
130126
glog.WithField("workspaceID", workspace.Name).WithField("phase", workspace.Status.Phase).Debug("Reconcile workspace")
131127

132128
if workspace.Status.Phase == workspacev1.WorkspacePhaseCreating ||
@@ -137,13 +133,18 @@ func (wsc *WorkspaceController) Reconcile(ctx context.Context, req ctrl.Request)
137133
}
138134

139135
if workspace.Status.Phase == workspacev1.WorkspacePhaseStopping {
136+
140137
result, err = wsc.handleWorkspaceStop(ctx, &workspace, req)
141138
return result, err
142139
}
143140

144141
return ctrl.Result{}, nil
145142
}
146143

144+
// latestWorkspace checks if the we have the latest generation of the workspace CR. We do this because
145+
// the cache could be stale and we retrieve a workspace CR that does not have the content init/backup
146+
// conditions even though we have set them previously. This will lead to us performing these operations
147+
// again. To prevent this we wait until we have the latest workspace CR.
147148
func (wsc *WorkspaceController) latestWorkspace(ctx context.Context, ws *workspacev1.Workspace) bool {
148149
ws.Status.SetCondition(workspacev1.NewWorkspaceConditionRefresh())
149150

@@ -157,6 +158,10 @@ func (wsc *WorkspaceController) handleWorkspaceInit(ctx context.Context, ws *wor
157158
defer tracing.FinishSpan(span, &err)
158159

159160
if c := wsk8s.GetCondition(ws.Status.Conditions, string(workspacev1.WorkspaceConditionContentReady)); c == nil {
161+
if !wsc.latestWorkspace(ctx, ws) {
162+
return ctrl.Result{Requeue: true}, nil
163+
}
164+
160165
init, err := wsc.prepareInitializer(ctx, ws)
161166
if err != nil {
162167
return ctrl.Result{}, err
@@ -226,6 +231,10 @@ func (wsc *WorkspaceController) handleWorkspaceStop(ctx context.Context, ws *wor
226231
return ctrl.Result{}, nil
227232
}
228233

234+
if !wsc.latestWorkspace(ctx, ws) {
235+
return ctrl.Result{Requeue: true}, nil
236+
}
237+
229238
disposeStart := time.Now()
230239
var snapshotName string
231240
var snapshotUrl string

0 commit comments

Comments
 (0)