Skip to content

Commit 918949e

Browse files
committed
Refactor Manager StartWorkspace
1 parent d954d32 commit 918949e

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

components/ws-manager-api/typescript/src/promisified-client.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,17 @@ export class PromisifiedWorkspaceManagerClient implements Disposable {
117117
this.client.startWorkspace(
118118
request,
119119
withTracing({ span }),
120-
this.getDefaultUnaryOptions(),
120+
{
121+
// Important!!!!: client timeout must be higher than ws-manager to be able to process any error
122+
// https://github.com/gitpod-io/gitpod/blob/main/components/ws-manager/pkg/manager/manager.go#L171
123+
deadline: new Date(new Date().getTime() + 60000*11),
124+
interceptors: this.interceptor,
125+
},
121126
(err, resp) => {
122127
span.finish();
123128
if (err) {
124-
if (attempt < 3 && err.message.indexOf("already exists") !== -1) {
125-
// lets wait a bit more
126-
} else {
127-
TraceContext.setError(ctx, err);
128-
reject(err);
129-
}
129+
TraceContext.setError(ctx, err);
130+
reject(err);
130131
} else {
131132
resolve(resp);
132133
}

components/ws-manager/pkg/manager/manager.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,13 @@ func (m *Manager) Close() {
164164
}
165165

166166
// 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+
168174
owi := log.LogContext(req.Metadata.Owner, req.Metadata.MetaId, req.Id, req.Metadata.GetProject(), req.Metadata.GetTeam())
169175
clog := log.WithFields(owi)
170176
span, ctx := tracing.FromContext(ctx, "StartWorkspace")
@@ -314,8 +320,12 @@ func (m *Manager) StartWorkspace(ctx context.Context, req *api.StartWorkspaceReq
314320
return nil, err
315321
}
316322

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))
318327
if err != nil {
328+
clog.WithError(err).WithField("req", req).WithField("pod", pod.Name).Warn("was unable to start workspace")
319329
return nil, xerrors.Errorf("workspace pod never reached Running state: %w", err)
320330
}
321331

@@ -326,7 +336,7 @@ func (m *Manager) StartWorkspace(ctx context.Context, req *api.StartWorkspaceReq
326336
return nil, xerrors.Errorf("unable to get workspace pod %s: %w", pod.Name, err)
327337
}
328338

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))
330340
if err != nil {
331341
if startContext.VolumeSnapshot != nil && startContext.VolumeSnapshot.VolumeSnapshotName != "" {
332342
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

Comments
 (0)