@skyhook-io/radar-app 1.20.3 → 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 +54 -10
- 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.ts +129 -5
- package/src/api/namespaceScopeRetry.test.ts +14 -0
- package/src/api/radarFeatures.ts +7 -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/NamespaceSwitcher.tsx +3 -1
- 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/diagnose/diagnoseEvidenceTypes.ts +2 -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/gitops/GitOpsView.tsx +1 -1
- package/src/components/helm/HelmDrawerFrame.tsx +1 -1
- package/src/components/helm/HelmView.tsx +20 -16
- package/src/components/helm/OwnedResources.tsx +4 -3
- package/src/components/home/ClusterHealthCard.tsx +3 -1
- 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 +15 -2
- 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/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/ResourcesView.tsx +12 -6
- 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 +3 -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 +46 -129
- package/src/components/traffic/trafficFilters.test.ts +172 -1
- package/src/components/traffic/trafficFilters.ts +139 -0
- package/src/components/ui/DiagnosticsOverlay.tsx +14 -1
- package/src/components/ui/UpdateNotification.manual.test.tsx +5 -2
- package/src/components/ui/UpdateNotification.test.tsx +31 -2
- package/src/components/ui/UpdateNotification.tsx +34 -17
- package/src/components/ui/command-items.ts +24 -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/WorkloadView.tsx +64 -27
- 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/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 +14 -2
- package/src/integrations/resourceHosts.tsx +22 -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/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
|
+
}
|
|
@@ -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>
|
|
@@ -9,6 +9,7 @@ import { Tooltip } from '../ui/Tooltip'
|
|
|
9
9
|
import { useConnection } from '../../context/ConnectionContext'
|
|
10
10
|
import { ChecksViewTabs } from './ChecksViewTabs'
|
|
11
11
|
import { UpgradeReadinessView } from './UpgradeReadinessView'
|
|
12
|
+
import { VulnerabilitiesView } from './VulnerabilitiesView'
|
|
12
13
|
|
|
13
14
|
interface AuditViewProps {
|
|
14
15
|
namespaces: string[]
|
|
@@ -26,6 +27,9 @@ export function AuditView({ namespaces, onNavigateToResource }: AuditViewProps)
|
|
|
26
27
|
if (pathname.startsWith('/checks/upgrade')) {
|
|
27
28
|
return <UpgradeReadinessView namespaces={namespaces} onNavigateToResource={onNavigateToResource} />
|
|
28
29
|
}
|
|
30
|
+
if (pathname.startsWith('/checks/vulnerabilities')) {
|
|
31
|
+
return <VulnerabilitiesView namespaces={namespaces} onNavigateToResource={onNavigateToResource} />
|
|
32
|
+
}
|
|
29
33
|
return <BestPracticesView namespaces={namespaces} onNavigateToResource={onNavigateToResource} />
|
|
30
34
|
}
|
|
31
35
|
|
|
@@ -1,15 +1,30 @@
|
|
|
1
1
|
import { renderToStaticMarkup } from 'react-dom/server'
|
|
2
2
|
import { MemoryRouter } from 'react-router-dom'
|
|
3
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
3
4
|
import { describe, expect, it } from 'vitest'
|
|
5
|
+
import type { APIResource } from '../../types'
|
|
4
6
|
import { ChecksViewTabs } from './ChecksViewTabs'
|
|
5
7
|
|
|
8
|
+
const vulnerabilityReports: APIResource = {
|
|
9
|
+
name: 'vulnerabilityreports', kind: 'VulnerabilityReport', group: 'aquasecurity.github.io', version: 'v1alpha1',
|
|
10
|
+
namespaced: true, verbs: ['list', 'get'], isCrd: true,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function render(path: string, resources: APIResource[] = []) {
|
|
14
|
+
const client = new QueryClient({ defaultOptions: { queries: { retry: false, enabled: false } } })
|
|
15
|
+
client.setQueryData(['api-resources'], resources)
|
|
16
|
+
return renderToStaticMarkup(
|
|
17
|
+
<QueryClientProvider client={client}>
|
|
18
|
+
<MemoryRouter initialEntries={[path]}>
|
|
19
|
+
<ChecksViewTabs />
|
|
20
|
+
</MemoryRouter>
|
|
21
|
+
</QueryClientProvider>,
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
|
|
6
25
|
describe('ChecksViewTabs', () => {
|
|
7
26
|
it('keeps browsing scope across tabs without leaking upgrade-only target state', () => {
|
|
8
|
-
const html =
|
|
9
|
-
<MemoryRouter initialEntries={['/checks/upgrade?namespaces=shop%2Cprod&target=1.36&resource=shop%2Fapi']}>
|
|
10
|
-
<ChecksViewTabs />
|
|
11
|
-
</MemoryRouter>,
|
|
12
|
-
)
|
|
27
|
+
const html = render('/checks/upgrade?namespaces=shop%2Cprod&target=1.36&resource=shop%2Fapi')
|
|
13
28
|
|
|
14
29
|
expect(html).toContain('href="/checks?namespaces=shop%2Cprod"')
|
|
15
30
|
expect(html).toContain('href="/checks/upgrade?namespaces=shop%2Cprod&target=1.36"')
|
|
@@ -17,4 +32,17 @@ describe('ChecksViewTabs', () => {
|
|
|
17
32
|
expect(html).toContain('aria-current="page"')
|
|
18
33
|
expect(html).not.toContain('role="tab"')
|
|
19
34
|
})
|
|
35
|
+
|
|
36
|
+
it('shows Vulnerabilities only where the cluster serves VulnerabilityReports', () => {
|
|
37
|
+
expect(render('/checks')).not.toContain('Vulnerabilities')
|
|
38
|
+
|
|
39
|
+
const html = render('/checks?namespaces=shop', [vulnerabilityReports])
|
|
40
|
+
expect(html).toContain('href="/checks/vulnerabilities?namespaces=shop"')
|
|
41
|
+
expect(html).toContain('Vulnerabilities')
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('marks Vulnerabilities as the current tab on its route', () => {
|
|
45
|
+
const html = render('/checks/vulnerabilities', [vulnerabilityReports])
|
|
46
|
+
expect(html).toMatch(/aria-current="page"[^>]*href="\/checks\/vulnerabilities"|href="\/checks\/vulnerabilities"[^>]*aria-current="page"/)
|
|
47
|
+
})
|
|
20
48
|
})
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { clsx } from 'clsx'
|
|
2
2
|
import { Link, useLocation, type To } from 'react-router-dom'
|
|
3
|
+
import { useAPIResources } from '../../api/apiResources'
|
|
4
|
+
import { hasVulnerabilityReports } from '../../api/vulnerabilities'
|
|
3
5
|
|
|
4
6
|
export function ChecksViewTabs() {
|
|
5
7
|
const { pathname, search } = useLocation()
|
|
8
|
+
const { data: resources } = useAPIResources()
|
|
6
9
|
const upgrade = pathname.startsWith('/checks/upgrade')
|
|
10
|
+
const vulnerabilities = pathname.startsWith('/checks/vulnerabilities')
|
|
7
11
|
const current = new URLSearchParams(search)
|
|
8
12
|
const browsing = new URLSearchParams()
|
|
9
13
|
for (const key of ['namespace', 'namespaces']) {
|
|
@@ -16,12 +20,18 @@ export function ChecksViewTabs() {
|
|
|
16
20
|
|
|
17
21
|
return (
|
|
18
22
|
<nav className="flex items-center gap-1 border-b border-theme-border" aria-label="Check views">
|
|
19
|
-
<ChecksTab to={{ pathname: '/checks', search: browsing.toString() }} active={!upgrade}>
|
|
23
|
+
<ChecksTab to={{ pathname: '/checks', search: browsing.toString() }} active={!upgrade && !vulnerabilities}>
|
|
20
24
|
Best practices
|
|
21
25
|
</ChecksTab>
|
|
22
26
|
<ChecksTab to={{ pathname: '/checks/upgrade', search: upgradeSearch.toString() }} active={upgrade}>
|
|
23
27
|
Upgrade impact
|
|
24
28
|
</ChecksTab>
|
|
29
|
+
{/* Shown only where a scanner writes reports: the tab reads them, it doesn't scan. */}
|
|
30
|
+
{(vulnerabilities || hasVulnerabilityReports(resources)) && (
|
|
31
|
+
<ChecksTab to={{ pathname: '/checks/vulnerabilities', search: browsing.toString() }} active={vulnerabilities}>
|
|
32
|
+
Vulnerabilities
|
|
33
|
+
</ChecksTab>
|
|
34
|
+
)}
|
|
25
35
|
</nav>
|
|
26
36
|
)
|
|
27
37
|
}
|
|
@@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest'
|
|
|
2
2
|
import { renderToStaticMarkup } from 'react-dom/server'
|
|
3
3
|
import { ApiError } from '../../api/client'
|
|
4
4
|
import { RadarFeatureUnsupportedError } from '../../api/radarFeatures'
|
|
5
|
-
import { UPGRADE_IMPACT_DOCS_URL, UpgradeReadinessError, groupFindings, incompleteUpgradeCheckCount, issueSpecificReferences, summaryMeta, upgradeEvaluationSummary, upgradeEvidenceCoverageLabel, upgradeUnavailableKindsMessage } from './UpgradeReadinessView'
|
|
5
|
+
import { UPGRADE_IMPACT_DOCS_URL, UpgradePlansNotice, distributionUpgradePlans, planCountIsLowerBound, UpgradeReadinessError, groupFindings, incompleteUpgradeCheckCount, issueSpecificReferences, summaryMeta, upgradeEvaluationSummary, upgradeEvidenceCoverageLabel, upgradeUnavailableKindsMessage } from './UpgradeReadinessView'
|
|
6
6
|
|
|
7
7
|
describe('UpgradeReadinessError', () => {
|
|
8
8
|
it('maps an unsupported-feature error to the v1.9 upgrade message', () => {
|
|
@@ -160,3 +160,37 @@ describe('issueSpecificReferences', () => {
|
|
|
160
160
|
expect(issueSpecificReferences(checkReferences, findingReferences)).toEqual([findingReferences[1]])
|
|
161
161
|
})
|
|
162
162
|
})
|
|
163
|
+
|
|
164
|
+
describe('upgrade Plans notice', () => {
|
|
165
|
+
const plan = (name: string, image: string, conditions: any[] = []) => ({
|
|
166
|
+
apiVersion: 'upgrade.cattle.io/v1', kind: 'Plan', metadata: { name, namespace: 'system-upgrade' },
|
|
167
|
+
spec: { version: 'v1.32.1+k3s1', upgrade: { image } }, status: { conditions },
|
|
168
|
+
})
|
|
169
|
+
it('lists only k3s and rke2 upgrade Plans', () => {
|
|
170
|
+
expect(distributionUpgradePlans([
|
|
171
|
+
plan('k3s-server', 'rancher/k3s-upgrade', [{ type: 'Complete', status: 'True' }]),
|
|
172
|
+
plan('system-agent-upgrader', 'rancher/system-agent:v0.3.13-suc'),
|
|
173
|
+
])).toEqual([{ namespace: 'system-upgrade', name: 'k3s-server', version: 'v1.32.1+k3s1', state: 'Complete' }])
|
|
174
|
+
})
|
|
175
|
+
it('returns nothing for no Plans or an unread list', () => {
|
|
176
|
+
expect(distributionUpgradePlans(undefined)).toEqual([])
|
|
177
|
+
expect(distributionUpgradePlans([])).toEqual([])
|
|
178
|
+
})
|
|
179
|
+
it('renders the notice with a link per Plan', () => {
|
|
180
|
+
const html = renderToStaticMarkup(UpgradePlansNotice({ plans: [{ namespace: 'system-upgrade', name: 'k3s-server', version: 'v1.32.1+k3s1', state: 'Complete' }], onNavigateToResource: () => {} }))
|
|
181
|
+
expect(html).toContain('1 upgrade Plan is defined for this cluster')
|
|
182
|
+
expect(html).toContain('k3s-server')
|
|
183
|
+
expect(html).toContain('v1.32.1+k3s1')
|
|
184
|
+
})
|
|
185
|
+
it('says at least N when the caller could list only some Plans', () => {
|
|
186
|
+
const html = renderToStaticMarkup(UpgradePlansNotice({ partial: true, plans: [{ namespace: 'system-upgrade', name: 'k3s-server', version: 'v1', state: 'Complete' }], onNavigateToResource: () => {} }))
|
|
187
|
+
expect(html).toContain('At least 1 upgrade Plan is defined for this cluster')
|
|
188
|
+
})
|
|
189
|
+
it('counts Plans exactly only when the list covers the cluster', () => {
|
|
190
|
+
expect(planCountIsLowerBound({ status: 'complete' } as any)).toBe(false)
|
|
191
|
+
expect(planCountIsLowerBound({ status: 'partial' } as any)).toBe(true)
|
|
192
|
+
expect(planCountIsLowerBound({ status: 'complete', narrowedBy: ['namespace_collection'] } as any)).toBe(true)
|
|
193
|
+
expect(planCountIsLowerBound({ status: 'unknown' } as any)).toBe(true)
|
|
194
|
+
expect(planCountIsLowerBound(undefined)).toBe(true)
|
|
195
|
+
})
|
|
196
|
+
})
|