@@ -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,18 +133,27 @@ 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
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 {
148
149
ws .Status .SetCondition (workspacev1 .NewWorkspaceConditionRefresh ())
149
150
150
151
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
152
157
}
153
158
154
159
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
157
162
defer tracing .FinishSpan (span , & err )
158
163
159
164
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
+
160
169
init , err := wsc .prepareInitializer (ctx , ws )
161
170
if err != nil {
162
171
return ctrl.Result {}, err
@@ -226,6 +235,10 @@ func (wsc *WorkspaceController) handleWorkspaceStop(ctx context.Context, ws *wor
226
235
return ctrl.Result {}, nil
227
236
}
228
237
238
+ if wsc .latestWorkspace (ctx , ws ) != nil {
239
+ return ctrl.Result {Requeue : true }, nil
240
+ }
241
+
229
242
disposeStart := time .Now ()
230
243
var snapshotName string
231
244
var snapshotUrl string
0 commit comments