Skip to content

[server, dashboard, db] Org-wide "maintenance mode" #20813

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 12 commits into from
May 15, 2025
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
42 changes: 22 additions & 20 deletions components/dashboard/src/AppNotifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { AttributionId } from "@gitpod/gitpod-protocol/lib/attribution";
import { getGitpodService } from "./service/service";
import { useOrgBillingMode } from "./data/billing-mode/org-billing-mode-query";
import { Organization } from "@gitpod/public-api/lib/gitpod/v1/organization_pb";
import { MaintenanceModeBanner } from "./org-admin/MaintenanceModeBanner";
import { MaintenanceNotificationBanner } from "./org-admin/MaintenanceNotificationBanner";

const KEY_APP_DISMISSED_NOTIFICATIONS = "gitpod-app-notifications-dismissed";
const PRIVACY_POLICY_LAST_UPDATED = "2024-12-03";
Expand Down Expand Up @@ -208,29 +210,29 @@ export function AppNotifications() {
setTopNotification(undefined);
}, [topNotification, setTopNotification]);

if (!topNotification) {
return <></>;
}

return (
<div className="app-container pt-2">
<Alert
type={topNotification.type}
closable={topNotification.id !== "gitpod-classic-sunset"} // Only show close button if it's not the sunset notification
onClose={() => {
if (!topNotification.preventDismiss) {
dismissNotification();
} else {
if (topNotification.onClose) {
topNotification.onClose();
<MaintenanceModeBanner />
<MaintenanceNotificationBanner />
{topNotification && (
<Alert
type={topNotification.type}
closable={topNotification.id !== "gitpod-classic-sunset"} // Only show close button if it's not the sunset notification
onClose={() => {
if (!topNotification.preventDismiss) {
dismissNotification();
} else {
if (topNotification.onClose) {
topNotification.onClose();
}
}
}
}}
showIcon={true}
className="flex rounded mb-2 w-full"
>
<span>{topNotification.message}</span>
</Alert>
}}
showIcon={true}
className="flex rounded mb-2 w-full"
>
<span>{topNotification.message}</span>
</Alert>
)}
</div>
);
}
Expand Down
2 changes: 2 additions & 0 deletions components/dashboard/src/app/AppRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const ConfigurationDetailPage = React.lazy(
);

const PrebuildListPage = React.lazy(() => import(/* webpackPrefetch: true */ "../prebuilds/list/PrebuildListPage"));
const AdminPage = React.lazy(() => import(/* webpackPrefetch: true */ "../org-admin/AdminPage"));

