@@ -164,7 +164,13 @@ func (m *Manager) Close() {
164
164
}
165
165
166
166
// StartWorkspace creates a new running workspace within the manager's cluster
167
- func (m * Manager ) StartWorkspace (ctx context.Context , req * api.StartWorkspaceRequest ) (res * api.StartWorkspaceResponse , err error ) {
167
+ func (m * Manager ) StartWorkspace (_ context.Context , req * api.StartWorkspaceRequest ) (res * api.StartWorkspaceResponse , err error ) {
168
+ // We cannot use the passed context because we need to decouple the timeouts
169
+ // Create a context with a high timeout value to be able to wait for scale-up events in the cluster (slow operation)
170
+ // Important!!!: this timeout must be lower than https://github.com/gitpod-io/gitpod/blob/main/components/ws-manager-api/typescript/src/promisified-client.ts#L122
171
+ ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Minute )
172
+ defer cancel ()
173
+
168
174
owi := log .LogContext (req .Metadata .Owner , req .Metadata .MetaId , req .Id , req .Metadata .GetProject (), req .Metadata .GetTeam ())
169
175
clog := log .WithFields (owi )
170
176
span , ctx := tracing .FromContext (ctx , "StartWorkspace" )
@@ -314,8 +320,12 @@ func (m *Manager) StartWorkspace(ctx context.Context, req *api.StartWorkspaceReq
314
320
return nil , err
315
321
}
316
322
317
- err = wait .PollWithContext (ctx , 100 * time .Millisecond , 10 * time .Minute , podRunning (m .Clientset , pod .Name , pod .Namespace ))
323
+ // if we reach this point the pod is created
324
+ // in case the context is canceled or a timeout happens we should delete the pod?
325
+
326
+ err = wait .PollImmediateWithContext (ctx , 100 * time .Millisecond , 7 * time .Minute , podRunning (m .Clientset , pod .Name , pod .Namespace ))
318
327
if err != nil {
328
+ clog .WithError (err ).WithField ("req" , req ).WithField ("pod" , pod .Name ).Warn ("was unable to start workspace" )
319
329
return nil , xerrors .Errorf ("workspace pod never reached Running state: %w" , err )
320
330
}
321
331
@@ -326,7 +336,7 @@ func (m *Manager) StartWorkspace(ctx context.Context, req *api.StartWorkspaceReq
326
336
return nil , xerrors .Errorf ("unable to get workspace pod %s: %w" , pod .Name , err )
327
337
}
328
338
329
- err = wait .PollWithContext (ctx , 100 * time .Millisecond , 5 * time .Minute , pvcRunning (m .Clientset , pvc .Name , pvc .Namespace ))
339
+ err = wait .PollImmediateWithContext (ctx , 100 * time .Millisecond , 5 * time .Minute , pvcRunning (m .Clientset , pvc .Name , pvc .Namespace ))
330
340
if err != nil {
331
341
if startContext .VolumeSnapshot != nil && startContext .VolumeSnapshot .VolumeSnapshotName != "" {
332
342
m .eventRecorder .Eventf (pod , corev1 .EventTypeWarning , "PersistentVolumeClaim" , "PVC %q restore from volume snapshot %q failed %v" , pvc .Name , startContext .VolumeSnapshot .VolumeSnapshotName , err )
0 commit comments