Skip to content

Commit bb8b645

Browse files
committed
[server] Respect projects.settings.usePersistentVolumeClaim during prebuild workspace creation
1 parent ad5b693 commit bb8b645

File tree

4 files changed

+19
-27
lines changed

4 files changed

+19
-27
lines changed

components/server/ee/src/prebuilds/prebuild-manager.ts

-9
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,8 @@ export class PrebuildManager {
249249
} else {
250250
span.setTag("starting", true);
251251
const projectEnvVars = await projectEnvVarsPromise;
252-
const usePVC = this.shouldUsePersistentVolumeClaim(project);
253252
await this.workspaceStarter.startWorkspace({ span }, workspace, user, [], projectEnvVars, {
254253
excludeFeatureFlags: ["full_workspace_backup"],
255-
pvcEnabledForPrebuilds: usePVC,
256254
});
257255
}
258256

@@ -322,13 +320,6 @@ export class PrebuildManager {
322320
return this.config.incrementalPrebuilds.repositoryPasslist.some((url) => trimRepoUrl(url) === repoUrl);
323321
}
324322

325-
protected shouldUsePersistentVolumeClaim(project?: Project): boolean {
326-
if (project?.settings?.usePersistentVolumeClaim) {
327-
return true;
328-
}
329-
return false;
330-
}
331-
332323
async fetchConfig(ctx: TraceContext, user: User, context: CommitContext): Promise<WorkspaceConfig> {
333324
const span = TraceContext.startSpan("fetchConfig", ctx);
334325
try {

components/server/ee/src/workspace/workspace-factory.ts

+17
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@ export class WorkspaceFactoryEE extends WorkspaceFactory {
166166
}
167167
ws.type = "prebuild";
168168
ws.projectId = project?.id;
169+
// Handle PVC propagation:
170+
if (!project?.settings?.usePersistentVolumeClaim) {
171+
if (ws.config._featureFlags) {
172+
// If PVC is disabled, we want to make sure that we remove that feature flag (in case the user enabled it!)
173+
// This is necessary to ensure if user has PVC enabled on their account, that they
174+
// will not hijack prebuild with PVC and make everyone who use this prebuild to auto enroll into PVC feature.
175+
ws.config._featureFlags = ws.config._featureFlags.filter((ff) => ff !== "persistent_volume_claim");
176+
}
177+
} else {
178+
// If PVC is enabled, we explicitly want all prebuilds to be stored that way.
179+
ws.config._featureFlags = (ws.config._featureFlags || []).concat(["persistent_volume_claim"]);
180+
}
169181
ws = await this.db.trace({ span }).store(ws);
170182

171183
const pws = await this.db.trace({ span }).storePrebuiltWorkspace({
@@ -318,6 +330,11 @@ export class WorkspaceFactoryEE extends WorkspaceFactory {
318330
}
319331
}
320332

333+
// Special case for PVC: While it's a workspace-persisted feature flag, we support the upgrade path (non-pvc -> pvc), so we apply it here
334+
if (user.featureFlags?.permanentWSFeatureFlags?.includes("persistent_volume_claim")) {
335+
config._featureFlags = (config._featureFlags || []).concat(["persistent_volume_claim"]);
336+
}
337+
321338
const id = await this.generateWorkspaceID(context);
322339
const newWs: Workspace = {
323340
id,

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

-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export class WorkspaceStarterEE extends WorkspaceStarter {
2424
user: User,
2525
excludeFeatureFlags: NamedWorkspaceFeatureFlag[],
2626
ideConfig: IDEConfig,
27-
pvcEnabledForPrebuilds: boolean,
2827
): Promise<WorkspaceInstance> {
2928
const instance = await super.newInstance(
3029
ctx,
@@ -33,7 +32,6 @@ export class WorkspaceStarterEE extends WorkspaceStarter {
3332
user,
3433
excludeFeatureFlags,
3534
ideConfig,
36-
pvcEnabledForPrebuilds,
3735
);
3836

3937
return instance;

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

+2-16
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ import {
5959
ProjectEnvVar,
6060
ImageBuildLogInfo,
6161
IDESettings,
62+
WithReferrerContext,
63+
EnvVarWithValue,
6264
} from "@gitpod/gitpod-protocol";
6365
import { IAnalyticsWriter } from "@gitpod/gitpod-protocol/lib/analytics";
6466
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
@@ -107,8 +109,6 @@ import { MessageBusIntegration } from "./messagebus-integration";
107109
import * as path from "path";
108110
import * as grpc from "@grpc/grpc-js";
109111
import { IDEConfig, IDEConfigService } from "../ide-config";
110-
import { EnvVarWithValue } from "@gitpod/gitpod-protocol/src/protocol";
111-
import { WithReferrerContext } from "@gitpod/gitpod-protocol/lib/protocol";
112112
import { IDEOption, IDEOptions } from "@gitpod/gitpod-protocol/lib/ide-protocol";
113113
import { Deferred } from "@gitpod/gitpod-protocol/lib/util/deferred";
114114
import { ExtendedUser } from "@gitpod/ws-manager/lib/constraints";
@@ -132,7 +132,6 @@ export interface StartWorkspaceOptions {
132132
rethrow?: boolean;
133133
forceDefaultImage?: boolean;
134134
excludeFeatureFlags?: NamedWorkspaceFeatureFlag[];
135-
pvcEnabledForPrebuilds?: boolean;
136135
}
137136

138137
const MAX_INSTANCE_START_RETRIES = 2;
@@ -364,7 +363,6 @@ export class WorkspaceStarter {
364363
user,
365364
options.excludeFeatureFlags || [],
366365
ideConfig,
367-
options.pvcEnabledForPrebuilds || false,
368366
),
369367
);
370368
span.log({ newInstance: instance.id });
@@ -759,7 +757,6 @@ export class WorkspaceStarter {
759757
user: User,
760758
excludeFeatureFlags: NamedWorkspaceFeatureFlag[],
761759
ideConfig: IDEConfig,
762-
pvcEnabledForPrebuilds: boolean,
763760
): Promise<WorkspaceInstance> {
764761
const span = TraceContext.startSpan("newInstance", ctx);
765762
//#endregion IDE resolution TODO(ak) move to IDE service
@@ -853,17 +850,6 @@ export class WorkspaceStarter {
853850

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

856-
if (workspace.type === "prebuild") {
857-
if (pvcEnabledForPrebuilds === true) {
858-
featureFlags = featureFlags.concat(["persistent_volume_claim"]);
859-
} else {
860-
// If PVC is disabled for prebuilds, we need to remove the PVC feature flag.
861-
// This is necessary to ensure if user has PVC enabled on their account, that they
862-
// will not hijack prebuild with PVC and make everyone who use this prebuild to auto enroll into PVC feature.
863-
featureFlags = featureFlags.filter((f) => f !== "persistent_volume_claim");
864-
}
865-
}
866-
867853
const userTeams = await this.teamDB.findTeamsByUser(user.id);
868854
const wsConnectionLimitingEnabled = await getExperimentsClientForBackend().getValueAsync(
869855
"workspace_connection_limiting",

0 commit comments

Comments
 (0)