-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[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
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8ba9feb
[dashboard] Initial infra rollout page, incl. list running workspaces
geropl ccdca90
[server, db, dashboard] Allow org-owner to stop workspace on all work…
geropl d73be97
[public-api, db, server, dashboard] Introduce MaintenanceNofitication…
geropl f2c77b6
review comments: use mutation instead of callback for state mutation
geropl 4eaaa9d
Fix workspace start prevention
geropl 51fb829
Review comments around banners and rendering
geropl 36a7cc1
[dashboard] Only show Admin entry for dedicated
geropl 81b081d
[server] Fix permissions for setMaintenanceMode to "maintenance"
geropl d7770f6
[dashboard] Adjusted copy incl. default notification message
geropl d156926
Review coments: re-use and fix styles, and naming
geropl 93d01d1
Minor copy improvements
geropl 2192fa6
[server] Fix bogus permission check in stopWorkspace
geropl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
components/dashboard/src/data/maintenande-mode/maintenance-mode-mutation.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}, | ||
}); | ||
}; |
42 changes: 42 additions & 0 deletions
42
components/dashboard/src/data/maintenande-mode/maintenance-mode-query.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
52 changes: 52 additions & 0 deletions
52
components/dashboard/src/data/maintenande-mode/maintenance-notification-mutation.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}, | ||
}); | ||
}; |
47 changes: 47 additions & 0 deletions
47
components/dashboard/src/data/maintenande-mode/maintenance-notification-query.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* 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"; | ||
|
||
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"> | ||
<h2 className="text-2xl font-semibold text-pk-content-primary mb-4">Infrastructure Rollout</h2> | ||
geropl marked this conversation as resolved.
Show resolved
Hide resolved
geropl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
{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
26
components/dashboard/src/org-admin/MaintenanceModeBanner.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/maintenande-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.</span> | ||
</div> | ||
</Alert> | ||
); | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.