Skip to content

Commit e06508b

Browse files
authored
[WorkspaceStarter] Don't call imageBuilder.needsImageBuild as we don't need it anymore (#18759)
Before, we used it to decide between handling the startWorkspace request sync or async. Now we are always async. And the check whether we actually need an image build is done in "build" anyway.
1 parent fff69c9 commit e06508b

File tree

1 file changed

+18
-83
lines changed

1 file changed

+18
-83
lines changed

components/server/src/workspace/workspace-starter.ts

Lines changed: 18 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ import {
7979
BuildStatus,
8080
ImageBuilderClientProvider,
8181
ResolveBaseImageRequest,
82-
ResolveWorkspaceImageRequest,
8382
} from "@gitpod/image-builder/lib";
8483
import {
8584
IDEImage,
@@ -368,31 +367,13 @@ export class WorkspaceStarter {
368367
workspace.context,
369368
);
370369

371-
const forceRebuild = !!workspace.context.forceImageBuild;
372-
try {
373-
// if we need to build the workspace image we must not wait for actuallyStartWorkspace to return as that would block the
374-
// frontend until the image is built.
375-
const additionalAuth = await this.getAdditionalImageAuth(envVars);
376-
const needsImageBuild =
377-
forceRebuild || (await this.needsImageBuild(ctx, user, workspace, instance, additionalAuth));
378-
if (needsImageBuild) {
379-
instance.status.conditions = {
380-
neededImageBuild: true,
381-
};
382-
}
383-
ctx.span?.setTag("needsImageBuild", needsImageBuild);
384-
} catch (err) {
385-
// if we fail to check if the workspace needs an image build (e.g. becuase the image builder is unavailable),
386-
// we must properly fail the workspace instance, i.e. set its status to stopped, deal with prebuilds etc.
387-
//
388-
// Once we've reached actuallyStartWorkspace that function will take care of failing the instance.
389-
await this.failInstanceStart(ctx, err, workspace, instance, abortSignal);
390-
throw err;
391-
}
392-
393-
await this.actuallyStartWorkspace(ctx, instance, workspace, user, envVars, abortSignal, forceRebuild);
370+
await this.actuallyStartWorkspace(ctx, instance, workspace, user, envVars, abortSignal);
394371
} catch (err) {
395-
log.error({ instanceId }, "error in reconcileWorkspaceStart", err);
372+
this.logAndTraceStartWorkspaceError(
373+
ctx,
374+
{ userId: user.id, workspaceId: workspace.id, instanceId },
375+
err,
376+
);
396377
} finally {
397378
ctx.span.finish();
398379
}
@@ -532,7 +513,6 @@ export class WorkspaceStarter {
532513
user: User,
533514
envVars: ResolvedEnvVars,
534515
abortSignal: RedlockAbortSignal,
535-
forceRebuild?: boolean,
536516
): Promise<void> {
537517
const span = TraceContext.startSpan("actuallyStartWorkspace", ctx);
538518
const region = instance.configuration.regionPreference;
@@ -543,6 +523,7 @@ export class WorkspaceStarter {
543523
organizationId: workspace.organizationId,
544524
workspaceId: workspace.id,
545525
};
526+
const forceRebuild = !!workspace.context.forceImageBuild;
546527
log.info(logCtx, "Attempting to start workspace", {
547528
forceRebuild: forceRebuild,
548529
});
@@ -661,6 +642,7 @@ export class WorkspaceStarter {
661642
} catch (err) {
662643
if (isGrpcError(err) && (err.code === grpc.status.UNAVAILABLE || err.code === grpc.status.ALREADY_EXISTS)) {
663644
// fall-through: we don't want to fail but retry/wait for future updates to resolve this
645+
log.warn(logCtx, "cannot start workspace instance due to temporary error", err);
664646
} else if (!(err instanceof StartInstanceError)) {
665647
// fallback in case we did not already handle this error
666648
await this.failInstanceStart({ span }, err, workspace, instance, abortSignal);
@@ -1146,62 +1128,6 @@ export class WorkspaceStarter {
11461128
}
11471129
}
11481130

1149-
private async needsImageBuild(
1150-
ctx: TraceContext,
1151-
user: User,
1152-
workspace: Workspace,
1153-
instance: WorkspaceInstance,
1154-
additionalAuth: Map<string, string>,
1155-
): Promise<boolean> {
1156-
const span = TraceContext.startSpan("needsImageBuild", ctx);
1157-
try {
1158-
const client = await this.getImageBuilderClient(
1159-
user,
1160-
workspace,
1161-
instance,
1162-
instance.configuration.regionPreference,
1163-
);
1164-
const { src, auth, disposable } = await this.prepareBuildRequest(
1165-
{ span },
1166-
workspace,
1167-
workspace.imageSource!,
1168-
user,
1169-
additionalAuth,
1170-
);
1171-
1172-
const req = new ResolveWorkspaceImageRequest();
1173-
req.setSource(src);
1174-
req.setAuth(auth);
1175-
const result = await client.resolveWorkspaceImage({ span }, req);
1176-
1177-
if (!!disposable) {
1178-
disposable.dispose();
1179-
}
1180-
1181-
if (result.getStatus() != BuildStatus.DONE_SUCCESS) {
1182-
log.info(
1183-
{
1184-
instanceId: instance.id,
1185-
userId: workspace.ownerId,
1186-
workspaceId: workspace.id,
1187-
organizationId: workspace.organizationId,
1188-
},
1189-
"Resolve workspace was unsuccessful",
1190-
{
1191-
buildStatus: result.getStatus(),
1192-
},
1193-
);
1194-
}
1195-
1196-
return result.getStatus() != BuildStatus.DONE_SUCCESS;
1197-
} catch (err) {
1198-
TraceContext.setError({ span }, err);
1199-
throw err;
1200-
} finally {
1201-
span.finish();
1202-
}
1203-
}
1204-
12051131
private async buildWorkspaceImage(
12061132
ctx: TraceContext,
12071133
user: User,
@@ -1266,6 +1192,11 @@ export class WorkspaceStarter {
12661192
const result = await client.build({ span }, req, imageBuildLogInfo);
12671193

12681194
if (result.actuallyNeedsBuild) {
1195+
instance.status.conditions = {
1196+
...instance.status.conditions,
1197+
neededImageBuild: true,
1198+
}; // Stored below
1199+
ctx.span?.setTag("needsImageBuild", true);
12691200
increaseImageBuildsStartedTotal();
12701201
}
12711202

@@ -1352,7 +1283,11 @@ export class WorkspaceStarter {
13521283
await this.failInstanceStart({ span }, err, workspace, instance, abortSignal);
13531284

13541285
const looksLikeUserError = (msg: string): boolean => {
1355-
return msg.startsWith("build failed:") || msg.includes("headless task failed:");
1286+
return (
1287+
msg.startsWith("build failed:") ||
1288+
msg.includes("headless task failed:") ||
1289+
msg.includes("cannot resolve image")
1290+
);
13561291
};
13571292
if (looksLikeUserError(message)) {
13581293
log.info(

0 commit comments

Comments
 (0)