Skip to content

[server] simplify workspace classes #15091

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
Dec 1, 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
3 changes: 0 additions & 3 deletions components/dashboard/src/admin/ProjectDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ export default function ProjectDetail(props: { project: Project; owner: string |
<Property name="Incremental Prebuilds">
{props.project.settings?.useIncrementalPrebuilds ? "Yes" : "No"}
</Property>
<Property name="Persistent Volume Claim">
{props.project.settings?.usePersistentVolumeClaim ? "Yes" : "No"}
</Property>
<Property name="Marked Deleted">{props.project.markedDeleted ? "Yes" : "No"}</Property>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions components/dashboard/src/service/service-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,15 @@ const gitpodServiceMock = createServiceMock({
displayName: "Standard",
description: "Up to 4 vCPU, 8GB memory, 30GB disk",
powerups: 1,
isSelected: true,
isDefault: true,
},
{
id: "g1-large",
category: "GENERAL PURPOSE",
displayName: "Large",
description: "Up to 8 vCPU, 16GB memory, 50GB disk",
powerups: 2,
isSelected: false,
isDefault: false,
},
];
},
Expand Down
23 changes: 1 addition & 22 deletions components/dashboard/src/settings/Preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ import { ThemeContext } from "../theme-context";
import { UserContext } from "../user-context";
import { trackEvent } from "../Analytics";
import SelectIDE from "./SelectIDE";
import SelectWorkspaceClass from "./selectClass";
import { PageWithSettingsSubMenu } from "./PageWithSettingsSubMenu";
import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode";
import { WorkspaceClasses } from "@gitpod/gitpod-protocol";

type Theme = "light" | "dark" | "system";

export default function Preferences() {
const { user, userBillingMode } = useContext(UserContext);
const { user } = useContext(UserContext);
const { setIsDark } = useContext(ThemeContext);

const [theme, setTheme] = useState<Theme>(localStorage.theme || "system");
Expand Down Expand Up @@ -50,30 +47,12 @@ export default function Preferences() {
}
};

const setWorkspaceClass = async (value: string) => {
const additionalData = user?.additionalData || {};
const prevWorkspaceClass = additionalData?.workspaceClasses?.regular;
const workspaceClasses = (additionalData?.workspaceClasses || {}) as WorkspaceClasses;
workspaceClasses.regular = value;
workspaceClasses.prebuild = value;
additionalData.workspaceClasses = workspaceClasses;
if (value !== prevWorkspaceClass) {
await getGitpodService().server.updateLoggedInUser({ additionalData });
}
return prevWorkspaceClass;
};

return (
<div>
<PageWithSettingsSubMenu title="Preferences" subtitle="Configure user preferences.">
<h3>Editor</h3>
<p className="text-base text-gray-500 dark:text-gray-400">Choose the editor for opening workspaces.</p>
<SelectIDE location="preferences" />
<SelectWorkspaceClass
workspaceClass={user?.additionalData?.workspaceClasses?.regular}
enabled={BillingMode.canSetWorkspaceClass(userBillingMode)}
setWorkspaceClass={setWorkspaceClass}
/>
<h3 className="mt-12">Theme</h3>
<p className="text-base text-gray-500 dark:text-gray-400">Early bird or night owl? Choose your side.</p>
<div className="mt-4 space-x-3 flex">
Expand Down
2 changes: 1 addition & 1 deletion components/dashboard/src/settings/selectClass.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function SelectWorkspaceClass(props: SelectWorkspaceClassProps) {
setSupportedClasses(classes);

if (!workspaceClass) {
setWorkspaceClass(classes.find((c) => c.isSelected)?.id || "");
setWorkspaceClass(classes.find((c) => c.isDefault)?.id || "");
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export interface ProjectConfig {

export interface ProjectSettings {
useIncrementalPrebuilds?: boolean;
usePersistentVolumeClaim?: boolean;
keepOutdatedPrebuildsRunning?: boolean;
// whether new workspaces can start on older prebuilds and incrementally update
allowUsingPreviousPrebuilds?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion components/gitpod-protocol/src/workspace-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export interface SupportedWorkspaceClass {
displayName: string;
description: string;
powerups: number;
isSelected: boolean;
isDefault: boolean;
}
9 changes: 7 additions & 2 deletions components/server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import * as fs from "fs";
import * as yaml from "js-yaml";
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
import { filePathTelepresenceAware } from "@gitpod/gitpod-protocol/lib/env";
import { WorkspaceClasses, WorkspaceClassesConfig } from "./workspace/workspace-classes";
import { WorkspaceClassesConfig } from "./workspace/workspace-classes";
import { PrebuildRateLimiters } from "./workspace/prebuild-rate-limiter";

export const Config = Symbol("Config");
Expand Down Expand Up @@ -307,7 +307,12 @@ export namespace ConfigFile {
}
}

WorkspaceClasses.validate(config.workspaceClasses);
if (config.workspaceClasses.filter((c) => c.isDefault).length !== 1) {
log.error(
"Exactly one default workspace class needs to be configured: " +
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Could be clarified as "Exactly one workspace class should be configured as default: "

JSON.stringify(config.workspaceClasses),
);
}

let patSigningKey = "";
if (config.patSigningKeyFile) {
Expand Down
29 changes: 9 additions & 20 deletions components/server/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ import { WorkspaceClusterImagebuilderClientProvider } from "./workspace-cluster-
import { VerificationService } from "../auth/verification-service";
import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode";
import { EntitlementService } from "../billing/entitlement-service";
import { WorkspaceClasses } from "./workspace-classes";
import { formatPhoneNumber } from "../user/phone-numbers";
import { IDEService } from "../ide-service";
import { MessageBusIntegration } from "./messagebus-integration";
Expand Down Expand Up @@ -2947,25 +2946,15 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
}

async getSupportedWorkspaceClasses(ctx: TraceContext): Promise<SupportedWorkspaceClass[]> {
let user = this.checkAndBlockUser("getSupportedWorkspaceClasses");
let selectedClass = await WorkspaceClasses.getConfiguredOrUpgradeFromLegacy(
user,
undefined,
this.config.workspaceClasses,
this.entitlementService,
);

let classes = this.config.workspaceClasses
.filter((c) => !c.deprecated)
.map((c) => ({
id: c.id,
category: c.category,
displayName: c.displayName,
description: c.description,
powerups: c.powerups,
isSelected: selectedClass === c.id,
}));

this.checkAndBlockUser("getSupportedWorkspaceClasses");
const classes = this.config.workspaceClasses.map((c) => ({
id: c.id,
category: c.category,
displayName: c.displayName,
description: c.description,
powerups: c.powerups,
isDefault: c.isDefault,
}));
return classes;
}

Expand Down
91 changes: 0 additions & 91 deletions components/server/src/workspace/workspace-classes.spec.ts

This file was deleted.

Loading