Skip to content

[server] ensure that user that has PVC enabled will not force prebuilds into PVC use #12165

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

Merged
merged 1 commit into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/server/ee/src/prebuilds/prebuild-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export class PrebuildManager {
const usePVC = this.shouldUsePersistentVolumeClaim(project);
await this.workspaceStarter.startWorkspace({ span }, workspace, user, [], projectEnvVars, {
excludeFeatureFlags: ["full_workspace_backup"],
forcePVC: usePVC,
pvcEnabledForPrebuilds: usePVC,
});
}

Expand Down
4 changes: 2 additions & 2 deletions components/server/ee/src/workspace/workspace-starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class WorkspaceStarterEE extends WorkspaceStarter {
user: User,
excludeFeatureFlags: NamedWorkspaceFeatureFlag[],
ideConfig: IDEConfig,
forcePVC: boolean,
pvcEnabledForPrebuilds: boolean,
): Promise<WorkspaceInstance> {
const instance = await super.newInstance(
ctx,
Expand All @@ -33,7 +33,7 @@ export class WorkspaceStarterEE extends WorkspaceStarter {
user,
excludeFeatureFlags,
ideConfig,
forcePVC,
pvcEnabledForPrebuilds,
);

return instance;
Expand Down
20 changes: 14 additions & 6 deletions components/server/src/workspace/workspace-starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export interface StartWorkspaceOptions {
rethrow?: boolean;
forceDefaultImage?: boolean;
excludeFeatureFlags?: NamedWorkspaceFeatureFlag[];
forcePVC?: boolean;
pvcEnabledForPrebuilds?: boolean;
}

const MAX_INSTANCE_START_RETRIES = 2;
Expand Down Expand Up @@ -352,7 +352,7 @@ export class WorkspaceStarter {
user,
options.excludeFeatureFlags || [],
ideConfig,
options.forcePVC || false,
options.pvcEnabledForPrebuilds || false,
),
);
span.log({ newInstance: instance.id });
Expand Down Expand Up @@ -743,7 +743,7 @@ export class WorkspaceStarter {
user: User,
excludeFeatureFlags: NamedWorkspaceFeatureFlag[],
ideConfig: IDEConfig,
forcePVC: boolean,
pvcEnabledForPrebuilds: boolean,
): Promise<WorkspaceInstance> {
const span = TraceContext.startSpan("buildWorkspaceImage", ctx);
//#endregion IDE resolution TODO(ak) move to IDE service
Expand Down Expand Up @@ -828,8 +828,15 @@ export class WorkspaceStarter {

featureFlags = featureFlags.filter((f) => !excludeFeatureFlags.includes(f));

if (forcePVC === true) {
featureFlags = featureFlags.concat(["persistent_volume_claim"]);
if (workspace.type === "prebuild") {
if (pvcEnabledForPrebuilds === true) {
featureFlags = featureFlags.concat(["persistent_volume_claim"]);
} else {
// If PVC is disabled for prebuilds, we need to remove the PVC feature flag.
// This is necessary to ensure if user has PVC enabled on their account, that they
// will not hijack prebuild with PVC and make everyone who use this prebuild to auto enroll into PVC feature.
featureFlags = featureFlags.filter((f) => f !== "persistent_volume_claim");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

}
}

let workspaceClass = "";
Expand Down Expand Up @@ -1428,7 +1435,8 @@ export class WorkspaceStarter {
}

const volumeSnapshotId =
((SnapshotContext.is(workspace.context) || WithPrebuild.is(workspace.context)) && !!workspace.context.snapshotBucketId)
(SnapshotContext.is(workspace.context) || WithPrebuild.is(workspace.context)) &&
!!workspace.context.snapshotBucketId
? workspace.context.snapshotBucketId
: lastValidWorkspaceInstanceId;

Expand Down