@@ -123,10 +123,6 @@ func (wsc *WorkspaceController) Reconcile(ctx context.Context, req ctrl.Request)
123
123
return ctrl.Result {}, client .IgnoreNotFound (err )
124
124
}
125
125
126
- if ! wsc .latestWorkspace (ctx , & workspace ) {
127
- return ctrl.Result {Requeue : true }, nil
128
- }
129
-
130
126
glog .WithField ("workspaceID" , workspace .Name ).WithField ("phase" , workspace .Status .Phase ).Debug ("Reconcile workspace" )
131
127
132
128
if workspace .Status .Phase == workspacev1 .WorkspacePhaseCreating ||
@@ -137,13 +133,18 @@ func (wsc *WorkspaceController) Reconcile(ctx context.Context, req ctrl.Request)
137
133
}
138
134
139
135
if workspace .Status .Phase == workspacev1 .WorkspacePhaseStopping {
136
+
140
137
result , err = wsc .handleWorkspaceStop (ctx , & workspace , req )
141
138
return result , err
142
139
}
143
140
144
141
return ctrl.Result {}, nil
145
142
}
146
143
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.
147
148
func (wsc * WorkspaceController ) latestWorkspace (ctx context.Context , ws * workspacev1.Workspace ) bool {
148
149
ws .Status .SetCondition (workspacev1 .NewWorkspaceConditionRefresh ())
149
150
@@ -157,6 +158,10 @@ func (wsc *WorkspaceController) handleWorkspaceInit(ctx context.Context, ws *wor
157
158
defer tracing .FinishSpan (span , & err )
158
159
159
160
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
+
160
165
init , err := wsc .prepareInitializer (ctx , ws )
161
166
if err != nil {
162
167
return ctrl.Result {}, err
@@ -226,6 +231,10 @@ func (wsc *WorkspaceController) handleWorkspaceStop(ctx context.Context, ws *wor
226
231
return ctrl.Result {}, nil
227
232
}
228
233
234
+ if ! wsc .latestWorkspace (ctx , ws ) {
235
+ return ctrl.Result {Requeue : true }, nil
236
+ }
237
+
229
238
disposeStart := time .Now ()
230
239
var snapshotName string
231
240
var snapshotUrl string
0 commit comments