@@ -181,24 +181,6 @@ func (r *WorkspaceReconciler) actOnStatus(ctx context.Context, workspace *worksp
181181 // if there isn't a workspace pod and we're not currently deleting this workspace,// create one.
182182 switch {
183183 case workspace .Status .PodStarts == 0 || workspace .Status .PodStarts - workspace .Status .PodRecreated < 1 :
184- if workspace .Status .PodRecreated > 0 {
185- // This is a re-creation: Make sure to wait at least for
186- c := wsk8s .GetCondition (workspace .Status .Conditions , string (workspacev1 .WorkspaceConditionPodRejected ))
187- if c == nil {
188- err = fmt .Errorf ("failed to retrieve PodRejected condition" )
189- log .Error (err , "failed to trigger pod recreation" )
190- return ctrl.Result {}, err
191- }
192-
193- recreationTimeout := r .podRecreationTimeout ()
194- waitTime := time .Until (c .LastTransitionTime .Add (recreationTimeout ))
195- if waitTime > 0 {
196- log .WithValues ("waitTime" , waitTime ).Info ("waiting for pod recreation timeout" )
197- return ctrl.Result {Requeue : true , RequeueAfter : waitTime }, nil
198- }
199- log .WithValues ("waitedTime" , waitTime .Abs ().String ()).Info ("waited for pod recreation timeout" )
200- }
201-
202184 sctx , err := newStartWorkspaceContext (ctx , r .Config , workspace )
203185 if err != nil {
204186 log .Error (err , "unable to create startWorkspace context" )
@@ -244,6 +226,21 @@ func (r *WorkspaceReconciler) actOnStatus(ctx context.Context, workspace *worksp
244226 }
245227 log .WithValues ("PodStarts" , workspace .Status .PodStarts , "PodRecreated" , workspace .Status .PodRecreated , "Phase" , workspace .Status .Phase ).Info ("trigger pod recreation" )
246228
229+ // Make sure to wait for "recreationTimeout" before creating the pod again
230+ if workspace .Status .PodDeletionTime == nil {
231+ log .Info ("want to wait for pod recreation timeout, but podDeletionTime not set (yet)" )
232+ return ctrl.Result {Requeue : true , RequeueAfter : 5 * time .Second }, nil
233+ }
234+
235+ recreationTimeout := r .podRecreationTimeout ()
236+ podDeletionTime := workspace .Status .PodDeletionTime .Time
237+ waitTime := time .Until (podDeletionTime .Add (recreationTimeout ))
238+ if waitTime > 0 {
239+ log .WithValues ("waitTime" , waitTime ).Info ("waiting for pod recreation timeout" )
240+ return ctrl.Result {Requeue : true , RequeueAfter : waitTime }, nil
241+ }
242+ log .WithValues ("waitedTime" , waitTime .Abs ().String ()).Info ("waited for pod recreation timeout" )
243+
247244 // Must persist the modification pod starts, and ensure we retry on conflict.
248245 // If we fail to persist this value, it's possible that the Pod gets recreated endlessly
249246 // when the workspace stops, due to PodStarts still being 0 when the original Pod
@@ -269,8 +266,7 @@ func (r *WorkspaceReconciler) actOnStatus(ctx context.Context, workspace *worksp
269266 r .metrics .forgetWorkspace (workspace )
270267
271268 r .Recorder .Event (workspace , corev1 .EventTypeNormal , "Recreating" , "" )
272- requeueAfter := r .podRecreationTimeout ()
273- return ctrl.Result {Requeue : true , RequeueAfter : requeueAfter }, nil
269+ return ctrl.Result {Requeue : true }, nil
274270
275271 case workspace .Status .Phase == workspacev1 .WorkspacePhaseStopped :
276272 if err := r .deleteWorkspaceSecrets (ctx , workspace ); err != nil {
@@ -377,7 +373,7 @@ func (r *WorkspaceReconciler) actOnStatus(ctx context.Context, workspace *worksp
377373}
378374
379375func (r * WorkspaceReconciler ) podRecreationTimeout () time.Duration {
380- recreationTimeout := 5 * time .Second
376+ recreationTimeout := 15 * time .Second // waiting less time creates issues with ws-daemon's pod-centric control loop ("Dispatch") if the workspace ends up on the same node again
381377 if r .Config .PodRecreationBackoff != 0 {
382378 recreationTimeout = time .Duration (r .Config .PodRecreationBackoff )
383379 }
0 commit comments