@skyhook-io/radar-app 1.20.1 → 1.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/package.json +10 -9
  2. package/src/App.tsx +65 -16
  3. package/src/api/client.audit-gating.test.tsx +105 -5
  4. package/src/api/client.auditBadgesSync.test.tsx +118 -0
  5. package/src/api/client.capabilitiesPoll.test.ts +61 -0
  6. package/src/api/client.namespaceSwitch.hook.test.tsx +170 -1
  7. package/src/api/client.pauseDeployment.test.tsx +77 -0
  8. package/src/api/client.restartError.test.ts +14 -0
  9. package/src/api/client.revisionRefresh.test.tsx +44 -0
  10. package/src/api/client.rollbackError.test.ts +14 -0
  11. package/src/api/client.ts +347 -16
  12. package/src/api/namespaceScopeRetry.test.ts +14 -0
  13. package/src/api/networkAttachments.test.tsx +120 -0
  14. package/src/api/networkAttachments.ts +30 -0
  15. package/src/api/radarFeatures.test.ts +5 -0
  16. package/src/api/radarFeatures.ts +10 -0
  17. package/src/api/secretsStore.test.ts +33 -0
  18. package/src/api/secretsStore.ts +37 -0
  19. package/src/api/substrateHealth.ts +134 -0
  20. package/src/api/velero.test.ts +60 -0
  21. package/src/api/velero.ts +201 -0
  22. package/src/api/vulnerabilities.ts +255 -0
  23. package/src/components/ConnectionErrorView.test.tsx +11 -0
  24. package/src/components/ConnectionErrorView.tsx +19 -0
  25. package/src/components/ContextSwitcher.tsx +9 -2
  26. package/src/components/NamespaceSwitcher.tsx +3 -1
  27. package/src/components/applications/ApplicationsView.openResource.test.tsx +118 -0
  28. package/src/components/applications/ApplicationsView.tsx +8 -11
  29. package/src/components/audit/AuditView.tsx +4 -0
  30. package/src/components/audit/ChecksViewTabs.test.tsx +33 -5
  31. package/src/components/audit/ChecksViewTabs.tsx +11 -1
  32. package/src/components/audit/UpgradeReadinessView.test.ts +35 -1
  33. package/src/components/audit/UpgradeReadinessView.tsx +60 -2
  34. package/src/components/audit/VulnerabilitiesView.tsx +907 -0
  35. package/src/components/cnpg/CNPGClusterTabs.tsx +3 -1
  36. package/src/components/cnpg/CNPGDrawerTrail.tsx +5 -26
  37. package/src/components/cnpg/CNPGInvestigationAction.test.tsx +27 -6
  38. package/src/components/cnpg/CNPGView.tsx +43 -117
  39. package/src/components/cnpg/CNPGWorkspace.compatibility.test.tsx +30 -0
  40. package/src/components/cnpg/host.tsx +2 -2
  41. package/src/components/cnpg/routes.ts +3 -1
  42. package/src/components/cnpg/shared.tsx +5 -53
  43. package/src/components/cnpg/useCNPGNavigate.ts +1 -21
  44. package/src/components/cnpg/useCNPGSidebarWorkspace.ts +16 -13
  45. package/src/components/community.tsx +42 -0
  46. package/src/components/cost/CostView.tsx +27 -9
  47. package/src/components/diagnose/InvestigationView.tsx +12 -3
  48. package/src/components/diagnose/diagnoseEvidenceTypes.ts +2 -0
  49. package/src/components/diagnose/investigationEvidence/adapters/helm.test.tsx +52 -0
  50. package/src/components/diagnose/investigationEvidence/adapters/helm.ts +10 -0
  51. package/src/components/diagnose/investigationEvidence/bodies/platform.tsx +82 -51
  52. package/src/components/diagnose/investigationEvidence/types.ts +5 -0
  53. package/src/components/diagnose/investigationMetrics.test.ts +20 -0
  54. package/src/components/diagnose/investigationMetrics.ts +2 -1
  55. package/src/components/dock/BottomDock.tsx +1 -0
  56. package/src/components/dock/LogsTab.tsx +3 -0
  57. package/src/components/dock/TerminalPreferences.query.test.tsx +57 -0
  58. package/src/components/dock/TerminalPreferences.test.tsx +68 -0
  59. package/src/components/dock/TerminalPreferences.tsx +73 -0
  60. package/src/components/gitops/GitOpsView.tsx +2 -10
  61. package/src/components/helm/HelmDrawerFrame.tsx +1 -1
  62. package/src/components/helm/HelmReleaseDrawer.tsx +24 -12
  63. package/src/components/helm/HelmView.tsx +25 -19
  64. package/src/components/helm/NotCheckedBadge.test.tsx +62 -0
  65. package/src/components/helm/NotCheckedBadge.tsx +39 -0
  66. package/src/components/helm/OwnedResources.test.tsx +86 -0
  67. package/src/components/helm/OwnedResources.tsx +69 -11
  68. package/src/components/home/ClusterHealthCard.heading.test.tsx +72 -0
  69. package/src/components/home/ClusterHealthCard.test.ts +44 -1
  70. package/src/components/home/ClusterHealthCard.tsx +25 -11
  71. package/src/components/home/HelmSummary.tsx +15 -15
  72. package/src/components/home/HomeAgentBlock.tsx +3 -0
  73. package/src/components/home/HomeView.tsx +7 -0
  74. package/src/components/home/MCPSetupDialog.test.tsx +19 -12
  75. package/src/components/home/MCPSetupDialog.tsx +4 -2
  76. package/src/components/home/mcpToolCatalog.ts +17 -4
  77. package/src/components/home/useVulnerabilitiesRow.test.ts +26 -0
  78. package/src/components/home/useVulnerabilitiesRow.ts +50 -0
  79. package/src/components/logs/LogsViewer.tsx +3 -1
  80. package/src/components/logs/MultiPodLogsTab.test.tsx +24 -4
  81. package/src/components/logs/MultiPodLogsTab.tsx +9 -5
  82. package/src/components/nav/PrimaryNavRail.test.tsx +17 -0
  83. package/src/components/nav/PrimaryNavRail.tsx +174 -29
  84. package/src/components/resource/PrometheusChartsGrid.tsx +5 -1
  85. package/src/components/resource/RightsizingStrip.test.ts +57 -0
  86. package/src/components/resource/RightsizingStrip.tsx +53 -4
  87. package/src/components/resource/SubstrateHealthCharts.test.tsx +143 -0
  88. package/src/components/resource/SubstrateHealthCharts.tsx +254 -0
  89. package/src/components/resource/SubstrateVerdictLine.test.tsx +131 -0
  90. package/src/components/resource/SubstrateVerdictLine.tsx +180 -0
  91. package/src/components/resources/ImageFilesystemModal.test.tsx +74 -6
  92. package/src/components/resources/ImageFilesystemModal.tsx +98 -6
  93. package/src/components/resources/PodFileUploadPanel.tsx +150 -0
  94. package/src/components/resources/PodFilesystemModal.tsx +246 -3
  95. package/src/components/resources/ResourcesView.tsx +12 -6
  96. package/src/components/resources/pod-file-upload.test.tsx +223 -0
  97. package/src/components/resources/pod-file-upload.ts +266 -0
  98. package/src/components/resources/renderers/HTTPRouteRenderer.test.tsx +50 -0
  99. package/src/components/resources/renderers/HTTPRouteRenderer.tsx +27 -0
  100. package/src/components/resources/renderers/PodRenderer.tsx +26 -1
  101. package/src/components/resources/renderers/SecretProviderClassRenderer.tsx +25 -0
  102. package/src/components/resources/renderers/UpgradePlanRenderer.test.tsx +20 -0
  103. package/src/components/resources/renderers/UpgradePlanRenderer.tsx +22 -0
  104. package/src/components/resources/renderers/VeleroBackupRenderer.tsx +16 -36
  105. package/src/components/resources/renderers/VeleroRestoreRenderer.tsx +6 -19
  106. package/src/components/resources/renderers/WorkloadRenderer.tsx +8 -0
  107. package/src/components/rightsizing/RightsizingScanView.tsx +19 -3
  108. package/src/components/rightsizing/model.test.ts +11 -0
  109. package/src/components/rightsizing/model.ts +3 -1
  110. package/src/components/rightsizing/presentation.test.ts +46 -0
  111. package/src/components/rightsizing/presentation.ts +17 -2
  112. package/src/components/shared/LargeClusterNamespacePicker.test.tsx +27 -0
  113. package/src/components/shared/LargeClusterNamespacePicker.tsx +8 -2
  114. package/src/components/timeline/TimelineView.tsx +3 -1
  115. package/src/components/traffic/TrafficConnectionsTable.test.tsx +94 -0
  116. package/src/components/traffic/TrafficConnectionsTable.tsx +21 -5
  117. package/src/components/traffic/TrafficData.test.tsx +37 -0
  118. package/src/components/traffic/TrafficData.tsx +27 -0
  119. package/src/components/traffic/TrafficFlowList.tsx +9 -7
  120. package/src/components/traffic/TrafficGraph.layoutEngine.test.tsx +193 -0
  121. package/src/components/traffic/TrafficGraph.test.tsx +269 -0
  122. package/src/components/traffic/TrafficGraph.tsx +135 -64
  123. package/src/components/traffic/TrafficGraphUnavailable.tsx +57 -0
  124. package/src/components/traffic/TrafficView.layoutUnavailable.test.tsx +211 -0
  125. package/src/components/traffic/TrafficView.tsx +72 -155
  126. package/src/components/traffic/trafficFilters.test.ts +189 -1
  127. package/src/components/traffic/trafficFilters.ts +169 -1
  128. package/src/components/ui/DiagnosticsOverlay.tsx +14 -1
  129. package/src/components/ui/Omnibar.tsx +4 -1
  130. package/src/components/ui/RadarOmnibar.test.tsx +55 -2
  131. package/src/components/ui/RadarOmnibar.tsx +7 -1
  132. package/src/components/ui/SearchSyntaxHelp.test.tsx +9 -2
  133. package/src/components/ui/SearchSyntaxHelp.tsx +3 -2
  134. package/src/components/ui/UpdateNotification.manual.test.tsx +5 -2
  135. package/src/components/ui/UpdateNotification.test.tsx +54 -3
  136. package/src/components/ui/UpdateNotification.tsx +60 -19
  137. package/src/components/ui/command-items.ts +24 -1
  138. package/src/components/ui/omnibar-match.test.ts +7 -0
  139. package/src/components/ui/omnibar-match.ts +1 -0
  140. package/src/components/ui/searchCoverageNote.test.ts +17 -0
  141. package/src/components/ui/searchCoverageNote.ts +31 -7
  142. package/src/components/useContextSwitchFlow.tsx +9 -1
  143. package/src/components/velero/VeleroBackupNow.test.tsx +165 -0
  144. package/src/components/velero/VeleroBackupNow.tsx +143 -0
  145. package/src/components/velero/VeleroDeleteBackup.test.tsx +364 -0
  146. package/src/components/velero/VeleroDeleteBackup.tsx +306 -0
  147. package/src/components/velero/VeleroDetailPage.tsx +148 -0
  148. package/src/components/velero/VeleroKindLists.test.tsx +48 -0
  149. package/src/components/velero/VeleroKindLists.tsx +43 -0
  150. package/src/components/velero/VeleroLocations.expand.test.tsx +27 -0
  151. package/src/components/velero/VeleroLocations.test.tsx +86 -0
  152. package/src/components/velero/VeleroLocations.tsx +240 -0
  153. package/src/components/velero/VeleroOverview.test.tsx +311 -0
  154. package/src/components/velero/VeleroOverview.tsx +485 -0
  155. package/src/components/velero/VeleroPages.test.tsx +516 -0
  156. package/src/components/velero/VeleroPages.tsx +1056 -0
  157. package/src/components/velero/VeleroRunLists.tsx +309 -0
  158. package/src/components/velero/VeleroRunMessagesHost.test.tsx +25 -0
  159. package/src/components/velero/VeleroRunMessagesHost.tsx +54 -0
  160. package/src/components/velero/VeleroScheduleStatusBadge.test.tsx +28 -0
  161. package/src/components/velero/VeleroScheduleStatusBadge.tsx +21 -0
  162. package/src/components/velero/VeleroSchedules.tsx +255 -0
  163. package/src/components/velero/VeleroView.tsx +59 -0
  164. package/src/components/velero/VeleroWorkspace.gate.test.tsx +97 -0
  165. package/src/components/velero/attention.test.ts +178 -0
  166. package/src/components/velero/attention.ts +281 -0
  167. package/src/components/velero/backupDelete.test.tsx +91 -0
  168. package/src/components/velero/backupDelete.tsx +182 -0
  169. package/src/components/velero/coverage.test.ts +87 -0
  170. package/src/components/velero/coverage.ts +150 -0
  171. package/src/components/velero/host.tsx +86 -0
  172. package/src/components/velero/routes.ts +78 -0
  173. package/src/components/velero/runs.tsx +121 -0
  174. package/src/components/velero/shared.test.ts +84 -0
  175. package/src/components/velero/shared.tsx +423 -0
  176. package/src/components/velero/useVeleroSidebarWorkspace.test.tsx +28 -0
  177. package/src/components/velero/useVeleroSidebarWorkspace.ts +71 -0
  178. package/src/components/velero/velero.fixtures.ts +61 -0
  179. package/src/components/velero/workspaceRoute.ts +21 -0
  180. package/src/components/vulnerabilities/WorkloadVulnerabilitiesSection.tsx +167 -0
  181. package/src/components/vulnerabilities/parts.test.ts +72 -0
  182. package/src/components/vulnerabilities/parts.tsx +291 -0
  183. package/src/components/workload/NodeCertificateEvidence.test.tsx +51 -0
  184. package/src/components/workload/NodeCertificateEvidence.tsx +44 -0
  185. package/src/components/workload/WorkloadView.tsx +114 -37
  186. package/src/components/workspace/DrawerTrailBack.tsx +32 -0
  187. package/src/components/workspace/WorkspaceFrame.tsx +71 -0
  188. package/src/components/workspace/coverage.ts +61 -0
  189. package/src/components/workspace/layout.test.tsx +29 -1
  190. package/src/components/workspace/layout.tsx +15 -5
  191. package/src/components/workspace/sidebar.ts +9 -0
  192. package/src/components/workspace/useWorkspaceDrawer.ts +63 -0
  193. package/src/components/workspace/useWorkspaceNavigate.ts +21 -0
  194. package/src/context/ConnectionContext.test.ts +1 -0
  195. package/src/context/ConnectionContext.tsx +2 -2
  196. package/src/desktop/AboutDialog.test.ts +12 -0
  197. package/src/desktop/AboutDialog.tsx +151 -0
  198. package/src/desktop/WindowsTitleBar.tsx +359 -0
  199. package/src/desktop/titleBar.test.ts +61 -0
  200. package/src/desktop/titleBar.ts +45 -0
  201. package/src/index.css +19 -0
  202. package/src/integrations/resourceHost.ts +5 -1
  203. package/src/integrations/resourceHosts.test.tsx +15 -3
  204. package/src/integrations/resourceHosts.tsx +26 -6
  205. package/src/integrations/workspaceRoute.ts +1 -1
  206. package/src/integrations/workspaceRoutes.test.ts +11 -0
  207. package/src/integrations/workspaceRoutes.ts +3 -1
  208. package/src/integrations/workspaceScreens.tsx +2 -0
  209. package/src/main.tsx +8 -0
  210. package/src/utils/desktop-zoom.test.ts +53 -0
  211. package/src/utils/desktop-zoom.ts +30 -0
  212. package/src/utils/namespacePick.test.ts +87 -0
  213. package/src/utils/namespacePick.ts +88 -0
  214. package/src/utils/staleAssetPrompt.test.tsx +76 -0
  215. package/src/utils/staleAssetPrompt.tsx +32 -0
