@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.
- package/package.json +10 -9
- package/src/App.tsx +65 -16
- package/src/api/client.audit-gating.test.tsx +105 -5
- package/src/api/client.auditBadgesSync.test.tsx +118 -0
- package/src/api/client.capabilitiesPoll.test.ts +61 -0
- package/src/api/client.namespaceSwitch.hook.test.tsx +170 -1
- package/src/api/client.pauseDeployment.test.tsx +77 -0
- package/src/api/client.restartError.test.ts +14 -0
- package/src/api/client.revisionRefresh.test.tsx +44 -0
- package/src/api/client.rollbackError.test.ts +14 -0
- package/src/api/client.ts +347 -16
- package/src/api/namespaceScopeRetry.test.ts +14 -0
- package/src/api/networkAttachments.test.tsx +120 -0
- package/src/api/networkAttachments.ts +30 -0
- package/src/api/radarFeatures.test.ts +5 -0
- package/src/api/radarFeatures.ts +10 -0
- package/src/api/secretsStore.test.ts +33 -0
- package/src/api/secretsStore.ts +37 -0
- package/src/api/substrateHealth.ts +134 -0
- package/src/api/velero.test.ts +60 -0
- package/src/api/velero.ts +201 -0
- package/src/api/vulnerabilities.ts +255 -0
- package/src/components/ConnectionErrorView.test.tsx +11 -0
- package/src/components/ConnectionErrorView.tsx +19 -0
- package/src/components/ContextSwitcher.tsx +9 -2
- package/src/components/NamespaceSwitcher.tsx +3 -1
- package/src/components/applications/ApplicationsView.openResource.test.tsx +118 -0
- package/src/components/applications/ApplicationsView.tsx +8 -11
- package/src/components/audit/AuditView.tsx +4 -0
- package/src/components/audit/ChecksViewTabs.test.tsx +33 -5
- package/src/components/audit/ChecksViewTabs.tsx +11 -1
- package/src/components/audit/UpgradeReadinessView.test.ts +35 -1
- package/src/components/audit/UpgradeReadinessView.tsx +60 -2
- package/src/components/audit/VulnerabilitiesView.tsx +907 -0
- package/src/components/cnpg/CNPGClusterTabs.tsx +3 -1
- package/src/components/cnpg/CNPGDrawerTrail.tsx +5 -26
- package/src/components/cnpg/CNPGInvestigationAction.test.tsx +27 -6
- package/src/components/cnpg/CNPGView.tsx +43 -117
- package/src/components/cnpg/CNPGWorkspace.compatibility.test.tsx +30 -0
- package/src/components/cnpg/host.tsx +2 -2
- package/src/components/cnpg/routes.ts +3 -1
- package/src/components/cnpg/shared.tsx +5 -53
- package/src/components/cnpg/useCNPGNavigate.ts +1 -21
- package/src/components/cnpg/useCNPGSidebarWorkspace.ts +16 -13
- package/src/components/community.tsx +42 -0
- package/src/components/cost/CostView.tsx +27 -9
- package/src/components/diagnose/InvestigationView.tsx +12 -3
- package/src/components/diagnose/diagnoseEvidenceTypes.ts +2 -0
- package/src/components/diagnose/investigationEvidence/adapters/helm.test.tsx +52 -0
- package/src/components/diagnose/investigationEvidence/adapters/helm.ts +10 -0
- package/src/components/diagnose/investigationEvidence/bodies/platform.tsx +82 -51
- package/src/components/diagnose/investigationEvidence/types.ts +5 -0
- package/src/components/diagnose/investigationMetrics.test.ts +20 -0
- package/src/components/diagnose/investigationMetrics.ts +2 -1
- package/src/components/dock/BottomDock.tsx +1 -0
- package/src/components/dock/LogsTab.tsx +3 -0
- package/src/components/dock/TerminalPreferences.query.test.tsx +57 -0
- package/src/components/dock/TerminalPreferences.test.tsx +68 -0
- package/src/components/dock/TerminalPreferences.tsx +73 -0
- package/src/components/gitops/GitOpsView.tsx +2 -10
- package/src/components/helm/HelmDrawerFrame.tsx +1 -1
- package/src/components/helm/HelmReleaseDrawer.tsx +24 -12
- package/src/components/helm/HelmView.tsx +25 -19
- package/src/components/helm/NotCheckedBadge.test.tsx +62 -0
- package/src/components/helm/NotCheckedBadge.tsx +39 -0
- package/src/components/helm/OwnedResources.test.tsx +86 -0
- package/src/components/helm/OwnedResources.tsx +69 -11
- package/src/components/home/ClusterHealthCard.heading.test.tsx +72 -0
- package/src/components/home/ClusterHealthCard.test.ts +44 -1
- package/src/components/home/ClusterHealthCard.tsx +25 -11
- package/src/components/home/HelmSummary.tsx +15 -15
- package/src/components/home/HomeAgentBlock.tsx +3 -0
- package/src/components/home/HomeView.tsx +7 -0
- package/src/components/home/MCPSetupDialog.test.tsx +19 -12
- package/src/components/home/MCPSetupDialog.tsx +4 -2
- package/src/components/home/mcpToolCatalog.ts +17 -4
- package/src/components/home/useVulnerabilitiesRow.test.ts +26 -0
- package/src/components/home/useVulnerabilitiesRow.ts +50 -0
- package/src/components/logs/LogsViewer.tsx +3 -1
- package/src/components/logs/MultiPodLogsTab.test.tsx +24 -4
- package/src/components/logs/MultiPodLogsTab.tsx +9 -5
- package/src/components/nav/PrimaryNavRail.test.tsx +17 -0
- package/src/components/nav/PrimaryNavRail.tsx +174 -29
- package/src/components/resource/PrometheusChartsGrid.tsx +5 -1
- package/src/components/resource/RightsizingStrip.test.ts +57 -0
- package/src/components/resource/RightsizingStrip.tsx +53 -4
- package/src/components/resource/SubstrateHealthCharts.test.tsx +143 -0
- package/src/components/resource/SubstrateHealthCharts.tsx +254 -0
- package/src/components/resource/SubstrateVerdictLine.test.tsx +131 -0
- package/src/components/resource/SubstrateVerdictLine.tsx +180 -0
- package/src/components/resources/ImageFilesystemModal.test.tsx +74 -6
- package/src/components/resources/ImageFilesystemModal.tsx +98 -6
- package/src/components/resources/PodFileUploadPanel.tsx +150 -0
- package/src/components/resources/PodFilesystemModal.tsx +246 -3
- package/src/components/resources/ResourcesView.tsx +12 -6
- package/src/components/resources/pod-file-upload.test.tsx +223 -0
- package/src/components/resources/pod-file-upload.ts +266 -0
- package/src/components/resources/renderers/HTTPRouteRenderer.test.tsx +50 -0
- package/src/components/resources/renderers/HTTPRouteRenderer.tsx +27 -0
- package/src/components/resources/renderers/PodRenderer.tsx +26 -1
- package/src/components/resources/renderers/SecretProviderClassRenderer.tsx +25 -0
- package/src/components/resources/renderers/UpgradePlanRenderer.test.tsx +20 -0
- package/src/components/resources/renderers/UpgradePlanRenderer.tsx +22 -0
- package/src/components/resources/renderers/VeleroBackupRenderer.tsx +16 -36
- package/src/components/resources/renderers/VeleroRestoreRenderer.tsx +6 -19
- package/src/components/resources/renderers/WorkloadRenderer.tsx +8 -0
- package/src/components/rightsizing/RightsizingScanView.tsx +19 -3
- package/src/components/rightsizing/model.test.ts +11 -0
- package/src/components/rightsizing/model.ts +3 -1
- package/src/components/rightsizing/presentation.test.ts +46 -0
- package/src/components/rightsizing/presentation.ts +17 -2
- package/src/components/shared/LargeClusterNamespacePicker.test.tsx +27 -0
- package/src/components/shared/LargeClusterNamespacePicker.tsx +8 -2
- package/src/components/timeline/TimelineView.tsx +3 -1
- package/src/components/traffic/TrafficConnectionsTable.test.tsx +94 -0
- package/src/components/traffic/TrafficConnectionsTable.tsx +21 -5
- package/src/components/traffic/TrafficData.test.tsx +37 -0
- package/src/components/traffic/TrafficData.tsx +27 -0
- package/src/components/traffic/TrafficFlowList.tsx +9 -7
- package/src/components/traffic/TrafficGraph.layoutEngine.test.tsx +193 -0
- package/src/components/traffic/TrafficGraph.test.tsx +269 -0
- package/src/components/traffic/TrafficGraph.tsx +135 -64
- package/src/components/traffic/TrafficGraphUnavailable.tsx +57 -0
- package/src/components/traffic/TrafficView.layoutUnavailable.test.tsx +211 -0
- package/src/components/traffic/TrafficView.tsx +72 -155
- package/src/components/traffic/trafficFilters.test.ts +189 -1
- package/src/components/traffic/trafficFilters.ts +169 -1
- package/src/components/ui/DiagnosticsOverlay.tsx +14 -1
- package/src/components/ui/Omnibar.tsx +4 -1
- package/src/components/ui/RadarOmnibar.test.tsx +55 -2
- package/src/components/ui/RadarOmnibar.tsx +7 -1
- package/src/components/ui/SearchSyntaxHelp.test.tsx +9 -2
- package/src/components/ui/SearchSyntaxHelp.tsx +3 -2
- package/src/components/ui/UpdateNotification.manual.test.tsx +5 -2
- package/src/components/ui/UpdateNotification.test.tsx +54 -3
- package/src/components/ui/UpdateNotification.tsx +60 -19
- package/src/components/ui/command-items.ts +24 -1
- package/src/components/ui/omnibar-match.test.ts +7 -0
- package/src/components/ui/omnibar-match.ts +1 -0
- package/src/components/ui/searchCoverageNote.test.ts +17 -0
- package/src/components/ui/searchCoverageNote.ts +31 -7
- package/src/components/useContextSwitchFlow.tsx +9 -1
- package/src/components/velero/VeleroBackupNow.test.tsx +165 -0
- package/src/components/velero/VeleroBackupNow.tsx +143 -0
- package/src/components/velero/VeleroDeleteBackup.test.tsx +364 -0
- package/src/components/velero/VeleroDeleteBackup.tsx +306 -0
- package/src/components/velero/VeleroDetailPage.tsx +148 -0
- package/src/components/velero/VeleroKindLists.test.tsx +48 -0
- package/src/components/velero/VeleroKindLists.tsx +43 -0
- package/src/components/velero/VeleroLocations.expand.test.tsx +27 -0
- package/src/components/velero/VeleroLocations.test.tsx +86 -0
- package/src/components/velero/VeleroLocations.tsx +240 -0
- package/src/components/velero/VeleroOverview.test.tsx +311 -0
- package/src/components/velero/VeleroOverview.tsx +485 -0
- package/src/components/velero/VeleroPages.test.tsx +516 -0
- package/src/components/velero/VeleroPages.tsx +1056 -0
- package/src/components/velero/VeleroRunLists.tsx +309 -0
- package/src/components/velero/VeleroRunMessagesHost.test.tsx +25 -0
- package/src/components/velero/VeleroRunMessagesHost.tsx +54 -0
- package/src/components/velero/VeleroScheduleStatusBadge.test.tsx +28 -0
- package/src/components/velero/VeleroScheduleStatusBadge.tsx +21 -0
- package/src/components/velero/VeleroSchedules.tsx +255 -0
- package/src/components/velero/VeleroView.tsx +59 -0
- package/src/components/velero/VeleroWorkspace.gate.test.tsx +97 -0
- package/src/components/velero/attention.test.ts +178 -0
- package/src/components/velero/attention.ts +281 -0
- package/src/components/velero/backupDelete.test.tsx +91 -0
- package/src/components/velero/backupDelete.tsx +182 -0
- package/src/components/velero/coverage.test.ts +87 -0
- package/src/components/velero/coverage.ts +150 -0
- package/src/components/velero/host.tsx +86 -0
- package/src/components/velero/routes.ts +78 -0
- package/src/components/velero/runs.tsx +121 -0
- package/src/components/velero/shared.test.ts +84 -0
- package/src/components/velero/shared.tsx +423 -0
- package/src/components/velero/useVeleroSidebarWorkspace.test.tsx +28 -0
- package/src/components/velero/useVeleroSidebarWorkspace.ts +71 -0
- package/src/components/velero/velero.fixtures.ts +61 -0
- package/src/components/velero/workspaceRoute.ts +21 -0
- package/src/components/vulnerabilities/WorkloadVulnerabilitiesSection.tsx +167 -0
- package/src/components/vulnerabilities/parts.test.ts +72 -0
- package/src/components/vulnerabilities/parts.tsx +291 -0
- package/src/components/workload/NodeCertificateEvidence.test.tsx +51 -0
- package/src/components/workload/NodeCertificateEvidence.tsx +44 -0
- package/src/components/workload/WorkloadView.tsx +114 -37
- package/src/components/workspace/DrawerTrailBack.tsx +32 -0
- package/src/components/workspace/WorkspaceFrame.tsx +71 -0
- package/src/components/workspace/coverage.ts +61 -0
- package/src/components/workspace/layout.test.tsx +29 -1
- package/src/components/workspace/layout.tsx +15 -5
- package/src/components/workspace/sidebar.ts +9 -0
- package/src/components/workspace/useWorkspaceDrawer.ts +63 -0
- package/src/components/workspace/useWorkspaceNavigate.ts +21 -0
- package/src/context/ConnectionContext.test.ts +1 -0
- package/src/context/ConnectionContext.tsx +2 -2
- package/src/desktop/AboutDialog.test.ts +12 -0
- package/src/desktop/AboutDialog.tsx +151 -0
- package/src/desktop/WindowsTitleBar.tsx +359 -0
- package/src/desktop/titleBar.test.ts +61 -0
- package/src/desktop/titleBar.ts +45 -0
- package/src/index.css +19 -0
- package/src/integrations/resourceHost.ts +5 -1
- package/src/integrations/resourceHosts.test.tsx +15 -3
- package/src/integrations/resourceHosts.tsx +26 -6
- package/src/integrations/workspaceRoute.ts +1 -1
- package/src/integrations/workspaceRoutes.test.ts +11 -0
- package/src/integrations/workspaceRoutes.ts +3 -1
- package/src/integrations/workspaceScreens.tsx +2 -0
- package/src/main.tsx +8 -0
- package/src/utils/desktop-zoom.test.ts +53 -0
- package/src/utils/desktop-zoom.ts +30 -0
- package/src/utils/namespacePick.test.ts +87 -0
- package/src/utils/namespacePick.ts +88 -0
- package/src/utils/staleAssetPrompt.test.tsx +76 -0
- package/src/utils/staleAssetPrompt.tsx +32 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { useMutation, useQuery, useQueryClient, type UseQueryResult } from '@tanstack/react-query'
|
|
2
|
+
import type { VeleroScheduleActivityResponse, VeleroWorkspaceResponse } from '@skyhook-io/k8s-ui'
|
|
3
|
+
import { apiFetch, fetchJSON, useRadarFeature } from './client'
|
|
4
|
+
import { readErrorBody } from './httpErrors'
|
|
5
|
+
import { getApiBase } from './config'
|
|
6
|
+
import { shouldRetryRadarQuery } from './radarFeatures'
|
|
7
|
+
|
|
8
|
+
// /api/velero/workspace
|
|
9
|
+
//
|
|
10
|
+
// Every Velero installation the caller can read, with per-kind coverage. The
|
|
11
|
+
// server ignores the namespace picker, so nothing view-scoped is sent. The API
|
|
12
|
+
// base is in the key because Radar Hub points one query client at many
|
|
13
|
+
// clusters.
|
|
14
|
+
export function useVeleroWorkspace(options?: { enabled?: boolean }) {
|
|
15
|
+
const { guard, gatedKey } = useRadarFeature('veleroWorkspace')
|
|
16
|
+
const base = getApiBase()
|
|
17
|
+
return useQuery<VeleroWorkspaceResponse>({
|
|
18
|
+
queryKey: ['velero', 'workspace', base, ...gatedKey],
|
|
19
|
+
queryFn: ({ signal }) => guard(() => fetchJSON<VeleroWorkspaceResponse>('/velero/workspace', signal)),
|
|
20
|
+
enabled: options?.enabled ?? true,
|
|
21
|
+
staleTime: 10_000,
|
|
22
|
+
refetchInterval: 30_000,
|
|
23
|
+
// Keep the previous answer while refetching, but never another cluster's.
|
|
24
|
+
placeholderData: (prev, prevQuery) => (prevQuery?.queryKey[2] === base ? prev : undefined),
|
|
25
|
+
retry: shouldRetryRadarQuery,
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// /api/velero/schedules/{namespace}/{name}/activity
|
|
30
|
+
//
|
|
31
|
+
// One Schedule's reading and its recent runs, for the Schedule drawer.
|
|
32
|
+
export function useVeleroScheduleActivity(namespace: string, name: string, options?: { enabled?: boolean }) {
|
|
33
|
+
const { guard, gatedKey } = useRadarFeature('veleroWorkspace')
|
|
34
|
+
const base = getApiBase()
|
|
35
|
+
return useQuery<VeleroScheduleActivityResponse>({
|
|
36
|
+
queryKey: ['velero', 'schedule-activity', base, namespace, name, ...gatedKey],
|
|
37
|
+
queryFn: ({ signal }) =>
|
|
38
|
+
guard(() =>
|
|
39
|
+
fetchJSON<VeleroScheduleActivityResponse>(
|
|
40
|
+
`/velero/schedules/${encodeURIComponent(namespace)}/${encodeURIComponent(name)}/activity`,
|
|
41
|
+
signal,
|
|
42
|
+
),
|
|
43
|
+
),
|
|
44
|
+
enabled: (options?.enabled ?? true) && !!namespace && !!name,
|
|
45
|
+
staleTime: 10_000,
|
|
46
|
+
refetchInterval: 30_000,
|
|
47
|
+
// Keep the previous answer only for the same schedule on the same cluster:
|
|
48
|
+
// another schedule's reading must never stand in for this one while it loads.
|
|
49
|
+
placeholderData: (prev, prevQuery) =>
|
|
50
|
+
prev && prevQuery?.queryKey[2] === base && prev.reading.namespace === namespace && prev.reading.name === name ? prev : undefined,
|
|
51
|
+
retry: shouldRetryRadarQuery,
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// POST /api/velero/schedules/{namespace}/{name}/backup
|
|
56
|
+
//
|
|
57
|
+
// Creates a Backup from the schedule's template, bound to the version of the
|
|
58
|
+
// schedule the user reviewed: a schedule edited since is refused (409).
|
|
59
|
+
export function useVeleroBackupNow() {
|
|
60
|
+
const queryClient = useQueryClient()
|
|
61
|
+
return useMutation({
|
|
62
|
+
// backupName and submission (8–64 letters, digits or hyphens) are chosen
|
|
63
|
+
// when the confirmation opens. Sending the same confirmation again, with
|
|
64
|
+
// both unchanged, returns the backup it already created; without
|
|
65
|
+
// backupName each request creates a new backup.
|
|
66
|
+
mutationFn: async ({ namespace, name, resourceVersion, backupName, submission }: { namespace: string; name: string; resourceVersion: string; backupName?: string; submission: string }) => {
|
|
67
|
+
const response = await apiFetch(
|
|
68
|
+
`${getApiBase()}/velero/schedules/${encodeURIComponent(namespace)}/${encodeURIComponent(name)}/backup`,
|
|
69
|
+
{ method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ resourceVersion, name: backupName, submission }) },
|
|
70
|
+
)
|
|
71
|
+
if (!response.ok) {
|
|
72
|
+
const error = await readErrorBody(response)
|
|
73
|
+
throw new Error(error.error || `HTTP ${response.status}`)
|
|
74
|
+
}
|
|
75
|
+
return (await response.json()) as { namespace: string; name: string }
|
|
76
|
+
},
|
|
77
|
+
meta: { errorMessage: 'Could not start the backup' },
|
|
78
|
+
onSuccess: () => {
|
|
79
|
+
void queryClient.invalidateQueries({ queryKey: ['velero'] })
|
|
80
|
+
},
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** internal/velero RunRow: one Backup or Restore as its list and pages show it. */
|
|
85
|
+
export interface VeleroRunRow {
|
|
86
|
+
namespace: string
|
|
87
|
+
name: string
|
|
88
|
+
uid: string
|
|
89
|
+
phase?: string
|
|
90
|
+
created?: string
|
|
91
|
+
started?: string
|
|
92
|
+
completed?: string
|
|
93
|
+
expiration?: string
|
|
94
|
+
/** A Backup's velero.io/schedule-name label: the schedule that submitted it. Never set on a Restore. */
|
|
95
|
+
schedule?: string
|
|
96
|
+
storageLocation?: string
|
|
97
|
+
/** Velero's progress: items processed so far (a Restore's itemsRestored also counts skipped and failed items), of itemsTotal. Absent until Velero reports them. */
|
|
98
|
+
itemsDone?: number
|
|
99
|
+
itemsTotal?: number
|
|
100
|
+
errors: number
|
|
101
|
+
warnings: number
|
|
102
|
+
/** A Backup created by Radar's Back up now from its schedule. */
|
|
103
|
+
manual?: boolean
|
|
104
|
+
reason?: string
|
|
105
|
+
backupName?: string
|
|
106
|
+
/** A Restore's spec.scheduleName: restore from that schedule's newest completed backup. Unrelated to schedule. */
|
|
107
|
+
scheduleName?: string
|
|
108
|
+
namespaceMapping?: Record<string, string>
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** A Restore's row: its namespace selection is always sent, empty for every namespace in the backup. */
|
|
112
|
+
export interface VeleroRestoreRow extends VeleroRunRow {
|
|
113
|
+
includedNamespaces: string[]
|
|
114
|
+
excludedNamespaces: string[]
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface VeleroRunsResponse<R extends VeleroRunRow = VeleroRunRow> {
|
|
118
|
+
observedAt: string
|
|
119
|
+
coverage: import('@skyhook-io/k8s-ui').VeleroKindCoverage
|
|
120
|
+
runs: R[]
|
|
121
|
+
/** The runs that passed the schedule or backup filter, before the cap; runs holds the newest. */
|
|
122
|
+
total: number
|
|
123
|
+
truncated?: boolean
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// GET /api/velero/runs/{backups|restores}?namespace=&schedule=&backup=
|
|
127
|
+
//
|
|
128
|
+
// Every Backup or Restore the caller can read, newest first, read through the
|
|
129
|
+
// same per-kind access as the Velero views; `coverage` says what it covered.
|
|
130
|
+
// `schedule` and `backup` narrow the answer on the server: one schedule's
|
|
131
|
+
// runs, or the restores made from one backup.
|
|
132
|
+
export function useVeleroRuns(kind: 'restores', namespace?: string, filter?: { backup?: string }, options?: { enabled?: boolean }): UseQueryResult<VeleroRunsResponse<VeleroRestoreRow>>
|
|
133
|
+
export function useVeleroRuns(kind: 'backups', namespace?: string, filter?: { schedule?: string }, options?: { enabled?: boolean }): UseQueryResult<VeleroRunsResponse>
|
|
134
|
+
export function useVeleroRuns(kind: 'backups' | 'restores', namespace?: string, filter?: { schedule?: string; backup?: string }, options?: { enabled?: boolean }) {
|
|
135
|
+
const { guard, gatedKey } = useRadarFeature('veleroRuns')
|
|
136
|
+
const base = getApiBase()
|
|
137
|
+
const params = new URLSearchParams()
|
|
138
|
+
if (namespace) params.set('namespace', namespace)
|
|
139
|
+
if (filter?.schedule) params.set('schedule', filter.schedule)
|
|
140
|
+
if (filter?.backup) params.set('backup', filter.backup)
|
|
141
|
+
const query = params.toString()
|
|
142
|
+
return useQuery<VeleroRunsResponse>({
|
|
143
|
+
queryKey: ['velero', 'runs', base, kind, namespace ?? '', filter?.schedule ?? '', filter?.backup ?? '', ...gatedKey],
|
|
144
|
+
queryFn: ({ signal }) => guard(() => fetchJSON<VeleroRunsResponse>(`/velero/runs/${kind}${query ? `?${query}` : ''}`, signal)),
|
|
145
|
+
enabled: options?.enabled ?? true,
|
|
146
|
+
staleTime: 10_000,
|
|
147
|
+
refetchInterval: 30_000,
|
|
148
|
+
placeholderData: (prev, prevQuery) =>
|
|
149
|
+
prevQuery?.queryKey[2] === base && prevQuery?.queryKey[3] === kind && prevQuery?.queryKey[4] === (namespace ?? '') && prevQuery?.queryKey[5] === (filter?.schedule ?? '') && prevQuery?.queryKey[6] === (filter?.backup ?? '') ? prev : undefined,
|
|
150
|
+
retry: shouldRetryRadarQuery,
|
|
151
|
+
})
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export interface VeleroDeletion {
|
|
155
|
+
state: 'waiting' | 'inProgress' | 'refused' | 'failed' | 'deleted' | 'unknown'
|
|
156
|
+
errors?: string[]
|
|
157
|
+
/** Absent when no request for the backup is retained: Velero removes a successful one with the backup, and any processed one after a day. */
|
|
158
|
+
request?: string
|
|
159
|
+
/** When the request was made; absent with request, or when it has no creation time. */
|
|
160
|
+
created?: string
|
|
161
|
+
/** A waiting request whose server Deployment has no pods (status.replicas is 0). Sent only when true, and checked only while waiting. */
|
|
162
|
+
serverStopped?: boolean
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// POST /api/velero/backups/{namespace}/{name}/delete
|
|
166
|
+
//
|
|
167
|
+
// Asks Velero to delete a backup through a DeleteBackupRequest, bound to the
|
|
168
|
+
// backup the user reviewed (its UID). An open request is reused by the server.
|
|
169
|
+
export function useVeleroDeleteBackup() {
|
|
170
|
+
return useMutation({
|
|
171
|
+
// fetchJSON throws ApiError, so the dialog can tell a refusal (4xx) from a
|
|
172
|
+
// write whose outcome is unknown.
|
|
173
|
+
mutationFn: ({ namespace, name, uid }: { namespace: string; name: string; uid: string }) =>
|
|
174
|
+
fetchJSON<{ request: string }>(
|
|
175
|
+
`/velero/backups/${encodeURIComponent(namespace)}/${encodeURIComponent(name)}/delete`,
|
|
176
|
+
{ method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ uid }) },
|
|
177
|
+
),
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const SETTLED = ['refused', 'failed', 'deleted', 'unknown']
|
|
182
|
+
|
|
183
|
+
export function useVeleroBackupDeletion(namespace: string, name: string, uid: string, enabled = true) {
|
|
184
|
+
const { guard, gatedKey } = useRadarFeature('veleroDeleteBackup')
|
|
185
|
+
const base = getApiBase()
|
|
186
|
+
return useQuery<VeleroDeletion>({
|
|
187
|
+
queryKey: ['velero', 'deletion', base, namespace, name, uid, ...gatedKey],
|
|
188
|
+
queryFn: ({ signal }) => guard(() => fetchJSON<VeleroDeletion>(
|
|
189
|
+
`/velero/backups/${encodeURIComponent(namespace)}/${encodeURIComponent(name)}/deletion?uid=${encodeURIComponent(uid)}`, signal)),
|
|
190
|
+
enabled: enabled && !!uid && !!namespace && !!name,
|
|
191
|
+
refetchInterval: (query) => {
|
|
192
|
+
const status = (query.state.error as { status?: number } | null)?.status
|
|
193
|
+
if (status && status >= 400 && status < 500) return false
|
|
194
|
+
return query.state.data && SETTLED.includes(query.state.data.state) ? false : 2_000
|
|
195
|
+
},
|
|
196
|
+
retry: (count, error) => {
|
|
197
|
+
const status = (error as { status?: number } | null)?.status
|
|
198
|
+
return status && status >= 400 && status < 500 ? false : shouldRetryRadarQuery(count, error)
|
|
199
|
+
},
|
|
200
|
+
})
|
|
201
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query'
|
|
2
|
+
import type { ReadGap } from '@skyhook-io/k8s-ui/types/read-coverage'
|
|
3
|
+
import type { APIResource } from '../types'
|
|
4
|
+
import { ApiError, fetchJSON, useRadarFeature } from './client'
|
|
5
|
+
import { readActionFor } from '@skyhook-io/k8s-ui/utils/read-actions'
|
|
6
|
+
import { shouldRetryRadarQuery } from './radarFeatures'
|
|
7
|
+
|
|
8
|
+
// Mirrors internal/vulnerabilities/types.go.
|
|
9
|
+
|
|
10
|
+
/** 'summary' is the totals and coverage without rows, for a page that shows counts. */
|
|
11
|
+
export type VulnerabilityView = 'image' | 'fix' | 'cve' | 'workload' | 'summary'
|
|
12
|
+
export type VulnerabilitySeverity = 'critical' | 'high' | 'medium' | 'low' | 'unknown'
|
|
13
|
+
|
|
14
|
+
export interface VulnerabilityCounts {
|
|
15
|
+
critical: number
|
|
16
|
+
high: number
|
|
17
|
+
medium: number
|
|
18
|
+
low: number
|
|
19
|
+
unknown: number
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface VulnerabilityWorkloadRef {
|
|
23
|
+
kind: string
|
|
24
|
+
group: string
|
|
25
|
+
namespace: string
|
|
26
|
+
name: string
|
|
27
|
+
container?: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface VulnerabilityFinding {
|
|
31
|
+
id: string
|
|
32
|
+
severity: VulnerabilitySeverity
|
|
33
|
+
/** The scanner gave no severity; this is the CVSS rating of score. */
|
|
34
|
+
severityFromScore?: boolean
|
|
35
|
+
score?: number
|
|
36
|
+
package: string
|
|
37
|
+
installedVersion: string
|
|
38
|
+
fixedVersion?: string
|
|
39
|
+
/** The smallest fixed version above the installed one, when Radar can order the package's versions. */
|
|
40
|
+
fixTarget?: string
|
|
41
|
+
packageType?: string
|
|
42
|
+
title?: string
|
|
43
|
+
link?: string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface VulnerableImage {
|
|
47
|
+
id: string
|
|
48
|
+
image: string
|
|
49
|
+
digest?: string
|
|
50
|
+
os?: string
|
|
51
|
+
scannedAt: string
|
|
52
|
+
counts: VulnerabilityCounts
|
|
53
|
+
fixable: VulnerabilityCounts
|
|
54
|
+
matching: number
|
|
55
|
+
/** Past the request's findings budget: counts unknown, not zero. */
|
|
56
|
+
findingsUnread?: boolean
|
|
57
|
+
workloads: VulnerabilityWorkloadRef[]
|
|
58
|
+
workloadsTotal: number
|
|
59
|
+
findings: VulnerabilityFinding[]
|
|
60
|
+
findingsTotal: number
|
|
61
|
+
report: { kind: string; group?: string; namespace?: string; name: string }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface VulnerabilityCVEImage {
|
|
65
|
+
imageId: string
|
|
66
|
+
image: string
|
|
67
|
+
packages: { package: string; installedVersion: string; fixedVersion?: string; fixTarget?: string }[]
|
|
68
|
+
workloads: VulnerabilityWorkloadRef[]
|
|
69
|
+
workloadsTotal: number
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface VulnerabilityCVE {
|
|
73
|
+
id: string
|
|
74
|
+
severity: VulnerabilitySeverity
|
|
75
|
+
score?: number
|
|
76
|
+
packages: string[]
|
|
77
|
+
fixable: boolean
|
|
78
|
+
/** Of `images`, the ones where every package the CVE is in has a fixed version. */
|
|
79
|
+
fixableImages: number
|
|
80
|
+
title?: string
|
|
81
|
+
link?: string
|
|
82
|
+
images: number
|
|
83
|
+
workloads: number
|
|
84
|
+
affected: VulnerabilityCVEImage[]
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface VulnerabilityFix {
|
|
88
|
+
package: string
|
|
89
|
+
packageType?: string
|
|
90
|
+
/** The lowest listed release that fixes every listed CVE; absent when none can be chosen from the scanner's versions. */
|
|
91
|
+
to?: string
|
|
92
|
+
/** Each distinct fixed-version text the scanner wrote, when there is no target. */
|
|
93
|
+
fixedVersions?: string[]
|
|
94
|
+
from: string[]
|
|
95
|
+
severity: VulnerabilitySeverity
|
|
96
|
+
counts: VulnerabilityCounts
|
|
97
|
+
cves: string[]
|
|
98
|
+
cvesTotal: number
|
|
99
|
+
images: number
|
|
100
|
+
workloads: number
|
|
101
|
+
affected: { imageId: string; image: string; installedVersions: string[]; workloads: VulnerabilityWorkloadRef[]; workloadsTotal: number }[]
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface VulnerabilityWorkloadContainer {
|
|
105
|
+
name: string
|
|
106
|
+
image: string
|
|
107
|
+
imageId?: string
|
|
108
|
+
scanned: boolean
|
|
109
|
+
scannedAt?: string
|
|
110
|
+
findingsUnread?: boolean
|
|
111
|
+
counts?: VulnerabilityCounts
|
|
112
|
+
fixable?: VulnerabilityCounts
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface VulnerabilityWorkload {
|
|
116
|
+
kind: string
|
|
117
|
+
group: string
|
|
118
|
+
namespace: string
|
|
119
|
+
name: string
|
|
120
|
+
counts: VulnerabilityCounts
|
|
121
|
+
fixable: VulnerabilityCounts
|
|
122
|
+
containers: VulnerabilityWorkloadContainer[]
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface VulnerabilitySummary {
|
|
126
|
+
imagesScanned: number
|
|
127
|
+
imagesClean: number
|
|
128
|
+
imagesUnscanned: number
|
|
129
|
+
imagesWithCritical: number
|
|
130
|
+
fixableCriticalHighCves: number
|
|
131
|
+
workloadsWithCriticalOrHigh: number
|
|
132
|
+
workloads: number
|
|
133
|
+
counts: VulnerabilityCounts
|
|
134
|
+
newestScan?: string
|
|
135
|
+
oldestScan?: string
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** A shared read gap; `kinds` names what wasn't read, absent meaning the reports themselves. */
|
|
139
|
+
export type VulnerabilityGap = ReadGap
|
|
140
|
+
|
|
141
|
+
export interface VulnerabilitiesResponse {
|
|
142
|
+
source: string
|
|
143
|
+
view: VulnerabilityView
|
|
144
|
+
summary: VulnerabilitySummary
|
|
145
|
+
images?: VulnerableImage[]
|
|
146
|
+
cves?: VulnerabilityCVE[]
|
|
147
|
+
workloads?: VulnerabilityWorkload[]
|
|
148
|
+
fixes?: VulnerabilityFix[]
|
|
149
|
+
/** Scanned images with no findings, kept out of the rows unless searched for. */
|
|
150
|
+
clean?: { id: string; image: string; scannedAt: string; workloads: VulnerabilityWorkloadRef[]; workloadsTotal: number; report: VulnerableImage['report'] }[]
|
|
151
|
+
/** Workloads whose every container is scanned and clean. */
|
|
152
|
+
cleanWorkloads?: VulnerabilityWorkloadRef[]
|
|
153
|
+
/** otherBuildScanned: Trivy's report is of another build of this tag, as after the tag moved. */
|
|
154
|
+
unscanned?: { image: string; otherBuildScanned?: boolean; workloads: VulnerabilityWorkloadRef[]; workloadsTotal: number }[]
|
|
155
|
+
coverage: {
|
|
156
|
+
complete: boolean
|
|
157
|
+
gaps: VulnerabilityGap[]
|
|
158
|
+
inactiveReports: number
|
|
159
|
+
truncated?: boolean
|
|
160
|
+
rowsOmitted?: number
|
|
161
|
+
cleanOmitted?: number
|
|
162
|
+
unscannedOmitted?: number
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface VulnerabilitiesParams {
|
|
167
|
+
view: VulnerabilityView
|
|
168
|
+
namespaces?: string[]
|
|
169
|
+
severities?: VulnerabilitySeverity[]
|
|
170
|
+
fixableOnly?: boolean
|
|
171
|
+
query?: string
|
|
172
|
+
workload?: { kind: string; group?: string; namespace: string; name: string }
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// What an answer is about, apart from its filters: the workload and the
|
|
176
|
+
// namespaces. An answer about another one is never shown as a placeholder.
|
|
177
|
+
function subjectOfPath(path: unknown): string {
|
|
178
|
+
if (typeof path !== 'string') return ''
|
|
179
|
+
const q = new URLSearchParams(path.split('?')[1] ?? '')
|
|
180
|
+
return [q.get('workloadKind'), q.get('workloadNamespace'), q.get('workloadName'), q.get('namespaces')].join('/')
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** The cluster doesn't serve the report kind: no scanner, not a failure. */
|
|
184
|
+
export function isKindUnknown(error: unknown): boolean {
|
|
185
|
+
return error instanceof ApiError && error.status === 404 && error.data?.error_code === 'kind_unknown'
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** A workload as the tab's `workload` URL filter writes it: Kind/namespace/name. */
|
|
189
|
+
export function workloadParam(w: { kind: string; namespace: string; name: string }): string {
|
|
190
|
+
return `${w.kind}/${w.namespace}/${w.name}`
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function parseWorkloadParam(value: string | null): { kind: string; namespace: string; name: string } | undefined {
|
|
194
|
+
const parts = (value ?? '').split('/')
|
|
195
|
+
if (parts.length !== 3 || parts.some((p) => p === '')) return undefined
|
|
196
|
+
return { kind: parts[0], namespace: parts[1], name: parts[2] }
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Trivy Operator's VulnerabilityReport is the one source the rollup reads;
|
|
200
|
+
// the Vulnerabilities tab, Home tile and drawer section show only when the
|
|
201
|
+
// cluster serves it.
|
|
202
|
+
export function hasVulnerabilityReports(resources: APIResource[] | undefined): boolean {
|
|
203
|
+
return !!resources?.some((r) => r.group === 'aquasecurity.github.io' && r.name === 'vulnerabilityreports')
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export function vulnerabilitiesPath(p: VulnerabilitiesParams): string {
|
|
207
|
+
const params = new URLSearchParams()
|
|
208
|
+
params.set('view', p.view)
|
|
209
|
+
if (p.namespaces && p.namespaces.length > 0) params.set('namespaces', p.namespaces.join(','))
|
|
210
|
+
if (p.severities && p.severities.length > 0) params.set('severity', p.severities.join(','))
|
|
211
|
+
if (p.fixableOnly) params.set('fixable', '1')
|
|
212
|
+
if (p.query?.trim()) params.set('q', p.query.trim())
|
|
213
|
+
if (p.workload) {
|
|
214
|
+
params.set('workloadKind', p.workload.kind)
|
|
215
|
+
params.set('workloadNamespace', p.workload.namespace)
|
|
216
|
+
params.set('workloadName', p.workload.name)
|
|
217
|
+
if (p.workload.group) params.set('workloadGroup', p.workload.group)
|
|
218
|
+
}
|
|
219
|
+
return `/vulnerabilities?${params.toString()}`
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// GET /api/vulnerabilities. Filters run server-side so the summary always
|
|
223
|
+
// describes the unfiltered scope and every surface (REST, MCP) filters alike.
|
|
224
|
+
export function useVulnerabilities(p: VulnerabilitiesParams, enabled = true) {
|
|
225
|
+
const { guard, gatedKey } = useRadarFeature('vulnerabilities')
|
|
226
|
+
const path = vulnerabilitiesPath(p)
|
|
227
|
+
return useQuery<VulnerabilitiesResponse>({
|
|
228
|
+
queryKey: ['vulnerabilities', path, ...gatedKey],
|
|
229
|
+
queryFn: ({ signal }) => guard(() => fetchJSON<VulnerabilitiesResponse>(path, signal)),
|
|
230
|
+
enabled,
|
|
231
|
+
// A read that settles by itself (the kind still syncing on a cold start,
|
|
232
|
+
// the connection just changed) keeps retrying, so callers show their
|
|
233
|
+
// loading state rather than an error.
|
|
234
|
+
retry: (failures, error) => (readSettles(error) ? failures < 8 : shouldRetryRadarQuery(failures, error)),
|
|
235
|
+
staleTime: 30_000,
|
|
236
|
+
// The tab's tables can run to megabytes and scans change hourly, so they
|
|
237
|
+
// refresh every five minutes; Home's totals and one workload's rows are
|
|
238
|
+
// small and stay at a minute.
|
|
239
|
+
refetchInterval: p.view === 'summary' || p.workload ? 60_000 : 300_000,
|
|
240
|
+
refetchIntervalInBackground: false,
|
|
241
|
+
// Keep showing the last answer, dimmed, while the tab's filters or view
|
|
242
|
+
// change (the summary is the same in every view; a caller shows rows
|
|
243
|
+
// only once data.view matches), but never carry one workload's or
|
|
244
|
+
// namespace scope's answer to another.
|
|
245
|
+
placeholderData: (prev, prevQuery) => (subjectOfPath(prevQuery?.queryKey[1]) === subjectOfPath(path) ? prev : undefined),
|
|
246
|
+
})
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Whether a failed read settles by itself: Radar still loading the kind, or
|
|
250
|
+
// its connection just changed. A 503 naming something to fix doesn't.
|
|
251
|
+
export function readSettles(error: unknown): boolean {
|
|
252
|
+
if (!(error instanceof ApiError)) return false
|
|
253
|
+
const code = error.data?.error_code
|
|
254
|
+
return error.status === 409 || (error.status === 503 && (code === undefined || readActionFor(code) === 'retry'))
|
|
255
|
+
}
|
|
@@ -192,6 +192,17 @@ describe('ConnectionErrorView kubeconfig guidance', () => {
|
|
|
192
192
|
})
|
|
193
193
|
})
|
|
194
194
|
|
|
195
|
+
describe('ConnectionErrorView settings error', () => {
|
|
196
|
+
it('shows the message itself and no action a restart is needed to clear', () => {
|
|
197
|
+
const markup = renderError('settings', 'prod')
|
|
198
|
+
|
|
199
|
+
expect(markup).toContain('safe error')
|
|
200
|
+
expect(markup).not.toContain('id="connection-raw-error"')
|
|
201
|
+
expect(markup).not.toContain('Retry Connection')
|
|
202
|
+
expect(markup).not.toContain('Switch context')
|
|
203
|
+
})
|
|
204
|
+
})
|
|
205
|
+
|
|
195
206
|
describe('ConnectionErrorView after a refused switch', () => {
|
|
196
207
|
const connection = { state: 'disconnected' as const, context: 'staging-eu', errorType: 'auth', error: 'safe error' }
|
|
197
208
|
|
|
@@ -403,6 +403,25 @@ export function ConnectionErrorView({ connection, onRetry, isRetrying, back, var
|
|
|
403
403
|
openLocalTerminal({ initialCommand: command, title: 'Auth' })
|
|
404
404
|
}
|
|
405
405
|
|
|
406
|
+
// A startup setting kept Radar from connecting, and the error names the
|
|
407
|
+
// setting to change. Settings are read at startup, so retrying or switching
|
|
408
|
+
// context can't clear it: only the message, no recovery actions.
|
|
409
|
+
if (connection.errorType === 'settings') {
|
|
410
|
+
return (
|
|
411
|
+
<div className="flex-1 flex items-start justify-center pt-12 px-8">
|
|
412
|
+
<div className="max-w-xl w-full flex flex-col items-center text-center">
|
|
413
|
+
<div className="w-14 h-14 rounded-full bg-red-500/10 flex items-center justify-center mb-5">
|
|
414
|
+
<ServerOff className="w-8 h-8 text-red-400" />
|
|
415
|
+
</div>
|
|
416
|
+
<h2 className="text-xl font-semibold text-theme-text-primary mb-6">Settings Need a Change</h2>
|
|
417
|
+
<div className="w-full bg-theme-surface border border-theme-border rounded-lg p-4 text-left">
|
|
418
|
+
<p className="text-sm text-theme-text-secondary break-words">{connection.error}</p>
|
|
419
|
+
</div>
|
|
420
|
+
</div>
|
|
421
|
+
</div>
|
|
422
|
+
)
|
|
423
|
+
}
|
|
424
|
+
|
|
406
425
|
return (
|
|
407
426
|
<div className="flex-1 flex items-start justify-center pt-12 px-8">
|
|
408
427
|
<div className="max-w-xl w-full">
|
|
@@ -7,6 +7,7 @@ import { useContexts, useClusterInfo, useCapabilities } from '../api/client'
|
|
|
7
7
|
import type { ContextInfo } from '../types'
|
|
8
8
|
import { useContextSwitchFlow } from './useContextSwitchFlow'
|
|
9
9
|
import { useContextSwitch } from '../context/ContextSwitchContext'
|
|
10
|
+
import { useConnection } from '../context/ConnectionContext'
|
|
10
11
|
import { parseContextForSwitcher, visibleContextQualifier, type ParsedContextName } from '../utils/context-name'
|
|
11
12
|
|
|
12
13
|
interface ContextSwitcherProps {
|
|
@@ -31,6 +32,10 @@ export const ContextSwitcher = forwardRef<ContextSwitcherHandle, ContextSwitcher
|
|
|
31
32
|
const { data: capabilities } = useCapabilities()
|
|
32
33
|
const switchFlow = useContextSwitchFlow()
|
|
33
34
|
const { failedSwitch } = useContextSwitch()
|
|
35
|
+
// A settings error (Desktop's namespace list over the limit) blocks every
|
|
36
|
+
// switch until restart, so offering the list would only lead to a refusal.
|
|
37
|
+
const { connection } = useConnection()
|
|
38
|
+
const settingsBlocked = connection.errorType === 'settings'
|
|
34
39
|
|
|
35
40
|
// Parse contexts and decide whether to render group headers (multi-account only).
|
|
36
41
|
// hasMultipleSources gates the kubeconfig-source chip — only useful when 2+
|
|
@@ -80,7 +85,9 @@ export const ContextSwitcher = forwardRef<ContextSwitcherHandle, ContextSwitcher
|
|
|
80
85
|
id: p.context.name,
|
|
81
86
|
name: p.raw,
|
|
82
87
|
nameQualifier: visibleContextQualifier(p.nameQualifier, p.context.source, hasMultipleSources),
|
|
83
|
-
|
|
88
|
+
// The full context under any shortened name: OpenShift writes one context
|
|
89
|
+
// per project for the same server, and only this line tells them apart.
|
|
90
|
+
secondary: p.raw !== p.clusterName ? p.raw : undefined,
|
|
84
91
|
badge: p.region || undefined,
|
|
85
92
|
sourceLabel: hasMultipleSources ? p.context.source : undefined,
|
|
86
93
|
group: { key: groupKey, label: groupLabel },
|
|
@@ -134,7 +141,7 @@ export const ContextSwitcher = forwardRef<ContextSwitcherHandle, ContextSwitcher
|
|
|
134
141
|
items={items}
|
|
135
142
|
onSelect={handleSelect}
|
|
136
143
|
loading={switchFlow.isPending}
|
|
137
|
-
disabled={contextsLoading || !capabilities || capabilities.configManagement === 'operator'}
|
|
144
|
+
disabled={settingsBlocked || contextsLoading || !capabilities || capabilities.configManagement === 'operator'}
|
|
138
145
|
searchable={items.length > 1}
|
|
139
146
|
currentSelectable={!!failedSwitch}
|
|
140
147
|
showGroupHeaders={hasMultipleAccounts}
|
|
@@ -33,7 +33,9 @@ export const NamespaceSwitcher = forwardRef<NamespaceSwitcherHandle, NamespaceSw
|
|
|
33
33
|
// per-user RBAC filter on a shared install, where neither applies.
|
|
34
34
|
const canConfigureNamespaces = capabilities?.deployment?.mode === 'local' && authMe?.authEnabled === false
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
// A failed list is a transient read error, retried by the scope query; it
|
|
37
|
+
// says nothing about which namespaces the user can configure.
|
|
38
|
+
const limitedListHelp = canConfigureNamespaces && !scope?.listFailed ? (
|
|
37
39
|
<a href={NAMESPACES_HELP_URL} target="_blank" rel="noreferrer" className="text-accent-text hover:underline">
|
|
38
40
|
How to add namespaces
|
|
39
41
|
</a>
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act, useEffect } from 'react'
|
|
3
|
+
import { createRoot } from 'react-dom/client'
|
|
4
|
+
import { MemoryRouter, useLocation } from 'react-router-dom'
|
|
5
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
6
|
+
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
|
7
|
+
import { ToastProvider, type AppRow, type AppWorkload, type SelectedResource } from '@skyhook-io/k8s-ui'
|
|
8
|
+
import { ApplicationsView } from './ApplicationsView'
|
|
9
|
+
|
|
10
|
+
let apps: AppRow[] = []
|
|
11
|
+
const idle = { data: undefined, isLoading: false, isError: false, error: null }
|
|
12
|
+
|
|
13
|
+
vi.mock('../../api/client', () => ({
|
|
14
|
+
useApplications: () => ({ ...idle, data: { applications: apps }, isSuccess: true, dataUpdatedAt: 0, refetch: () => {} }),
|
|
15
|
+
useApplicationHistory: () => idle,
|
|
16
|
+
useGitOpsTree: () => idle,
|
|
17
|
+
useHelmRelease: () => idle,
|
|
18
|
+
useIssues: () => idle,
|
|
19
|
+
useTopology: () => idle,
|
|
20
|
+
}))
|
|
21
|
+
vi.mock('../../context/ConnectionContext', () => ({ useConnection: () => ({ connection: { state: 'connected', context: 'test' } }) }))
|
|
22
|
+
vi.mock('../../context/TimelineSource', () => ({
|
|
23
|
+
useTimelineSource: () => ({ capabilities: { mode: 'local' }, useEvents: () => ({ data: [], isLoading: false, isError: false }) }),
|
|
24
|
+
}))
|
|
25
|
+
// The workload view's own content is out of scope here: the stub stands in for
|
|
26
|
+
// any resource the user clicks inside it (a config chip or a topology node).
|
|
27
|
+
vi.mock('../workload/WorkloadView', () => ({
|
|
28
|
+
WorkloadView: ({ name, onNavigateToResource }: { name: string; onNavigateToResource: (r: SelectedResource) => void }) => (
|
|
29
|
+
<div data-testid="workload-view" data-name={name}>
|
|
30
|
+
<button data-testid="open-cm" onClick={() => onNavigateToResource({ kind: 'ConfigMap', namespace: 'shop', name: 'web-config' })} />
|
|
31
|
+
<button data-testid="open-ing" onClick={() => onNavigateToResource({ kind: 'Ingress', namespace: 'shop', name: 'web', group: 'networking.k8s.io' })} />
|
|
32
|
+
</div>
|
|
33
|
+
),
|
|
34
|
+
}))
|
|
35
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
36
|
+
|
|
37
|
+
function deployment(name: string): AppWorkload {
|
|
38
|
+
return { kind: 'Deployment', group: 'apps', namespace: 'shop', name, health: 'healthy', ready: 1, desired: 1, restarts: 0 }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function app(key: string, workloadNames: string[]): AppRow {
|
|
42
|
+
return { key, name: key.split('/').pop() ?? key, namespace: 'shop', health: 'healthy', workloads: workloadNames.map(deployment) }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let root: ReturnType<typeof createRoot>
|
|
46
|
+
let container: HTMLDivElement
|
|
47
|
+
let client: QueryClient
|
|
48
|
+
let location = ''
|
|
49
|
+
|
|
50
|
+
function recordLocation(next: string) {
|
|
51
|
+
location = next
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function LocationProbe({ onChange }: { onChange: (location: string) => void }) {
|
|
55
|
+
const loc = useLocation()
|
|
56
|
+
useEffect(() => onChange(`${loc.pathname}${loc.search}`), [loc, onChange])
|
|
57
|
+
return null
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
beforeEach(() => {
|
|
61
|
+
vi.stubGlobal('matchMedia', () => ({ matches: false, addEventListener: () => {}, removeEventListener: () => {} }))
|
|
62
|
+
container = document.createElement('div')
|
|
63
|
+
document.body.appendChild(container)
|
|
64
|
+
root = createRoot(container)
|
|
65
|
+
client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
afterEach(async () => {
|
|
69
|
+
await act(async () => root.unmount())
|
|
70
|
+
container.remove()
|
|
71
|
+
client.clear()
|
|
72
|
+
vi.unstubAllGlobals()
|
|
73
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
async function renderAt(url: string, onOpenResource = vi.fn()) {
|
|
77
|
+
await act(async () => {
|
|
78
|
+
root.render(
|
|
79
|
+
<QueryClientProvider client={client}>
|
|
80
|
+
<ToastProvider>
|
|
81
|
+
<MemoryRouter initialEntries={[url]}>
|
|
82
|
+
<ApplicationsView namespaces={[]} onOpenResource={onOpenResource} />
|
|
83
|
+
<LocationProbe onChange={recordLocation} />
|
|
84
|
+
</MemoryRouter>
|
|
85
|
+
</ToastProvider>
|
|
86
|
+
</QueryClientProvider>,
|
|
87
|
+
)
|
|
88
|
+
})
|
|
89
|
+
await act(async () => { await new Promise((resolve) => setTimeout(resolve, 0)) })
|
|
90
|
+
return onOpenResource
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function click(testId: string) {
|
|
94
|
+
const button = container.querySelector(`[data-testid="${testId}"]`)
|
|
95
|
+
if (!(button instanceof HTMLElement)) throw new Error(`no ${testId} in the workload view`)
|
|
96
|
+
await act(async () => button.click())
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
it('opens a ConfigMap clicked in a single-workload app on its resource page', async () => {
|
|
100
|
+
apps = [app('shop/Deployment/web', ['web'])]
|
|
101
|
+
await renderAt('/applications?app=shop%2FDeployment%2Fweb&tab=topology')
|
|
102
|
+
await click('open-cm')
|
|
103
|
+
const url = new URL(location, 'http://radar.invalid')
|
|
104
|
+
expect(url.pathname).toBe('/resources/configmaps')
|
|
105
|
+
expect(url.searchParams.get('resource')).toBe('shop/web-config')
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it('keeps the API group, namespace filter and open investigation when opening an Ingress from a single-workload app', async () => {
|
|
109
|
+
apps = [app('shop/Deployment/web', ['web'])]
|
|
110
|
+
await renderAt('/applications?app=shop%2FDeployment%2Fweb&namespaces=shop&ai-run=run-1')
|
|
111
|
+
await click('open-ing')
|
|
112
|
+
const url = new URL(location, 'http://radar.invalid')
|
|
113
|
+
expect(url.pathname).toBe('/resources/ingresses')
|
|
114
|
+
expect(url.searchParams.get('resource')).toBe('shop/web')
|
|
115
|
+
expect(url.searchParams.get('apiGroup')).toBe('networking.k8s.io')
|
|
116
|
+
expect(url.searchParams.get('namespaces')).toBe('shop')
|
|
117
|
+
expect(url.searchParams.get('ai-run')).toBe('run-1')
|
|
118
|
+
})
|