Skip to content

Commit ea5adbf

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

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

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

Lines changed: 19 additions & 6 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,18 +133,27 @@ 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

147-
func (wsc *WorkspaceController) latestWorkspace(ctx context.Context, ws *workspacev1.Workspace) bool {
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.
148+
func (wsc *WorkspaceController) latestWorkspace(ctx context.Context, ws *workspacev1.Workspace) error {
148149
ws.Status.SetCondition(workspacev1.NewWorkspaceConditionRefresh())
149150

150151
err := wsc.Client.Status().Update(ctx, ws)
151-
return !errors.IsConflict(err)
152+
if err != nil && !errors.IsConflict(err) {
153+
glog.Warnf("could not refresh workspace: %v", err)
154+
}
155+
156+
return err
152157
}
153158

154159
func (wsc *WorkspaceController) handleWorkspaceInit(ctx context.Context, ws *workspacev1.Workspace, req ctrl.Request) (result ctrl.Result, err error) {
@@ -157,6 +162,10 @@ func (wsc *WorkspaceController) handleWorkspaceInit(ctx context.Context, ws *wor
157162
defer tracing.FinishSpan(span, &err)
158163

159164
if c := wsk8s.GetCondition(ws.Status.Conditions, string(workspacev1.WorkspaceConditionContentReady)); c == nil {
165+
if wsc.latestWorkspace(ctx, ws) != nil {
166+
return ctrl.Result{Requeue: true}, nil
167+
}
168+
160169
init, err := wsc.prepareInitializer(ctx, ws)
161170
if err != nil {
162171
return ctrl.Result{}, err
@@ -226,6 +235,10 @@ func (wsc *WorkspaceController) handleWorkspaceStop(ctx context.Context, ws *wor
226235
return ctrl.Result{}, nil
227236
}
228237

238+
if wsc.latestWorkspace(ctx, ws) != nil {
239+
return ctrl.Result{Requeue: true}, nil
240+
}
241+
229242
disposeStart := time.Now()
230243
var snapshotName string
231244
var snapshotUrl string

0 commit comments

Comments
 (0)