-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[fga] Workspace: create, get, stop and delete #18403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
b4f85c3
eb1e4cc
470d6c2
a1e5387
6b8acb5
9e4adba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -12,6 +12,7 @@ import { TracedWorkspaceDB, DBWithTracing, WorkspaceDB } from "@gitpod/gitpod-db | |||
import { TraceContext } from "@gitpod/gitpod-protocol/lib/util/tracing"; | ||||
import { Config } from "../config"; | ||||
import { Job } from "./runner"; | ||||
import { WorkspaceService } from "../workspace/workspace-service"; | ||||
|
||||
/** | ||||
* The WorkspaceGarbageCollector has two tasks: | ||||
|
@@ -20,6 +21,7 @@ import { Job } from "./runner"; | |||
*/ | ||||
@injectable() | ||||
export class WorkspaceGarbageCollector implements Job { | ||||
@inject(WorkspaceService) protected readonly workspaceService: WorkspaceService; | ||||
@inject(WorkspaceDeletionService) protected readonly deletionService: WorkspaceDeletionService; | ||||
@inject(TracedWorkspaceDB) protected readonly workspaceDB: DBWithTracing<WorkspaceDB>; | ||||
@inject(Config) protected readonly config: Config; | ||||
|
@@ -70,7 +72,7 @@ export class WorkspaceGarbageCollector implements Job { | |||
); | ||||
const afterSelect = new Date(); | ||||
const deletes = await Promise.all( | ||||
workspaces.map((ws) => this.deletionService.softDeleteWorkspace({ span }, ws, "gc")), | ||||
workspaces.map((ws) => this.workspaceService.deleteWorkspace(ws.ownerId, ws.id, "gc")), // TODO(gpl) This should be a system user/service account instead of ws owner | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would work, but is not correct as this is not triggered by the owner but by the system. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I was not aware that we have a way ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'm not particularly satisfied with that choice for the protocol. But I liked it better than introducing a system ID or anything else I could think of. 🤷 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @svenefftinge Could you shoot me a link to an example? I can't find one on main atm, and wonder if you meant setting all userId types to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After looking at the change, I really thing we should make this a separate argument, instead of overriding userId for the security reasons. Let's discuss in sync. 👍 |
||||
); | ||||
const afterDelete = new Date(); | ||||
|
||||
|
@@ -125,7 +127,17 @@ export class WorkspaceGarbageCollector implements Job { | |||
now, | ||||
); | ||||
const deletes = await Promise.all( | ||||
workspaces.map((ws) => this.deletionService.hardDeleteWorkspace({ span }, ws.id)), | ||||
workspaces.map((ws) => | ||||
this.workspaceService | ||||
.hardDeleteWorkspace(ws.ownerId, ws.id) | ||||
.catch((err) => | ||||
log.error( | ||||
{ userId: ws.ownerId, workspaceId: ws.id }, | ||||
"failed to hard-delete workspace", | ||||
err, | ||||
), | ||||
), | ||||
), // TODO(gpl) This should be a system user/service account instead of ws owner | ||||
); | ||||
|
||||
log.info(`workspace-gc: successfully purged ${deletes.length} workspaces`); | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,6 @@ import { | |
import { log } from "@gitpod/gitpod-protocol/lib/util/logging"; | ||
import { TraceContext } from "@gitpod/gitpod-protocol/lib/util/tracing"; | ||
import { getCommitInfo, HostContextProvider } from "../auth/host-context-provider"; | ||
import { WorkspaceFactory } from "../workspace/workspace-factory"; | ||
import { ConfigProvider } from "../workspace/config-provider"; | ||
import { WorkspaceStarter } from "../workspace/workspace-starter"; | ||
import { Config } from "../config"; | ||
|
@@ -38,6 +37,7 @@ import { ErrorCodes, ApplicationError } from "@gitpod/gitpod-protocol/lib/messag | |
import { UserAuthentication } from "../user/user-authentication"; | ||
import { EntitlementService, MayStartWorkspaceResult } from "../billing/entitlement-service"; | ||
import { EnvVarService } from "../workspace/env-var-service"; | ||
import { WorkspaceService } from "../workspace/workspace-service"; | ||
|
||
export class WorkspaceRunningError extends Error { | ||
constructor(msg: string, public instance: WorkspaceInstance) { | ||
|
@@ -56,7 +56,7 @@ export interface StartPrebuildParams { | |
@injectable() | ||
export class PrebuildManager { | ||
@inject(TracedWorkspaceDB) protected readonly workspaceDB: DBWithTracing<WorkspaceDB>; | ||
@inject(WorkspaceFactory) protected readonly workspaceFactory: WorkspaceFactory; | ||
@inject(WorkspaceService) protected readonly workspaceService: WorkspaceService; | ||
@inject(WorkspaceStarter) protected readonly workspaceStarter: WorkspaceStarter; | ||
@inject(HostContextProvider) protected readonly hostContextProvider: HostContextProvider; | ||
@inject(ConfigProvider) protected readonly configProvider: ConfigProvider; | ||
|
@@ -77,21 +77,18 @@ export class PrebuildManager { | |
const results: Promise<any>[] = []; | ||
for (const prebuild of prebuilds) { | ||
try { | ||
for (const instance of prebuild.instances) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No clue why we would cycle over instances here before. I could imagine this was to mitigate some weird behavior we had in the past. 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I just noticed that same code paths did not emit |
||
log.info( | ||
{ userId: user.id, instanceId: instance.id, workspaceId: instance.workspaceId }, | ||
"Cancelling Prebuild workspace because a newer commit was pushed to the same branch.", | ||
); | ||
results.push( | ||
this.workspaceStarter.stopWorkspaceInstance( | ||
{ span }, | ||
instance.id, | ||
instance.region, | ||
"prebuild cancelled because a newer commit was pushed to the same branch", | ||
StopWorkspacePolicy.ABORT, | ||
), | ||
); | ||
} | ||
log.info( | ||
{ userId: user.id, workspaceId: prebuild.workspace.id }, | ||
"Cancelling Prebuild workspace because a newer commit was pushed to the same branch.", | ||
); | ||
results.push( | ||
this.workspaceService.stopWorkspace( | ||
user.id, | ||
prebuild.workspace.id, | ||
"prebuild cancelled because a newer commit was pushed to the same branch", | ||
StopWorkspacePolicy.ABORT, | ||
), | ||
); | ||
prebuild.prebuild.state = "aborted"; | ||
prebuild.prebuild.error = "A newer commit was pushed to the same branch."; | ||
results.push(this.workspaceDB.trace({ span }).storePrebuiltWorkspace(prebuild.prebuild)); | ||
|
@@ -224,7 +221,7 @@ export class PrebuildManager { | |
} | ||
} | ||
|
||
const workspace = await this.workspaceFactory.createForContext( | ||
const workspace = await this.workspaceService.createWorkspace( | ||
{ span }, | ||
user, | ||
project.teamId, | ||
|
Uh oh!
There was an error while loading. Please reload this page.