package/src/api/client.ts CHANGED
@@ -35,6 +35,7 @@ import type {
35
35
  import { focusManager, useInfiniteQuery, useQuery, useMutation, useQueryClient, skipToken, type QueryClient } from '@tanstack/react-query'
36
36
  import { showApiError, showApiSuccess, showApiNotice } from '../components/ui/Toast'
37
37
  import { useIsAuthEnabled, useNamespacedCapabilities } from '../contexts/CapabilitiesContext'
38
+ import { applyTabPick, cleanPick, ownsTabPick, pruneTabPick, withActives, writeTabPick } from '../utils/namespacePick'
38
39
  import type {
39
40
  Topology,
40
41
  ClusterInfo,
@@ -89,6 +90,7 @@ import {
89
90
  } from './radarFeatures'
90
91
  import { useRadarUpgradeHost } from '../context/RadarUpgradeHost'
91
92
  import { apiVersionToGroup } from '../utils/navigation'
93
+ import { isBadgeWorthy } from '../utils/auditBadges'
92
94
  import type { DeploymentMode } from '../types'
93
95
 
94
96
  // Auto-refresh cadences (ms) — named constants for each polled hook's
@@ -427,7 +429,12 @@ export async function fetchJSON<T>(
427
429
  // ============================================================================
428
430
 
429
431
  export interface DashboardCluster {
432
+ // Kubeconfig context, or "in-cluster". The kubeconfig cluster entry is in
433
+ // kubeconfigCluster.
430
434
  name: string;
435
+ // Kubeconfig cluster entry the context points at; several contexts can
436
+ // share one. Absent in in-cluster mode and from older Radar.
437
+ kubeconfigCluster?: string;
431
438
  platform: string;
432
439
  version: string;
433
440
  connected: boolean;
@@ -526,6 +533,8 @@ export interface DashboardHelmRelease {
526
533
  chartVersion: string;
527
534
  status: string;
528
535
  resourceHealth?: string;
536
+ // Workloads and Pods whose live status wasn't read.
537
+ statusUnreadCount?: number;
529
538
  }
530
539
 
531
540
  export interface DashboardHelmSummary {
@@ -731,11 +740,26 @@ export function useDashboard(
731
740
  export function useAudit(namespaces: string[] = []) {
732
741
  const params =
733
742
  namespaces.length > 0 ? `?namespaces=${namespaces.join(",")}` : "";
734
- // Mounted app-wide, so without this it keeps polling a cluster that is down.
743
+ // Without the connection check a mounted view keeps polling a cluster that
744
+ // is down.
735
745
  const connected = useClusterConnected();
746
+ const queryClient = useQueryClient();
736
747
  return useQuery<AuditResponse>({
737
748
  queryKey: ["audit", namespaces],
738
- queryFn: () => fetchJSON(`/audit${params}`),
749
+ queryFn: async () => {
750
+ const audit = await fetchJSON<AuditResponse>(`/audit${params}`);
751
+ // Resource badges read the same scan through their own smaller query.
752
+ // A fresher full scan has them refetch rather than show a different
753
+ // answer: invalidating, unlike writing the projection, can't install an
754
+ // older scan or one from before a context switch. An in-flight badges
755
+ // request may predate this scan, and a first request isn't restarted by
756
+ // invalidation, so it is cancelled first. This runs with the fetch, not
757
+ // the view, so leaving the page mid-fetch doesn't skip it.
758
+ const badges = ["audit", namespaces, "badges"];
759
+ await queryClient.cancelQueries({ queryKey: badges, exact: true });
760
+ void queryClient.invalidateQueries({ queryKey: badges, exact: true });
761
+ return audit;
762
+ },
739
763
  enabled: connected,
740
764
  staleTime: 30000,
741
765
  refetchInterval: AUDIT_REFRESH_INTERVAL_MS,
@@ -743,6 +767,39 @@ export function useAudit(namespaces: string[] = []) {
743
767
  });
744
768
  }
745
769
 
770
+ export type AuditBadges = Pick<AuditResponse, "findings" | "checks">;
771
+
772
+ // Keeps only what a badge view shows: findings of badge-worthy checks and
773
+ // those checks' catalog entries. A Radar that predates include=badges answers
774
+ // with the full response, which this cuts down rather than retaining.
775
+ export function projectAuditBadges(response: AuditBadges): AuditBadges {
776
+ const findings = (response.findings ?? []).filter((f) => isBadgeWorthy(f, response.checks));
777
+ const checks: AuditBadges["checks"] = {};
778
+ for (const f of findings) checks[f.checkID] = response.checks[f.checkID];
779
+ return { findings, checks };
780
+ }
781
+
782
+ // The audit as resource badges need it (topology, resource lists): the
783
+ // badge-worthy findings only, a small fraction of the full scan, which repeats
784
+ // every finding per resource and per check for the Checks page.
785
+ export function useAuditBadges(
786
+ namespaces: string[] = [],
787
+ options: { enabled?: boolean } = {},
788
+ ) {
789
+ const params = new URLSearchParams({ include: "badges" });
790
+ if (namespaces.length > 0) params.set("namespaces", namespaces.join(","));
791
+ const connected = useClusterConnected();
792
+ return useQuery<AuditBadges>({
793
+ queryKey: ["audit", namespaces, "badges"],
794
+ // The signal lets a superseded request stop downloading, not just lose.
795
+ queryFn: async ({ signal }) => projectAuditBadges(await fetchJSON<AuditBadges>(`/audit?${params}`, signal)),
796
+ enabled: connected && (options.enabled ?? true),
797
+ staleTime: 30000,
798
+ refetchInterval: AUDIT_REFRESH_INTERVAL_MS,
799
+ placeholderData: (prev) => prev,
800
+ });
801
+ }
802
+
746
803
  export function useUpgradeReadiness(target?: string) {
747
804
  // The server memoizes scans per caller (~60s). Ordinary and background
748
805
  // refetches read that memo; only the explicit manual refresh passes
@@ -937,6 +994,7 @@ export interface CronJobSchedulingEvidence {
937
994
  }
938
995
 
939
996
  export interface SubjectIssuesResponse {
997
+ node_certificate_report?: NodeCertificateReport;
940
998
  scheduling_report?: CronJobSchedulingEvidence;
941
999
  issues: Issue[];
942
1000
  coverage: "ok" | "syncing" | "notWatched" | "unknownKind";
@@ -946,6 +1004,19 @@ export interface SubjectIssuesResponse {
946
1004
  unchecked_sources?: UncheckedSource[];
947
1005
  }
948
1006
 
1007
+ export interface NodeCertificateReport {
1008
+ uid: string;
1009
+ event_id?: string;
1010
+ state: 'reported' | 'unverified' | 'ok';
1011
+ reason: string;
1012
+ message: string;
1013
+ last_reported_at: string;
1014
+ expires_at?: string;
1015
+ not_before?: string;
1016
+ history_incomplete?: boolean;
1017
+ validity_unknown?: boolean;
1018
+ }
1019
+
949
1020
  export function useSubjectIssues(
950
1021
  subject: { kind: string; group: string; namespace: string; name: string; uid?: string } | null,
951
1022
  enabled: boolean,
@@ -1140,7 +1211,8 @@ export interface OpenCostNamespaceCost {
1140
1211
  hourlyCost: number;
1141
1212
  cpuCost: number;
1142
1213
  memoryCost: number;
1143
- storageCost?: number;
1214
+ // null: the namespace has volumes whose cost could not be calculated.
1215
+ storageCost?: number | null;
1144
1216
  cpuUsageCost?: number;
1145
1217
  memoryUsageCost?: number;
1146
1218
  efficiency?: number;
@@ -1175,7 +1247,8 @@ export interface OpenCostSummary {
1175
1247
  currency?: string;
1176
1248
  window?: string;
1177
1249
  totalHourlyCost?: number;
1178
- totalStorageCost?: number;
1250
+ // null: at least one namespace's storage cost is unknown.
1251
+ totalStorageCost?: number | null;
1179
1252
  totalIdleCost?: number;
1180
1253
  clusterEfficiency?: number;
1181
1254
  namespaceScope?: string[];
@@ -1872,6 +1945,12 @@ export interface VersionInfo {
1872
1945
  releaseNotes?: string;
1873
1946
  installMethod: InstallMethod;
1874
1947
  updateCommand?: string;
1948
+ /**
1949
+ * Desktop install that cannot update itself, and how the user updates instead:
1950
+ * a new AppImage, a new .deb/.rpm through the package manager, or a download
1951
+ * because Radar can't write to its folder. Absent: Update Now works.
1952
+ */
1953
+ manualUpdate?: 'appimage' | 'package' | 'download';
1875
1954
  error?: string;
1876
1955
  productHuntLaunch?: { enabled: boolean; url: string; start: string; end: string };
1877
1956
  }
@@ -2044,9 +2123,10 @@ export function useApplyDesktopUpdate() {
2044
2123
  }
2045
2124
  return response.json();
2046
2125
  },
2126
+ // No success toast: the update card shows the restart, in the corner a
2127
+ // toast would cover.
2047
2128
  meta: {
2048
2129
  errorMessage: "Failed to apply update",
2049
- successMessage: "Update applied — restarting...",
2050
2130
  },
2051
2131
  });
2052
2132
  }
@@ -2172,10 +2252,33 @@ export function useCapabilities() {
2172
2252
  staleTime: 60000, // 1 minute - cached on backend too
2173
2253
  // Re-check periodically so transient failures self-correct, but not while
2174
2254
  // the cluster is down: reconnecting refreshes every query anyway.
2175
- refetchInterval: connected ? 60000 : false,
2255
+ refetchInterval: (query) => connected ? capabilitiesRefetchInterval(query, 60000) : false,
2176
2256
  });
2177
2257
  }
2178
2258
 
2259
+ // A result built on a failed access check is kept by the server for only 5s;
2260
+ // ask again soon, backing off while the checks keep failing.
2261
+ export function capabilitiesRefetchInterval(
2262
+ query: { state: { dataUpdatedAt: number; data?: Pick<Capabilities, "checksIncomplete"> } },
2263
+ settled: number | false,
2264
+ ): number | false {
2265
+ return backoffRefetchInterval(query, query.state.dataUpdatedAt, !!query.state.data?.checksIncomplete, settled);
2266
+ }
2267
+
2268
+ const failedAnswerStreaks = new WeakMap<object, { answeredAt: number; count: number }>();
2269
+
2270
+ // backoffRefetchInterval polls 5s, 10s, 20s… up to 60s after consecutive
2271
+ // failed answers, so a struggling apiserver isn't asked more often the longer
2272
+ // it struggles; answeredAt identifies an answer, since React Query asks for
2273
+ // the interval more than once per fetch.
2274
+ export function backoffRefetchInterval(query: object, answeredAt: number, failing: boolean, settled: number | false): number | false {
2275
+ const previous = failedAnswerStreaks.get(query) ?? { answeredAt: 0, count: 0 };
2276
+ const streak = answeredAt === previous.answeredAt ? previous : { answeredAt, count: failing ? previous.count + 1 : 0 };
2277
+ failedAnswerStreaks.set(query, streak);
2278
+ if (!failing || streak.count === 0) return settled;
2279
+ return Math.min(5000 * 2 ** (streak.count - 1), 60_000);
2280
+ }
2281
+
2179
2282
  // ============================================================================
2180
2283
  // In-product Cloud Connect (driver lane)
2181
2284
  // ============================================================================
@@ -2454,12 +2557,14 @@ export function useNamespaceCapabilities(
2454
2557
  globalCaps: Capabilities | undefined,
2455
2558
  ) {
2456
2559
  const needsCheck = namespace && globalCaps;
2560
+ const connected = useClusterConnected();
2457
2561
  return useQuery<Capabilities>({
2458
2562
  queryKey: ["capabilities", namespace],
2459
2563
  queryFn: () =>
2460
2564
  fetchJSON(`/capabilities?namespace=${encodeURIComponent(namespace!)}`),
2461
2565
  enabled: !!needsCheck,
2462
2566
  staleTime: 60000,
2567
+ refetchInterval: (query) => connected ? capabilitiesRefetchInterval(query, false) : false,
2463
2568
  });
2464
2569
  }
2465
2570
 
@@ -2580,13 +2685,26 @@ export function useCanHelmAct(namespace?: string): { allowed: boolean; reason?:
2580
2685
 
2581
2686
  // Namespaces
2582
2687
  export function useNamespaces() {
2688
+ const connected = useClusterConnected();
2583
2689
  return useQuery<Namespace[]>({
2584
2690
  queryKey: ["namespaces"],
2585
2691
  queryFn: () => fetchJSON("/namespaces"),
2586
2692
  staleTime: 30000, // 30 seconds
2693
+ refetchInterval: (query) => namespacesRefetchInterval(query, connected),
2587
2694
  });
2588
2695
  }
2589
2696
 
2697
+ // A 5xx is a list Radar couldn't read (a timed-out LIST or access check), not
2698
+ // an empty one; ask again (backing off) until it answers. A denial won't
2699
+ // change by polling, and while the cluster is disconnected reconnecting
2700
+ // refreshes every query anyway.
2701
+ export function namespacesRefetchInterval(query: { state: { status: string; error: unknown; dataUpdatedAt: number; errorUpdatedAt: number } }, connected = true): number | false {
2702
+ if (!connected) return false;
2703
+ const { status, error, dataUpdatedAt, errorUpdatedAt } = query.state;
2704
+ const failing = status === "error" && error instanceof ApiError && error.status >= 500;
2705
+ return backoffRefetchInterval(query, Math.max(dataUpdatedAt, errorUpdatedAt), failing, false);
2706
+ }
2707
+
2590
2708
  // Topology (for manual refresh)
2591
2709
  export function useTopology(
2592
2710
  namespaces: string[],
@@ -3911,7 +4029,8 @@ export type RightsizingFit =
3911
4029
  | "oversized"
3912
4030
  | "under_requested"
3913
4031
  | "missing_request"
3914
- | "insufficient_history";
4032
+ | "insufficient_history"
4033
+ | "pod_level_request";
3915
4034
  export type RightsizingConfidence = "low" | "medium" | "high";
3916
4035
  export type RightsizingOwnerCoverage = "ksm_history" | "current_pods";
3917
4036
 
@@ -3924,6 +4043,9 @@ export interface RightsizingRow {
3924
4043
  currentRequestValue?: number;
3925
4044
  currentLimit?: string;
3926
4045
  currentLimitValue?: number;
4046
+ /** The pod's fixed pod-level request (spec.resources), set when fit is pod_level_request. */
4047
+ podLevelRequest?: string;
4048
+ podLevelRequestValue?: number;
3927
4049
  observed?: {
3928
4050
  name: "P95" | "P99" | "Max";
3929
4051
  value: number;
@@ -4709,7 +4831,10 @@ function deleteResourceNotification(result: DeleteResourceResult): { message: st
4709
4831
  return { message: "Resource deleted", type: "success" };
4710
4832
  }
4711
4833
 
4712
- export function useDeleteResource() {
4834
+ export function useDeleteResource(options?: {
4835
+ /** Runs after any outcome, even when the caller unmounted meanwhile. */
4836
+ onSettled?: () => void;
4837
+ }) {
4713
4838
  const queryClient = useQueryClient();
4714
4839
 
4715
4840
  return useMutation({
@@ -4719,12 +4844,17 @@ export function useDeleteResource() {
4719
4844
  namespace,
4720
4845
  name,
4721
4846
  force,
4847
+ uid,
4848
+ resourceVersion,
4722
4849
  }: {
4723
4850
  kind: string;
4724
4851
  group?: string;
4725
4852
  namespace: string;
4726
4853
  name: string;
4727
4854
  force?: boolean;
4855
+ /** Delete only the object reviewed: a Radar with resourceDeletePreconditions answers 409 when it changed. */
4856
+ uid?: string;
4857
+ resourceVersion?: string;
4728
4858
  }) => {
4729
4859
  const url = new URL(
4730
4860
  apiUrl(`/resources/${resourcePathSegments(kind, namespace, name)}`),
@@ -4736,6 +4866,8 @@ export function useDeleteResource() {
4736
4866
  if (force) {
4737
4867
  url.searchParams.set("force", "true");
4738
4868
  }
4869
+ if (uid) url.searchParams.set("uid", uid);
4870
+ if (resourceVersion) url.searchParams.set("resourceVersion", resourceVersion);
4739
4871
  return readDeleteResult(apiFetch(url.toString(), { method: "DELETE" }));
4740
4872
  },
4741
4873
  meta: {
@@ -4753,6 +4885,7 @@ export function useDeleteResource() {
4753
4885
  });
4754
4886
  queryClient.invalidateQueries({ queryKey: ["topology"] });
4755
4887
  },
4888
+ onSettled: () => options?.onSettled?.(),
4756
4889
  });
4757
4890
  }
4758
4891
 
@@ -5373,8 +5506,7 @@ export function useRestartWorkload() {
5373
5506
  },
5374
5507
  );
5375
5508
  if (!response.ok) {
5376
- const error = await readErrorBody(response);
5377
- throw new Error(error.error || `HTTP ${response.status}`);
5509
+ throw new Error(restartErrorMessage(await readErrorBody(response), response.status));
5378
5510
  }
5379
5511
  return response.json();
5380
5512
  },
@@ -5391,6 +5523,63 @@ export function useRestartWorkload() {
5391
5523
  });
5392
5524
  }
5393
5525
 
5526
+ function useSetDeploymentPaused(
5527
+ action: "pause" | "resume",
5528
+ meta: { errorMessage: string; successMessage: string },
5529
+ ) {
5530
+ const queryClient = useQueryClient();
5531
+ const { guard } = useRadarFeature("deploymentPause");
5532
+
5533
+ return useMutation({
5534
+ mutationFn: ({
5535
+ kind,
5536
+ namespace,
5537
+ name,
5538
+ }: {
5539
+ kind: string;
5540
+ namespace: string;
5541
+ name: string;
5542
+ }) =>
5543
+ guard(async () => {
5544
+ const response = await apiFetch(
5545
+ `${getApiBase()}/workloads/${kind}/${namespace}/${name}/${action}`,
5546
+ {
5547
+ method: "POST",
5548
+ },
5549
+ );
5550
+ if (!response.ok) {
5551
+ const error = await readErrorBody(response);
5552
+ throw new Error(error.error || `HTTP ${response.status}`);
5553
+ }
5554
+ return response.json();
5555
+ }),
5556
+ meta,
5557
+ onSuccess: (_, variables) => {
5558
+ queryClient.invalidateQueries({
5559
+ queryKey: ["resources", variables.kind],
5560
+ });
5561
+ queryClient.invalidateQueries({
5562
+ queryKey: ["resource", variables.kind, variables.namespace, variables.name],
5563
+ });
5564
+ queryClient.invalidateQueries({ queryKey: ["topology"] });
5565
+ },
5566
+ });
5567
+ }
5568
+
5569
+ export function usePauseDeployment() {
5570
+ return useSetDeploymentPaused("pause", {
5571
+ errorMessage: "Failed to pause rollout",
5572
+ successMessage: "Rollout paused",
5573
+ });
5574
+ }
5575
+
5576
+ export function useResumeDeployment() {
5577
+ return useSetDeploymentPaused("resume", {
5578
+ errorMessage: "Failed to resume rollout",
5579
+ successMessage: "Rollout resumed",
5580
+ });
5581
+ }
5582
+
5394
5583
  export function fetchWorkloadImages(
5395
5584
  kind: string,
5396
5585
  namespace: string,
@@ -5558,6 +5747,46 @@ export function useWorkloadRevisions(
5558
5747
  });
5559
5748
  }
5560
5749
 
5750
+ // A rollout can start long after its request returned, as when a resume releases
5751
+ // a held template, so nothing in the request says when its revision exists. The
5752
+ // controller records the Deployment's revision only after creating that ReplicaSet.
5753
+ // deploymentRevision is undefined until the resource loads, and empty on a loaded
5754
+ // Deployment with no revision yet, which is how one created paused starts out.
5755
+ export function useRefreshRevisionsOnNewRollout(
5756
+ kind: string,
5757
+ namespace: string,
5758
+ name: string,
5759
+ deploymentRevision: string | undefined,
5760
+ ) {
5761
+ const queryClient = useQueryClient();
5762
+ const seen = useRef(deploymentRevision);
5763
+
5764
+ useEffect(() => {
5765
+ const previous = seen.current;
5766
+ seen.current = deploymentRevision;
5767
+ if (previous === undefined || deploymentRevision === undefined || previous === deploymentRevision) return;
5768
+ queryClient.invalidateQueries({
5769
+ queryKey: ["workload-revisions", kind, namespace, name],
5770
+ });
5771
+ }, [queryClient, kind, namespace, name, deploymentRevision]);
5772
+ }
5773
+
5774
+ // The server's paused-refusal text is written for API and agent callers; in the
5775
+ // UI the way out is the Resume rollout button on the same page.
5776
+ export function rollbackErrorMessage(body: { error?: string; error_code?: string }, status: number): string {
5777
+ if (body.error_code === "workload_paused") {
5778
+ return "This Deployment is paused. Click Resume rollout, then roll back.";
5779
+ }
5780
+ return body.error || `HTTP ${status}`;
5781
+ }
5782
+
5783
+ export function restartErrorMessage(body: { error?: string; error_code?: string }, status: number): string {
5784
+ if (body.error_code === "workload_paused") {
5785
+ return "This Deployment is paused. Click Resume rollout, then restart.";
5786
+ }
5787
+ return body.error || `HTTP ${status}`;
5788
+ }
5789
+
5561
5790
  export function useRollbackWorkload() {
5562
5791
  const queryClient = useQueryClient();
5563
5792
  return useMutation({
@@ -5581,8 +5810,7 @@ export function useRollbackWorkload() {
5581
5810
  },
5582
5811
  );
5583
5812
  if (!response.ok) {
5584
- const error = await readErrorBody(response);
5585
- throw new Error(error.error || `HTTP ${response.status}`);
5813
+ throw new Error(rollbackErrorMessage(await readErrorBody(response), response.status));
5586
5814
  }
5587
5815
  return response.json();
5588
5816
  },
@@ -7531,8 +7759,20 @@ export function useSwitchContext() {
7531
7759
  // ============================================================================
7532
7760
 
7533
7761
  export interface NamespaceScope {
7762
+ /**
7763
+ * This tab's pick. Outside --namespace-scope it is the tab's own (see
7764
+ * utils/namespacePick); the server's remembered pick only seeds it.
7765
+ */
7534
7766
  actives: string[];
7535
7767
  kubeconfigNamespace: string;
7768
+ /** Context the scope was read under. Absent from servers older than per-tab picks. */
7769
+ context?: string;
7770
+ /**
7771
+ * True when the server drops its own pick to `accessibleNamespaces` on this
7772
+ * read; a tab drops its pick under the same rule. Absent from servers older
7773
+ * than per-tab picks.
7774
+ */
7775
+ accessChecked?: boolean;
7536
7776
  /**
7537
7777
  * 'cluster-wide' — no per-user pick; user can list across namespaces.
7538
7778
  * 'namespace' — per-user view filter pinned to one or more namespaces.
@@ -7551,13 +7791,42 @@ export interface NamespaceScope {
7551
7791
  cacheScopeNamespace?: string;
7552
7792
  /** true when this client may rebuild the local cache for another namespace. */
7553
7793
  namespaceRescope: boolean;
7794
+ /**
7795
+ * The server's namespace LIST failed for a reason other than RBAC (e.g. a
7796
+ * timeout right after a context switch), so accessibleNamespaces is only
7797
+ * its short fallback list. Absent from older servers.
7798
+ */
7799
+ listFailed?: boolean;
7800
+ }
7801
+
7802
+ /**
7803
+ * A failed namespace list is retried rather than kept as the answer: 3s after
7804
+ * the first failure, doubling to 30s so a list that keeps failing doesn't add
7805
+ * load to an apiserver that is already struggling.
7806
+ */
7807
+ export function namespaceScopeRefetchInterval(
7808
+ scope: Pick<NamespaceScope, "listFailed"> | undefined,
7809
+ consecutiveFailures: number,
7810
+ ): number | false {
7811
+ if (!scope?.listFailed) return false;
7812
+ return Math.min(3000 * 2 ** Math.max(0, consecutiveFailures - 1), 30000);
7554
7813
  }
7555
7814
 
7815
+ // Consecutive listFailed answers per apiBase, for the back-off above.
7816
+ const namespaceListFailures = new Map<string, number>();
7817
+
7556
7818
  export function useNamespaceScope() {
7557
7819
  return useQuery<NamespaceScope>({
7558
7820
  queryKey: ["namespace-scope"],
7559
- queryFn: () => fetchJSON("/cluster/namespace-scope"),
7821
+ queryFn: async ({ signal }) => {
7822
+ const apiBase = getApiBase();
7823
+ const scope = await fetchJSON<NamespaceScope>("/cluster/namespace-scope", signal);
7824
+ namespaceListFailures.set(apiBase, scope.listFailed ? (namespaceListFailures.get(apiBase) ?? 0) + 1 : 0);
7825
+ return applyTabPick(scope, apiBase);
7826
+ },
7560
7827
  staleTime: 30000,
7828
+ refetchInterval: (query) =>
7829
+ namespaceScopeRefetchInterval(query.state.data, namespaceListFailures.get(getApiBase()) ?? 0),
7561
7830
  });
7562
7831
  }
7563
7832
 
@@ -7619,9 +7888,34 @@ export async function refreshAfterNamespaceSwitch(
7619
7888
  await queryClient.invalidateQueries({ predicate: notScope }, { cancelRefetch: false });
7620
7889
  }
7621
7890
 
7891
+ // Per apiBase, the last namespace switch this tab started, and the newest one
7892
+ // whose answer it applied. Answers can arrive out of order: an older switch
7893
+ // must not overwrite a newer one that already landed, but it still applies
7894
+ // while the newer one is in flight, in case that one is refused.
7895
+ const startedNamespaceSwitch = new Map<string, number>();
7896
+ const appliedNamespaceSwitch = new Map<string, number>();
7897
+
7898
+ export interface NamespaceSwitchStart {
7899
+ seq: number;
7900
+ apiBase: string;
7901
+ context: string | undefined;
7902
+ }
7903
+
7904
+ /** True while `start` is the newest namespace switch this tab has applied. */
7905
+ export function isAppliedNamespaceSwitch(start: NamespaceSwitchStart | undefined): boolean {
7906
+ return !start || appliedNamespaceSwitch.get(start.apiBase) === start.seq;
7907
+ }
7908
+
7909
+ /** Records `start` as applied unless a newer switch already landed. */
7910
+ function claimNamespaceSwitch(start: NamespaceSwitchStart): boolean {
7911
+ if (start.seq < (appliedNamespaceSwitch.get(start.apiBase) ?? 0)) return false;
7912
+ appliedNamespaceSwitch.set(start.apiBase, start.seq);
7913
+ return true;
7914
+ }
7915
+
7622
7916
  export function useSetActiveNamespace() {
7623
7917
  const queryClient = useQueryClient();
7624
- return useMutation<NamespaceScope, Error, { namespaces: string[] }>({
7918
+ return useMutation<NamespaceScope, Error, { namespaces: string[] }, NamespaceSwitchStart>({
7625
7919
  meta: {
7626
7920
  // Surface 403s (RBAC drift, denied bookmark) and network errors via the
7627
7921
  // global toast. Without this, App.tsx call sites that mutate without
@@ -7665,7 +7959,9 @@ export function useSetActiveNamespace() {
7665
7959
  const error = await readErrorBody(response);
7666
7960
  throw new Error(error.error || `HTTP ${response.status}`);
7667
7961
  }
7668
- return response.json();
7962
+ // Awaited so a body lost in transfer reaches the catch below.
7963
+ const scope: NamespaceScope = await response.json();
7964
+ return scope;
7669
7965
  } catch (error) {
7670
7966
  clearTimeout(timeoutId);
7671
7967
  debugNamespaceLog("mutation:error", {
@@ -7688,10 +7984,45 @@ export function useSetActiveNamespace() {
7688
7984
  { cause: error },
7689
7985
  );
7690
7986
  }
7987
+ // A network failure can hide a write the server already made; its
7988
+ // scope says whether the pick landed. A refused pick (HTTP error) did
7989
+ // not land.
7990
+ if (!isRescope && error instanceof TypeError) {
7991
+ const applied = await reconcileNamespaceSwitch(namespaces);
7992
+ if (applied) {
7993
+ debugNamespaceLog("mutation:network-error-but-applied", { namespaces });
7994
+ return applied;
7995
+ }
7996
+ }
7691
7997
  throw error;
7692
7998
  }
7693
7999
  },
7694
- onSuccess: (scope) => {
8000
+ onMutate: () => {
8001
+ const apiBase = getApiBase();
8002
+ const seq = (startedNamespaceSwitch.get(apiBase) ?? 0) + 1;
8003
+ startedNamespaceSwitch.set(apiBase, seq);
8004
+ const context = queryClient.getQueryData<NamespaceScope>(["namespace-scope"])?.context;
8005
+ return { seq, apiBase, context };
8006
+ },
8007
+ onSuccess: (response, { namespaces }, start) => {
8008
+ let scope = response;
8009
+ if (ownsTabPick(response)) {
8010
+ // The response renders the server's stored pick after the write, which
8011
+ // another tab can change in between, and its context is read after the
8012
+ // write too. Record what this tab asked for, under the context it
8013
+ // asked in.
8014
+ const context = start.context ?? response.context;
8015
+ const cached = queryClient.getQueryData<NamespaceScope>(["namespace-scope"]);
8016
+ // A context switch landed meanwhile: the tab starts again from the
8017
+ // server's pick for the new context.
8018
+ if (getApiBase() !== start.apiBase || (cached && cached.context !== context) || response.context !== context) return;
8019
+ if (!claimNamespaceSwitch(start)) return;
8020
+ const picked = pruneTabPick(response, cleanPick(namespaces));
8021
+ writeTabPick(start.apiBase, context, picked);
8022
+ scope = withActives(response, picked);
8023
+ } else {
8024
+ claimNamespaceSwitch(start);
8025
+ }
7695
8026
  debugNamespaceLog("mutation:success-before-scope-cache-write", {
7696
8027
  actives: scope.actives,
7697
8028
  mode: scope.mode,
@@ -0,0 +1,14 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { namespaceScopeRefetchInterval } from './client'
3
+
4
+ describe('namespaceScopeRefetchInterval', () => {
5
+ it('retries a failed namespace list, backing off to 30s', () => {
6
+ expect([1, 2, 3, 4, 5, 6, 20].map(n => namespaceScopeRefetchInterval({ listFailed: true }, n)))
7
+ .toEqual([3000, 6000, 12000, 24000, 30000, 30000, 30000])
8
+ })
9
+ it('keeps a real answer, and an older Radar that never says', () => {
10
+ expect(namespaceScopeRefetchInterval({ listFailed: false }, 3)).toBe(false)
11
+ expect(namespaceScopeRefetchInterval({}, 0)).toBe(false)
12
+ expect(namespaceScopeRefetchInterval(undefined, 0)).toBe(false)
13
+ })
14
+ })