export const AppRoutes = () => {
const hash = getURLHash();
Expand Down Expand Up @@ -205,6 +206,7 @@ export const AppRoutes = () => {
{/* TODO: migrate other org settings pages underneath /settings prefix so we can utilize nested routes */}
<Route exact path="/billing" component={TeamUsageBasedBilling} />
<Route exact path="/sso" component={SSO} />
<Route exact path="/org-admin" component={AdminPage} />

<Route exact path={`/prebuilds`} component={PrebuildListPage} />
<Route path="/prebuilds/:prebuildId" component={PrebuildDetailPage} />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright (c) 2025 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License.AGPL.txt in the project root for license information.
*/

import { useMutation, useQueryClient } from "@tanstack/react-query";
import { useCurrentOrg } from "../organizations/orgs-query";
import { organizationClient } from "../../service/public-api";
import { maintenanceModeQueryKey } from "./maintenance-mode-query";

export interface SetMaintenanceModeArgs {
enabled: boolean;
}

export const useSetMaintenanceModeMutation = () => {
const { data: org } = useCurrentOrg();
const queryClient = useQueryClient();
const organizationId = org?.id ?? "";

return useMutation<boolean, Error, SetMaintenanceModeArgs>({
mutationFn: async ({ enabled }) => {
if (!organizationId) {
throw new Error("No organization selected");
}

try {
const response = await organizationClient.setOrganizationMaintenanceMode({
organizationId,
enabled,
});
return response.enabled;
} catch (error) {
console.error("Failed to set maintenance mode", error);
throw error;
}
},
onSuccess: (result) => {
// Update the cache
queryClient.setQueryData(maintenanceModeQueryKey(organizationId), result);
},
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright (c) 2025 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License.AGPL.txt in the project root for license information.
*/

import { useQuery } from "@tanstack/react-query";
import { useCurrentOrg } from "../organizations/orgs-query";
import { organizationClient } from "../../service/public-api";

export const maintenanceModeQueryKey = (orgId: string) => ["maintenance-mode", orgId];

export const useMaintenanceMode = () => {
const { data: org } = useCurrentOrg();

const { data: isMaintenanceMode = false, isLoading } = useQuery(
maintenanceModeQueryKey(org?.id || ""),
async () => {
if (!org?.id) return false;

try {
const response = await organizationClient.getOrganizationMaintenanceMode({
organizationId: org.id,
});
return response.enabled;
} catch (error) {
console.error("Failed to fetch maintenance mode status", error);
return false;
}
},
{
enabled: !!org?.id,
staleTime: 30 * 1000, // 30 seconds
refetchInterval: 60 * 1000, // 1 minute
},
);

return {
isMaintenanceMode,
isLoading,
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright (c) 2025 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License.AGPL.txt in the project root for license information.
*/

import { useMutation, useQueryClient } from "@tanstack/react-query";
import { useCurrentOrg } from "../organizations/orgs-query";
import { organizationClient } from "../../service/public-api";
import { MaintenanceNotification } from "@gitpod/gitpod-protocol";
import { maintenanceNotificationQueryKey } from "./maintenance-notification-query";

export interface SetMaintenanceNotificationArgs {
isEnabled: boolean;
customMessage?: string;
}

export const useSetMaintenanceNotificationMutation = () => {
const { data: org } = useCurrentOrg();
const queryClient = useQueryClient();
const organizationId = org?.id ?? "";

return useMutation<MaintenanceNotification, Error, SetMaintenanceNotificationArgs>({
mutationFn: async ({ isEnabled, customMessage }) => {
if (!organizationId) {
throw new Error("No organization selected");
}

try {
const response = await organizationClient.setMaintenanceNotification({
organizationId,
isEnabled,
customMessage,
});

const result: MaintenanceNotification = {
enabled: response.isEnabled,
message: response.message,
};

return result;
} catch (error) {
console.error("Failed to set maintenance notification", error);
throw error;
}
},
onSuccess: (result) => {
// Update the cache
queryClient.setQueryData(maintenanceNotificationQueryKey(organizationId), result);
},
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copyright (c) 2025 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License.AGPL.txt in the project root for license information.
*/

import { useQuery } from "@tanstack/react-query";
import { useCurrentOrg } from "../organizations/orgs-query";
import { organizationClient } from "../../service/public-api";
import { MaintenanceNotification } from "@gitpod/gitpod-protocol";

export const maintenanceNotificationQueryKey = (orgId: string) => ["maintenance-notification", orgId];

export const useMaintenanceNotification = () => {
const { data: org } = useCurrentOrg();

const { data, isLoading } = useQuery<MaintenanceNotification>(
maintenanceNotificationQueryKey(org?.id || ""),
async () => {
if (!org?.id) return { enabled: false };

try {
const response = await organizationClient.getMaintenanceNotification({
organizationId: org.id,
});
return {
enabled: response.isEnabled,
message: response.message,
};
} catch (error) {
console.error("Failed to fetch maintenance notification settings", error);
return { enabled: false };
}
},
{
enabled: !!org?.id,
staleTime: 30 * 1000, // 30 seconds
refetchInterval: 60 * 1000, // 1 minute
},
);

return {
isNotificationEnabled: data?.enabled || false,
notificationMessage: data?.message,
isLoading,
};
};
11 changes: 11 additions & 0 deletions components/dashboard/src/menu/OrganizationSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@ export default function OrganizationSelector() {
separator: false,
link: "/settings",
});

if (isOwner && isDedicated) {
// Add Admin link for owners
linkEntries.push({
title: "Organization Administration",
customContent: <LinkEntry>Organization Administration</LinkEntry>,
active: false,
separator: false,
link: "/org-admin",
});
}
}
}

Expand Down
66 changes: 66 additions & 0 deletions components/dashboard/src/org-admin/AdminPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* Copyright (c) 2025 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License.AGPL.txt in the project root for license information.
*/

import React, { useEffect } from "react";
import { useHistory } from "react-router-dom";
import { useUserLoader } from "../hooks/use-user-loader";
import { useCurrentOrg } from "../data/organizations/orgs-query";
import { useIsOwner } from "../data/organizations/members-query";
import Header from "../components/Header";
import { SpinnerLoader } from "../components/Loader";
import { RunningWorkspacesCard } from "./RunningWorkspacesCard";
import { MaintenanceModeCard } from "./MaintenanceModeCard";
import { MaintenanceNotificationCard } from "./MaintenanceNotificationCard";
import { Heading2 } from "@podkit/typography/Headings";

const AdminPage: React.FC = () => {
const history = useHistory();
const { loading: userLoading } = useUserLoader();
const { data: currentOrg, isLoading: orgLoading } = useCurrentOrg();
const isOwner = useIsOwner();

useEffect(() => {
if (userLoading || orgLoading) {
return;
}
if (!isOwner) {
history.replace("/workspaces");
}
}, [isOwner, userLoading, orgLoading, history, currentOrg?.id]);

return (
<div className="flex flex-col w-full">
<Header title="Organization Administration" subtitle="Manage Infrastructure Rollouts" />
<div className="app-container py-6 flex flex-col gap-4">
<Heading2>Infrastructure Rollout</Heading2>

{userLoading ||
orgLoading ||
(!isOwner && (
<div className="flex items-center justify-center w-full p-8">
<SpinnerLoader />
</div>
))}

{!orgLoading && !currentOrg && (
<div className="text-red-500 p-4 bg-red-100 dark:bg-red-900 border border-red-500 rounded-md">
Could not load organization details. Please ensure you are part of an organization.
</div>
)}

{currentOrg && (
<>
<MaintenanceNotificationCard />
<MaintenanceModeCard />
<RunningWorkspacesCard />
</>
)}
</div>
</div>
);
};

export default AdminPage;
26 changes: 26 additions & 0 deletions components/dashboard/src/org-admin/MaintenanceModeBanner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright (c) 2025 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License.AGPL.txt in the project root for license information.
*/

import { FC } from "react";
import Alert from "../components/Alert";
import { useMaintenanceMode } from "../data/maintenance-mode/maintenance-mode-query";

export const MaintenanceModeBanner: FC = () => {
const { isMaintenanceMode } = useMaintenanceMode();

if (!isMaintenanceMode) {
return null;
}

return (
<Alert type="warning" className="mb-2">
<div className="flex items-center flex-wrap gap-2">
<span className="font-semibold">System is in maintenance mode.</span>
<span>Starting new workspaces is currently disabled by your organization owner.</span>
</div>
</Alert>
);
};
Loading
Loading