@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.
Files changed (152) hide show
  1. package/package.json +10 -9
  2. package/src/App.tsx +54 -10
  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.ts +129 -5
  7. package/src/api/namespaceScopeRetry.test.ts +14 -0
  8. package/src/api/radarFeatures.ts +7 -0
  9. package/src/api/substrateHealth.ts +134 -0
  10. package/src/api/velero.test.ts +60 -0
  11. package/src/api/velero.ts +201 -0
  12. package/src/api/vulnerabilities.ts +255 -0
  13. package/src/components/NamespaceSwitcher.tsx +3 -1
  14. package/src/components/audit/AuditView.tsx +4 -0
  15. package/src/components/audit/ChecksViewTabs.test.tsx +33 -5
  16. package/src/components/audit/ChecksViewTabs.tsx +11 -1
  17. package/src/components/audit/UpgradeReadinessView.test.ts +35 -1
  18. package/src/components/audit/UpgradeReadinessView.tsx +60 -2
  19. package/src/components/audit/VulnerabilitiesView.tsx +907 -0
  20. package/src/components/cnpg/CNPGClusterTabs.tsx +3 -1
  21. package/src/components/cnpg/CNPGDrawerTrail.tsx +5 -26
  22. package/src/components/cnpg/CNPGInvestigationAction.test.tsx +27 -6
  23. package/src/components/cnpg/CNPGView.tsx +43 -117
  24. package/src/components/cnpg/CNPGWorkspace.compatibility.test.tsx +30 -0
  25. package/src/components/cnpg/host.tsx +2 -2
  26. package/src/components/cnpg/routes.ts +3 -1
  27. package/src/components/cnpg/shared.tsx +5 -53
  28. package/src/components/cnpg/useCNPGNavigate.ts +1 -21
  29. package/src/components/cnpg/useCNPGSidebarWorkspace.ts +16 -13
  30. package/src/components/community.tsx +42 -0
  31. package/src/components/diagnose/diagnoseEvidenceTypes.ts +2 -0
  32. package/src/components/diagnose/investigationMetrics.test.ts +20 -0
  33. package/src/components/diagnose/investigationMetrics.ts +2 -1
  34. package/src/components/dock/BottomDock.tsx +1 -0
  35. package/src/components/dock/LogsTab.tsx +3 -0
  36. package/src/components/gitops/GitOpsView.tsx +1 -1
  37. package/src/components/helm/HelmDrawerFrame.tsx +1 -1
  38. package/src/components/helm/HelmView.tsx +20 -16
  39. package/src/components/helm/OwnedResources.tsx +4 -3
  40. package/src/components/home/ClusterHealthCard.tsx +3 -1
  41. package/src/components/home/HomeAgentBlock.tsx +3 -0
  42. package/src/components/home/HomeView.tsx +7 -0
  43. package/src/components/home/MCPSetupDialog.test.tsx +19 -12
  44. package/src/components/home/MCPSetupDialog.tsx +4 -2
  45. package/src/components/home/mcpToolCatalog.ts +15 -2
  46. package/src/components/home/useVulnerabilitiesRow.test.ts +26 -0
  47. package/src/components/home/useVulnerabilitiesRow.ts +50 -0
  48. package/src/components/logs/LogsViewer.tsx +3 -1
  49. package/src/components/logs/MultiPodLogsTab.test.tsx +24 -4
  50. package/src/components/logs/MultiPodLogsTab.tsx +9 -5
  51. package/src/components/nav/PrimaryNavRail.test.tsx +17 -0
  52. package/src/components/nav/PrimaryNavRail.tsx +174 -29
  53. package/src/components/resource/PrometheusChartsGrid.tsx +5 -1
  54. package/src/components/resource/SubstrateHealthCharts.test.tsx +143 -0
  55. package/src/components/resource/SubstrateHealthCharts.tsx +254 -0
  56. package/src/components/resource/SubstrateVerdictLine.test.tsx +131 -0
  57. package/src/components/resource/SubstrateVerdictLine.tsx +180 -0
  58. package/src/components/resources/ResourcesView.tsx +12 -6
  59. package/src/components/resources/renderers/UpgradePlanRenderer.test.tsx +20 -0
  60. package/src/components/resources/renderers/UpgradePlanRenderer.tsx +22 -0
  61. package/src/components/resources/renderers/VeleroBackupRenderer.tsx +16 -36
  62. package/src/components/resources/renderers/VeleroRestoreRenderer.tsx +6 -19
  63. package/src/components/resources/renderers/WorkloadRenderer.tsx +8 -0
  64. package/src/components/rightsizing/RightsizingScanView.tsx +3 -2
  65. package/src/components/shared/LargeClusterNamespacePicker.test.tsx +27 -0
  66. package/src/components/shared/LargeClusterNamespacePicker.tsx +8 -2
  67. package/src/components/timeline/TimelineView.tsx +3 -1
  68. package/src/components/traffic/TrafficConnectionsTable.test.tsx +94 -0
  69. package/src/components/traffic/TrafficConnectionsTable.tsx +21 -5
  70. package/src/components/traffic/TrafficData.test.tsx +37 -0
  71. package/src/components/traffic/TrafficData.tsx +27 -0
  72. package/src/components/traffic/TrafficFlowList.tsx +9 -7
  73. package/src/components/traffic/TrafficGraph.layoutEngine.test.tsx +193 -0
  74. package/src/components/traffic/TrafficGraph.test.tsx +269 -0
  75. package/src/components/traffic/TrafficGraph.tsx +135 -64
  76. package/src/components/traffic/TrafficGraphUnavailable.tsx +57 -0
  77. package/src/components/traffic/TrafficView.layoutUnavailable.test.tsx +211 -0
  78. package/src/components/traffic/TrafficView.tsx +46 -129
  79. package/src/components/traffic/trafficFilters.test.ts +172 -1
  80. package/src/components/traffic/trafficFilters.ts +139 -0
  81. package/src/components/ui/DiagnosticsOverlay.tsx +14 -1
  82. package/src/components/ui/UpdateNotification.manual.test.tsx +5 -2
  83. package/src/components/ui/UpdateNotification.test.tsx +31 -2
  84. package/src/components/ui/UpdateNotification.tsx +34 -17
  85. package/src/components/ui/command-items.ts +24 -1
  86. package/src/components/velero/VeleroBackupNow.test.tsx +165 -0
  87. package/src/components/velero/VeleroBackupNow.tsx +143 -0
  88. package/src/components/velero/VeleroDeleteBackup.test.tsx +364 -0
  89. package/src/components/velero/VeleroDeleteBackup.tsx +306 -0
  90. package/src/components/velero/VeleroDetailPage.tsx +148 -0
  91. package/src/components/velero/VeleroKindLists.test.tsx +48 -0
  92. package/src/components/velero/VeleroKindLists.tsx +43 -0
  93. package/src/components/velero/VeleroLocations.expand.test.tsx +27 -0
  94. package/src/components/velero/VeleroLocations.test.tsx +86 -0
  95. package/src/components/velero/VeleroLocations.tsx +240 -0
  96. package/src/components/velero/VeleroOverview.test.tsx +311 -0
  97. package/src/components/velero/VeleroOverview.tsx +485 -0
  98. package/src/components/velero/VeleroPages.test.tsx +516 -0
  99. package/src/components/velero/VeleroPages.tsx +1056 -0
  100. package/src/components/velero/VeleroRunLists.tsx +309 -0
  101. package/src/components/velero/VeleroRunMessagesHost.test.tsx +25 -0
  102. package/src/components/velero/VeleroRunMessagesHost.tsx +54 -0
  103. package/src/components/velero/VeleroScheduleStatusBadge.test.tsx +28 -0
  104. package/src/components/velero/VeleroScheduleStatusBadge.tsx +21 -0
  105. package/src/components/velero/VeleroSchedules.tsx +255 -0
  106. package/src/components/velero/VeleroView.tsx +59 -0
  107. package/src/components/velero/VeleroWorkspace.gate.test.tsx +97 -0
  108. package/src/components/velero/attention.test.ts +178 -0
  109. package/src/components/velero/attention.ts +281 -0
  110. package/src/components/velero/backupDelete.test.tsx +91 -0
  111. package/src/components/velero/backupDelete.tsx +182 -0
  112. package/src/components/velero/coverage.test.ts +87 -0
  113. package/src/components/velero/coverage.ts +150 -0
  114. package/src/components/velero/host.tsx +86 -0
  115. package/src/components/velero/routes.ts +78 -0
  116. package/src/components/velero/runs.tsx +121 -0
  117. package/src/components/velero/shared.test.ts +84 -0
  118. package/src/components/velero/shared.tsx +423 -0
  119. package/src/components/velero/useVeleroSidebarWorkspace.test.tsx +28 -0
  120. package/src/components/velero/useVeleroSidebarWorkspace.ts +71 -0
  121. package/src/components/velero/velero.fixtures.ts +61 -0
  122. package/src/components/velero/workspaceRoute.ts +21 -0
  123. package/src/components/vulnerabilities/WorkloadVulnerabilitiesSection.tsx +167 -0
  124. package/src/components/vulnerabilities/parts.test.ts +72 -0
  125. package/src/components/vulnerabilities/parts.tsx +291 -0
  126. package/src/components/workload/WorkloadView.tsx +64 -27
  127. package/src/components/workspace/DrawerTrailBack.tsx +32 -0
  128. package/src/components/workspace/WorkspaceFrame.tsx +71 -0
  129. package/src/components/workspace/coverage.ts +61 -0
  130. package/src/components/workspace/layout.test.tsx +29 -1
  131. package/src/components/workspace/layout.tsx +15 -5
  132. package/src/components/workspace/sidebar.ts +9 -0
  133. package/src/components/workspace/useWorkspaceDrawer.ts +63 -0
  134. package/src/components/workspace/useWorkspaceNavigate.ts +21 -0
  135. package/src/desktop/AboutDialog.test.ts +12 -0
  136. package/src/desktop/AboutDialog.tsx +151 -0
  137. package/src/desktop/WindowsTitleBar.tsx +359 -0
  138. package/src/desktop/titleBar.test.ts +61 -0
  139. package/src/desktop/titleBar.ts +45 -0
  140. package/src/index.css +19 -0
  141. package/src/integrations/resourceHost.ts +5 -1
  142. package/src/integrations/resourceHosts.test.tsx +14 -2
  143. package/src/integrations/resourceHosts.tsx +22 -6
  144. package/src/integrations/workspaceRoute.ts +1 -1
  145. package/src/integrations/workspaceRoutes.test.ts +11 -0
  146. package/src/integrations/workspaceRoutes.ts +3 -1
  147. package/src/integrations/workspaceScreens.tsx +2 -0
  148. package/src/main.tsx +8 -0
  149. package/src/utils/desktop-zoom.test.ts +53 -0
  150. package/src/utils/desktop-zoom.ts +30 -0
  151. package/src/utils/staleAssetPrompt.test.tsx +76 -0
  152. package/src/utils/staleAssetPrompt.tsx +32 -0
@@ -0,0 +1,255 @@
1
+ import {
2
+ Tooltip,
3
+ VELERO_NONE_KEPT,
4
+ VELERO_MANUAL_RUN,
5
+ VELERO_MANUAL_RUN_TITLE,
6
+ VELERO_NONE_KEPT_SHORT,
7
+ VELERO_RUNS_UNKNOWN,
8
+ VeleroRunPhase,
9
+ VeleroScheduleStateBadge,
10
+ VeleroZoneValue,
11
+ formatRelativeAgeTime,
12
+ veleroNextRunText,
13
+ veleroCadenceText,
14
+ veleroNextRunTitle,
15
+ veleroScheduleBadge,
16
+ veleroScheduleReasonText,
17
+ veleroLocalTime,
18
+ veleroDeclaredRetention,
19
+ type VeleroScheduleReading,
20
+ } from '@skyhook-io/k8s-ui'
21
+ import { useMemo } from 'react'
22
+ import { useMediaQuery } from '../../hooks/useMediaQuery'
23
+ import { ScreenBody, SectionTable, Sub, type TableColumn } from '../workspace/layout'
24
+ import { coverageEmpty } from '../workspace/coverage'
25
+ import { VELERO_WIDE, VeleroCoverageNotice, VeleroName, VeleroWorkspaceHeader, WholeNames, inInstallation, veleroResource, type VeleroScreenProps } from './shared'
26
+
27
+ /**
28
+ * The schedule's last run: the newest one Velero keeps, with the newest
29
+ * success when that run wasn't one; when the runs are not kept or not read,
30
+ * when Velero last submitted one.
31
+ */
32
+ function LastRunCell({ s, onInspect }: { s: VeleroScheduleReading; onInspect: VeleroScreenProps['onInspect'] }) {
33
+ const submitted = s.lastSubmitted ? (
34
+ <Tooltip content={veleroLocalTime(s.lastSubmitted)}>
35
+ <span>submitted {formatRelativeAgeTime(s.lastSubmitted)}</span>
36
+ </Tooltip>
37
+ ) : null
38
+ if (s.runs.read === 'unknown') {
39
+ return (
40
+ <>
41
+ {submitted ?? <span className="text-theme-text-tertiary">{VELERO_RUNS_UNKNOWN}</span>}
42
+ {submitted && <Sub>{VELERO_RUNS_UNKNOWN}</Sub>}
43
+ </>
44
+ )
45
+ }
46
+ const run = s.runs.newest
47
+ if (!run) {
48
+ if (!submitted) return <span className="text-theme-text-tertiary">Never</span>
49
+ return (
50
+ <>
51
+ {submitted}
52
+ <Sub><NoneKept /></Sub>
53
+ </>
54
+ )
55
+ }
56
+ const success = s.runs.newestCompleted
57
+ return (
58
+ <>
59
+ <button
60
+ type="button"
61
+ onClick={(e) => {
62
+ e.stopPropagation()
63
+ onInspect(veleroResource('Backup', s.namespace, run.name))
64
+ }}
65
+ aria-label={`Open backup ${run.name}`}
66
+ className="flex flex-wrap items-center gap-x-2 gap-y-0.5 text-left"
67
+ >
68
+ <VeleroRunPhase phase={run.phase} />
69
+ <Tooltip content={veleroLocalTime(run.ranAt)}>
70
+ <span className="text-xs text-theme-text-tertiary">{formatRelativeAgeTime(run.ranAt)}</span>
71
+ </Tooltip>
72
+ {run.manual && <ManualMark />}
73
+ </button>
74
+ {success?.name !== run.name && (
75
+ <Sub>
76
+ {success ? (
77
+ <Tooltip content={veleroLocalTime(success.completed ?? success.ranAt)}>
78
+ <span>last success {formatRelativeAgeTime(success.completed ?? success.ranAt)}{success.manual ? `, ${VELERO_MANUAL_RUN}` : ''}</span>
79
+ </Tooltip>
80
+ ) : (
81
+ 'no success kept'
82
+ )}
83
+ </Sub>
84
+ )}
85
+ </>
86
+ )
87
+ }
88
+
89
+ function ManualMark() {
90
+ return (
91
+ <Tooltip content={VELERO_MANUAL_RUN_TITLE}>
92
+ <span className="text-xs text-theme-text-secondary">{VELERO_MANUAL_RUN}</span>
93
+ </Tooltip>
94
+ )
95
+ }
96
+
97
+ function NoneKept() {
98
+ return (
99
+ <Tooltip content={VELERO_NONE_KEPT}>
100
+ <span className="text-theme-text-tertiary">{VELERO_NONE_KEPT_SHORT}</span>
101
+ </Tooltip>
102
+ )
103
+ }
104
+
105
+ /** The zone every schedule's cron is read in, when they share one Radar is sure of. */
106
+ function sharedZone(schedules: VeleroScheduleReading[]): string | null {
107
+ const names = new Set(schedules.map((s) => (s.zone.source === 'inferred' || s.zone.source === 'unknown' ? '\u0000' : s.zone.name)))
108
+ return names.size === 1 && !names.has('\u0000') ? [...names][0] : null
109
+ }
110
+
111
+ function LocationCell({ s }: { s: VeleroScheduleReading }) {
112
+ if (!s.location.viaDefault) return <VeleroName name={s.location.name ?? ''} />
113
+ return (
114
+ <>
115
+ {s.location.name ? <VeleroName name={s.location.name} /> : <span className="text-theme-text-tertiary">Unresolved</span>}
116
+ <Tooltip content="The schedule names no location, so its backups go to the installation’s default.">
117
+ <Sub>the default; not set on the schedule</Sub>
118
+ </Tooltip>
119
+ </>
120
+ )
121
+ }
122
+
123
+ const SERVER_DEFAULT_TTL = 'The schedule sets no retention, so the Velero server’s default applies (30 days unless it was changed).'
124
+
125
+ /** How long each run is kept: the schedule's own setting, else the server's default. */
126
+ export function KeptForCell({ s }: { s: VeleroScheduleReading }) {
127
+ const kept = veleroDeclaredRetention(s.ttl)
128
+ if (kept) return <>{kept}</>
129
+ return (
130
+ <Tooltip content={SERVER_DEFAULT_TTL}>
131
+ <span className="text-theme-text-secondary">server default</span>
132
+ </Tooltip>
133
+ )
134
+ }
135
+
136
+ /** KeptForCell as a line under where the runs are stored, for a narrow table. */
137
+ export function KeptForLine({ s }: { s: VeleroScheduleReading }) {
138
+ const kept = veleroDeclaredRetention(s.ttl)
139
+ if (kept) return <Sub>kept for {kept}</Sub>
140
+ return (
141
+ <Sub>
142
+ <Tooltip content={SERVER_DEFAULT_TTL}>
143
+ <span>kept for the server’s default</span>
144
+ </Tooltip>
145
+ </Sub>
146
+ )
147
+ }
148
+
149
+ export const KEPT_FOR_HEADER = (
150
+ <Tooltip content="The schedule’s setting: how long Velero keeps each run (spec.template.ttl).">
151
+ <span>Kept for</span>
152
+ </Tooltip>
153
+ )
154
+
155
+ /** Due within its grace reads on schedule (see veleroScheduleBadge), so its next run reads "due now", not "was due". */
156
+ export function NextRunCell({ s }: { s: VeleroScheduleReading }) {
157
+ if (!s.nextRun) return <span className="text-theme-text-tertiary">—</span>
158
+ const dueNow = s.state === 'due' && s.reason !== 'serverDown'
159
+ return (
160
+ <>
161
+ <Tooltip content={veleroNextRunTitle(s)}>
162
+ <span>{dueNow ? 'due now' : veleroNextRunText(s)}</span>
163
+ </Tooltip>
164
+ <Sub>{veleroLocalTime(s.nextRun)}</Sub>
165
+ </>
166
+ )
167
+ }
168
+
169
+ /**
170
+ * Every schedule read against Velero's controller rules: its state, next run
171
+ * and last run. The Velero Schedule kind's list.
172
+ */
173
+ export function VeleroSchedules({ data, installation, onInstallation, onInspect, inspected }: VeleroScreenProps) {
174
+ const multi = data.installations.length > 1
175
+ const schedules = useMemo(() => inInstallation(data.schedules, installation), [data.schedules, installation])
176
+ const zone = sharedZone(schedules)
177
+ const wide = useMediaQuery(VELERO_WIDE)
178
+
179
+ const runs = (s: VeleroScheduleReading, under: boolean) => {
180
+ const cadence = veleroCadenceText(s.cron)
181
+ const lead = cadence ? <span>{cadence}</span> : <span className="font-mono text-sm">{s.cron}</span>
182
+ return (
183
+ <>
184
+ {under ? (
185
+ <Sub>
186
+ {cadence ?? <span className="font-mono">{s.cron}</span>}
187
+ {zone && ` (${zone})`}
188
+ </Sub>
189
+ ) : (
190
+ lead
191
+ )}
192
+ {cadence && <div className="mt-0.5 font-mono text-xs text-theme-text-tertiary">{s.cron}</div>}
193
+ {!zone && <Sub><VeleroZoneValue zone={s.zone} /></Sub>}
194
+ </>
195
+ )
196
+ }
197
+
198
+ // Narrow: the cadence goes under the schedule's name, and the retention under where it stores.
199
+ const columns: TableColumn<VeleroScheduleReading>[] = [
200
+ {
201
+ header: 'Schedule',
202
+ width: wide ? '18%' : '24%',
203
+ cell: (s) => (
204
+ <>
205
+ <VeleroName name={s.name} />
206
+ {multi && <Sub><WholeNames text={s.namespace} /></Sub>}
207
+ {!wide && runs(s, true)}
208
+ </>
209
+ ),
210
+ },
211
+ ...(wide ? [{ header: zone ? `Runs (${zone})` : 'Runs', width: '15%', cell: (s: VeleroScheduleReading) => runs(s, false) }] : []),
212
+ {
213
+ header: 'State',
214
+ width: wide ? '12%' : '17%',
215
+ cell: (s) => (
216
+ <Tooltip content={veleroScheduleBadge(s).detail ?? veleroScheduleReasonText(s)}>
217
+ <VeleroScheduleStateBadge reading={s} />
218
+ </Tooltip>
219
+ ),
220
+ },
221
+ { header: 'Next run', width: wide ? '12%' : '16%', cell: (s) => <NextRunCell s={s} /> },
222
+ { header: 'Last run', width: wide ? '17%' : '23%', cell: (s) => <LastRunCell s={s} onInspect={onInspect} /> },
223
+ {
224
+ header: 'Stored in',
225
+ width: wide ? '15%' : '20%',
226
+ cell: (s) => (
227
+ <>
228
+ <LocationCell s={s} />
229
+ {!wide && <KeptForLine s={s} />}
230
+ </>
231
+ ),
232
+ },
233
+ ...(wide ? [{ header: KEPT_FOR_HEADER, width: '11%', cell: (s: VeleroScheduleReading) => <KeptForCell s={s} /> }] : []),
234
+ ]
235
+
236
+ return (
237
+ <div className="flex min-h-0 flex-1 flex-col">
238
+ <VeleroWorkspaceHeader title="Schedules" data={data} installation={installation} onInstallation={onInstallation} />
239
+ <ScreenBody>
240
+ <VeleroCoverageNotice data={data} kinds={['schedules', 'backups']} />
241
+ <SectionTable
242
+ subtitle={`${schedules.length} ${schedules.length === 1 ? 'schedule' : 'schedules'}`}
243
+ columns={columns}
244
+ rows={schedules}
245
+ rowKey={(s) => `${s.namespace}/${s.name}`}
246
+ rowResource={(s) => veleroResource('Schedule', s.namespace, s.name)}
247
+ onInspect={onInspect}
248
+ inspected={inspected}
249
+ empty={coverageEmpty(data.coverage.schedules, 'Velero schedules')}
250
+ minWidth={wide ? 980 : 600}
251
+ />
252
+ </ScreenBody>
253
+ </div>
254
+ )
255
+ }
@@ -0,0 +1,59 @@
1
+ import { useMemo } from 'react'
2
+ import { useLocation } from 'react-router-dom'
3
+ import type { WorkspaceScreenProps } from '../../integrations/workspaceRoute'
4
+ import { useAPIResources } from '../../api/apiResources'
5
+ import { useVeleroWorkspace } from '../../api/velero'
6
+ import { useNamespaces, useRadarFeature } from '../../api/client'
7
+ import { useMediaQuery } from '../../hooks/useMediaQuery'
8
+ import { useCNPGSidebarWorkspace } from '../cnpg/useCNPGSidebarWorkspace'
9
+ import { WorkspaceFrame } from '../workspace/WorkspaceFrame'
10
+ import { useMergedSidebarWorkspaces } from '../workspace/sidebar'
11
+ import { useWorkspaceDrawer } from '../workspace/useWorkspaceDrawer'
12
+ import { VeleroScreenGate, useVeleroInstallation } from './shared'
13
+ import { VeleroOverview } from './VeleroOverview'
14
+ import { useVeleroSidebarWorkspace, veleroDiscovered } from './useVeleroSidebarWorkspace'
15
+ import { VELERO_DETAIL_KINDS, VELERO_GROUP, parseVeleroRoute } from './routes'
16
+ import { VeleroDetailPage } from './VeleroDetailPage'
17
+
18
+ /**
19
+ * The Velero Overview, and each Velero object's page. Lives inside Resources and renders the same Resources
20
+ * sidebar, with the Overview above the Velero kinds; the Schedule,
21
+ * BackupStorageLocation, Backup and Restore kinds' lists are Radar's own
22
+ * tables (VeleroKindLists).
23
+ * It reads every installation the caller can see; the namespace picker does
24
+ * not apply.
25
+ */
26
+ export function VeleroView({ namespaces, selectedResource, onOpenResource, onCloseResource }: WorkspaceScreenProps) {
27
+ const { detail } = parseVeleroRoute(useLocation().pathname)
28
+ const narrow = useMediaQuery('(max-width: 1100px)')
29
+ const laptop = useMediaQuery('(max-width: 1300px)')
30
+ const compactNavigation = narrow || (laptop && !!detail)
31
+ const deleteObject = useRadarFeature('resourceDeletePreconditions').support === 'supported'
32
+ const { data: apiResources, isPending: discoveryPending, isError: discoveryFailed } = useAPIResources()
33
+ // Discovery that could not be read does not say Velero is absent; the server is asked then.
34
+ const discovered = veleroDiscovered(apiResources) || discoveryFailed
35
+ const query = useVeleroWorkspace({ enabled: discovered })
36
+ // An object's page highlights its kind's row; the Overview row only the Overview.
37
+ const veleroSidebar = useVeleroSidebarWorkspace({ apiResources, active: !detail })
38
+ const plural = detail?.plural
39
+ const selectedKind = useMemo(() => (plural ? { name: plural, kind: VELERO_DETAIL_KINDS[plural].kind, group: VELERO_GROUP } : null), [plural])
40
+ const cnpgSidebar = useCNPGSidebarWorkspace({ apiResources, namespaces })
41
+ const sidebarWorkspace = useMergedSidebarWorkspaces(cnpgSidebar, veleroSidebar)
42
+ const { drawerTarget, inspect } = useWorkspaceDrawer({ selectedResource, onOpenResource, onCloseResource })
43
+
44
+ const [installation, setInstallation] = useVeleroInstallation(query.data?.installations)
45
+ const namespaceList = useNamespaces()
46
+ const namespaceNames = useMemo(() => (namespaceList.isError ? 'error' as const : namespaceList.data?.map((n) => n.name)), [namespaceList.isError, namespaceList.data])
47
+
48
+ return (
49
+ <WorkspaceFrame namespaces={namespaces} categoryWorkspaces={sidebarWorkspace} selectedKind={selectedKind} compactNavigation={compactNavigation}>
50
+ {detail ? (
51
+ <VeleroDetailPage target={detail} onOpenResource={onOpenResource} />
52
+ ) : (
53
+ <VeleroScreenGate query={query} discoveryPending={discoveryPending} discovered={discovered}>
54
+ {(data) => <VeleroOverview data={data} installation={installation} onInstallation={setInstallation} onInspect={inspect} inspected={drawerTarget} namespaces={namespaceNames} deleteObject={deleteObject} />}
55
+ </VeleroScreenGate>
56
+ )}
57
+ </WorkspaceFrame>
58
+ )
59
+ }
@@ -0,0 +1,97 @@
1
+ // @vitest-environment jsdom
2
+ import { act, type ComponentProps } from 'react'
3
+ import { createRoot } from 'react-dom/client'
4
+ import { renderToStaticMarkup } from 'react-dom/server'
5
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
6
+ import { afterEach, describe, expect, it, vi } from 'vitest'
7
+ import { RadarFeatureUnsupportedError, guardRadarFeature, type RadarFeatureSupport } from '../../api/radarFeatures'
8
+ import { workspace } from './velero.fixtures'
9
+
10
+ const state = vi.hoisted(() => ({ support: 'supported' as RadarFeatureSupport, fetches: [] as string[] }))
11
+
12
+ vi.mock('../../api/client', () => ({
13
+ useRadarFeature: () => ({
14
+ support: state.support,
15
+ guard: <T,>(request: () => Promise<T>) => guardRadarFeature('veleroWorkspace', state.support, { currentVersion: 'v1.16.0' }, request),
16
+ gatedKey: state.support === 'unsupported' ? ['radar-feature-unsupported'] : [],
17
+ }),
18
+ fetchJSON: async (path: string) => {
19
+ state.fetches.push(path)
20
+ const { workspace: build } = await import('./velero.fixtures')
21
+ return build()
22
+ },
23
+ }))
24
+ vi.mock('../../context/ConnectionContext', () => ({ useConnection: () => ({ connection: { context: 'kind-demo' } }) }))
25
+
26
+ import { useVeleroWorkspace } from '../../api/velero'
27
+ import { VeleroScreenGate } from './shared'
28
+
29
+ async function settle(done: () => boolean) {
30
+ for (let i = 0; i < 50 && !done(); i++) {
31
+ await act(async () => { await new Promise((r) => setTimeout(r, 10)) })
32
+ }
33
+ }
34
+
35
+ afterEach(() => {
36
+ state.support = 'supported'
37
+ state.fetches = []
38
+ })
39
+
40
+ type GateQuery = ComponentProps<typeof VeleroScreenGate>['query']
41
+ const ready: GateQuery = { data: undefined, error: null, isLoading: false, isFetching: false, refetch: vi.fn(), isRefetchError: false, dataUpdatedAt: 0 }
42
+
43
+ function gate(query: Partial<GateQuery>, opts = { discoveryPending: false, discovered: true }) {
44
+ return renderToStaticMarkup(
45
+ <VeleroScreenGate query={{ ...ready, ...query }} discoveryPending={opts.discoveryPending} discovered={opts.discovered}>
46
+ {() => <div>screen</div>}
47
+ </VeleroScreenGate>,
48
+ )
49
+ }
50
+
51
+ describe('Velero screen gate', () => {
52
+ it('shows the upgrade note, not an error, on a Radar that predates the views', () => {
53
+ const html = gate({ error: new RadarFeatureUnsupportedError('veleroWorkspace', { currentVersion: 'v1.16.0' }) })
54
+ expect(html).toContain('Velero needs a newer Radar on this cluster')
55
+ expect(html).toContain('This cluster runs v1.16.')
56
+ expect(html).not.toContain('Velero data unavailable')
57
+ })
58
+
59
+ it('offers a retry for a failed read, and says when Velero is not installed', () => {
60
+ expect(gate({ error: new Error('boom') })).toContain('Retry')
61
+ expect(gate({ data: workspace({ installed: false }) })).toContain('Velero is not installed')
62
+ expect(gate({}, { discoveryPending: false, discovered: false })).toContain('Velero is not installed')
63
+ expect(gate({}, { discoveryPending: true, discovered: false })).toContain('Loading Velero')
64
+ expect(gate({ data: workspace() })).toContain('screen')
65
+ })
66
+ })
67
+
68
+ describe('useVeleroWorkspace', () => {
69
+ it('stops asking a Radar once it is known to predate the views, on a shared query client', async () => {
70
+ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
71
+ const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })
72
+ const seen: { data?: unknown; error?: unknown }[] = []
73
+ function Probe() {
74
+ const q = useVeleroWorkspace()
75
+ seen.push({ data: q.data, error: q.error })
76
+ return null
77
+ }
78
+ const root = createRoot(document.createElement('div'))
79
+ await act(async () => {
80
+ root.render(<QueryClientProvider client={queryClient}><Probe /></QueryClientProvider>)
81
+ })
82
+ await settle(() => !!seen.at(-1)?.data)
83
+ expect(state.fetches).toEqual(['/velero/workspace'])
84
+ expect(seen.at(-1)?.data).toBeTruthy()
85
+
86
+ state.support = 'unsupported'
87
+ await act(async () => {
88
+ root.render(<QueryClientProvider client={queryClient}><Probe key="after" /></QueryClientProvider>)
89
+ })
90
+ await settle(() => !!seen.at(-1)?.error)
91
+ expect(state.fetches).toEqual(['/velero/workspace'])
92
+ expect(seen.at(-1)?.error).toBeInstanceOf(RadarFeatureUnsupportedError)
93
+ // The previous cluster answer is not kept as a placeholder once the gate decides.
94
+ expect(seen.at(-1)?.data).toBeUndefined()
95
+ root.unmount()
96
+ })
97
+ })
@@ -0,0 +1,178 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import type { VeleroIssue } from '@skyhook-io/k8s-ui'
3
+ import { veleroAttention, veleroAttentionCount, veleroScreenCounts } from './attention'
4
+ import { veleroKindListMode } from './routes'
5
+ import { location, schedule, workspace } from './velero.fixtures'
6
+
7
+ const issue = (kind: string, name: string): VeleroIssue => ({
8
+ id: `${kind}/${name}`, severity: 'critical', category: 'backup_target_unavailable', kind, group: 'velero.io', namespace: 'velero', name, reason: 'BackupStorageLocationUnavailable',
9
+ })
10
+
11
+ // The sidebar badge counts what the Overview lists, so it never promises a
12
+ // problem the screen does not show, or hides one it does.
13
+ describe('the Velero Overview badge', () => {
14
+ it('counts what Needs attention lists', () => {
15
+ const data = workspace({
16
+ schedules: [schedule({ name: 'late', state: 'late', attention: true }), schedule()],
17
+ locations: [location({ name: 'dr', attention: true })],
18
+ issues: [issue('BackupStorageLocation', 'dr'), issue('Backup', 'nightly-1')],
19
+ issueTotals: { velero: 2 },
20
+ })
21
+ expect(veleroAttention(data, null)).toHaveLength(4)
22
+ expect(veleroAttentionCount(data)).toMatchObject({ count: 4, lowerBound: false })
23
+ })
24
+
25
+ it('names a server with backups disabled once, for the schedules that are not paused, folding their held runs', () => {
26
+ const server = { ...workspace().installations[0].server, deployment: 'velero', backupsDisabled: true }
27
+ const data = workspace({
28
+ installations: [{ ...workspace().installations[0], server }],
29
+ schedules: [schedule({ name: 'nightly', state: 'held', reason: 'unstartedBlocker', attention: true }), schedule({ name: 'weekly', state: 'paused' })],
30
+ })
31
+ const rows = veleroAttention(data, null)
32
+ expect(rows).toHaveLength(1)
33
+ expect(rows[0]).toMatchObject({ id: 'backups-disabled:velero', title: 'Velero backups disabled', tone: 'unhealthy', subject: { kind: 'Deployment', name: 'velero' } })
34
+ expect(rows[0].detail).toContain('schedule nightly backs up nothing')
35
+ const allPaused = workspace({ installations: data.installations, schedules: [schedule({ name: 'weekly', state: 'paused' })] })
36
+ expect(veleroAttention(allPaused, null)).toHaveLength(0)
37
+ })
38
+
39
+ it('reads zero as unknown while the server Deployment is unread', () => {
40
+ const unread = workspace({ installations: [{ ...workspace().installations[0], server: { source: 'unread' } }] })
41
+ expect(veleroAttentionCount(unread)).toMatchObject({ count: null, lowerBound: true })
42
+ })
43
+
44
+ // A stopped server would fold the late ones into one row, disabled backups the held ones.
45
+ it('keeps its lower bound under what the rows become once the server is read', () => {
46
+ const held = (name: string) => schedule({ name, state: 'held', reason: 'unstartedBlocker', attention: true })
47
+ const unread = workspace({
48
+ installations: [{ ...workspace().installations[0], server: { source: 'unread' } }],
49
+ schedules: [held('a'), held('b'), held('c'), schedule({ name: 'late', state: 'late', attention: true })],
50
+ })
51
+ expect(veleroAttention(unread, null)).toHaveLength(4)
52
+ expect(veleroAttentionCount(unread)).toMatchObject({ count: 2, lowerBound: true })
53
+ const disabled = workspace({ installations: [{ ...workspace().installations[0], server: { source: 'deployment', backupsDisabled: true } }], schedules: unread.schedules })
54
+ expect(veleroAttention(disabled, null).length).toBeGreaterThanOrEqual(2)
55
+ })
56
+
57
+ it('reads zero as none only when everything was read', () => {
58
+ expect(veleroAttentionCount(workspace())).toMatchObject({ count: 0, lowerBound: false })
59
+ const partial = workspace({ coverage: { ...workspace().coverage, backups: { state: 'partial' } as any } })
60
+ expect(veleroAttentionCount(partial)).toMatchObject({ count: null, lowerBound: true })
61
+ })
62
+
63
+ it('gives each list the rows about its kind, so the lists add up to the total', () => {
64
+ const data = workspace({
65
+ schedules: [schedule({ name: 'late', state: 'late', attention: true }), schedule()],
66
+ locations: [location({ name: 'dr', attention: true })],
67
+ issues: [issue('BackupStorageLocation', 'dr'), issue('Backup', 'nightly-1')],
68
+ issueTotals: { velero: 2 },
69
+ })
70
+ const screens = veleroScreenCounts(data)
71
+ expect(Object.fromEntries(Object.entries(screens).map(([k, v]) => [k, v.count]))).toEqual({ backups: 1, schedules: 1, restores: 0, backupstoragelocations: 2 })
72
+ expect(screens.schedules.title).toBe('1 schedule needs attention.')
73
+ const partial = veleroScreenCounts(workspace({ coverage: { ...workspace().coverage, restores: { state: 'partial' } as any } }))
74
+ expect(partial.restores).toMatchObject({ count: null, lowerBound: true })
75
+ expect(partial.backups).toMatchObject({ count: 0, lowerBound: false })
76
+ })
77
+
78
+ it('counts issues the server capped from the total it sends', () => {
79
+ const data = workspace({ issues: [issue('Backup', 'a')], issueTotals: { velero: 7 } })
80
+ expect(veleroAttentionCount(data)).toMatchObject({ count: 7, lowerBound: false })
81
+ })
82
+
83
+ it('gives each list a lower bound while the server capped issues, since those may be about any kind', () => {
84
+ const screens = veleroScreenCounts(workspace({ issues: [issue('Backup', 'a')], issueTotals: { velero: 7 } }))
85
+ expect(screens.backups).toMatchObject({ count: 1, lowerBound: true })
86
+ expect(screens.backups.title).toContain('there may be more')
87
+ expect(screens.schedules).toMatchObject({ count: null, lowerBound: true })
88
+ })
89
+ })
90
+
91
+ // One fault is one row, as on the Issues page: the stopped server's row names
92
+ // the schedules it left late, and storage it left unchecked is not listed.
93
+ describe('a stopped Velero server on the Overview', () => {
94
+ const stopped = { ...workspace().installations[0], server: { ...workspace().installations[0].server, replicas: 0, deployment: 'velero' } }
95
+ const late = (name: string) => schedule({ name, state: 'late', attention: true, reason: 'serverDown' })
96
+
97
+ it('is one row naming the schedules it left late, without the storage it left unchecked', () => {
98
+ const rows = veleroAttention(workspace({
99
+ installations: [stopped],
100
+ schedules: [late('late')],
101
+ locations: [location({ attention: true, validationOverdue: true, reason: 'serverDown' })],
102
+ }), null)
103
+ expect(rows.map((r) => r.category)).toEqual(['server'])
104
+ expect(rows[0].detail).toContain('1 schedule has missed runs: late.')
105
+ })
106
+
107
+ it('stays one row for a hundred schedules', () => {
108
+ const rows = veleroAttention(workspace({ installations: [stopped], schedules: Array.from({ length: 100 }, (_, i) => late(`s${i}`)) }), null)
109
+ expect(rows).toHaveLength(1)
110
+ expect(rows[0].detail).toContain('100 schedules have missed runs: s0, s1, s2 and 97 more.')
111
+ })
112
+
113
+ it('keeps a schedule wrong for another reason as its own row', () => {
114
+ const rows = veleroAttention(workspace({ installations: [stopped], schedules: [late('late'), schedule({ name: 'long', state: 'cannotRun', attention: true })] }), null)
115
+ expect(rows.map((r) => r.subject?.name)).toEqual(['velero', 'long'])
116
+ })
117
+ })
118
+
119
+ describe('an unavailable storage location on the Overview', () => {
120
+ it('names the runs Velero rejected because of it, each one a link', () => {
121
+ const data = workspace({
122
+ issues: [{ ...issue('BackupStorageLocation', 'dr'), message: 'bucket not found', affected: [{ kind: 'Backup', name: 'a-1' }, { kind: 'Backup', name: 'b-1' }] }],
123
+ issueTotals: { velero: 1 },
124
+ })
125
+ const [row] = veleroAttention(data, null)
126
+ expect(row.detail).toBe('bucket not found.')
127
+ expect(row.related?.lead).toBe('Velero rejected 2 runs because of it:')
128
+ expect(row.related?.refs).toEqual([
129
+ { kind: 'Backup', group: 'velero.io', namespace: 'velero', name: 'a-1' },
130
+ { kind: 'Backup', group: 'velero.io', namespace: 'velero', name: 'b-1' },
131
+ ])
132
+ })
133
+ })
134
+
135
+ describe('the Velero Schedule and BackupStorageLocation kind lists', () => {
136
+ it("are Radar's own tables when this Radar serves them, and the generic table otherwise", () => {
137
+ expect(veleroKindListMode('supported', false)).toBe('view')
138
+ expect(veleroKindListMode('unknown', true)).toBe('wait')
139
+ expect(veleroKindListMode('unknown', false)).toBe('table')
140
+ expect(veleroKindListMode('unsupported', false)).toBe('table')
141
+ })
142
+ })
143
+
144
+ describe('Velero next steps', () => {
145
+ it('says what to do about every Issue reason and every attention state', async () => {
146
+ const { veleroIssueNextStep } = await import('./shared')
147
+ const { veleroScheduleNextStep } = await import('./attention')
148
+ for (const reason of ['BackupFailed', 'BackupPartiallyFailed', 'BackupValidationFailed', 'RestoreFailed', 'RestorePartiallyFailed', 'RestoreValidationFailed', 'ScheduleValidationFailed', 'BackupStorageLocationUnavailable', 'BackupRepositoryNotReady', 'BackupRepositoryMaintenanceFailed', 'VeleroRunStalled', 'VeleroServerNotRunning', 'VeleroScheduleLate', 'VeleroScheduleCannotRun', 'VeleroScheduleHeld', 'VeleroScheduleNotValidated', 'VeleroLocationValidationOverdue']) {
149
+ expect(veleroIssueNextStep({ reason }), reason).toBeTruthy()
150
+ }
151
+ expect(veleroIssueNextStep({ reason: 'BackupFailed', message: 'found a backup with status "InProgress" during the server starting, mark it as "Failed"' })).toBe('Run the backup again')
152
+ expect(veleroIssueNextStep({ reason: 'BackupFailed', action: 'Do the thing' })).toBe('Do the thing')
153
+ expect(veleroIssueNextStep({ reason: 'VeleroScheduleCannotRun', message: "This schedule's name is longer than 63 characters" })).toBe('Recreate the schedule with a name of 63 characters or fewer')
154
+ for (const state of ['cannotRun', 'alwaysDue', 'rejected', 'held', 'late', 'probablyLate', 'lateOrHeld', 'notValidated'] as const) {
155
+ expect(veleroScheduleNextStep({ state }), state).toBeTruthy()
156
+ }
157
+ expect(veleroScheduleNextStep({ state: 'late', reason: 'serverDown' })).toContain('Start the Velero server')
158
+ expect(veleroScheduleNextStep({ state: 'held' })).toContain('backup controller enabled')
159
+ // Delete object is offered only for a queued run Velero never gave a location.
160
+ const queued = { name: 'nightly-20261119010000', phase: 'New', created: '', ranAt: '' }
161
+ expect(veleroScheduleNextStep({ state: 'held', blocker: queued }, { deleteObject: true })).toContain('or open the queued backup and use Delete object: nothing of it is in storage')
162
+ expect(veleroScheduleNextStep({ state: 'held', blocker: { ...queued, storageLocation: 'default' } }, { deleteObject: true })).not.toContain('Delete object')
163
+ // A Radar without Delete object, or one that doesn't report runs' locations, gets the plain step.
164
+ expect(veleroScheduleNextStep({ state: 'held', blocker: queued })).not.toContain('Delete object')
165
+ expect(veleroIssueNextStep({ reason: 'VeleroScheduleHeld' })).toBe(veleroScheduleNextStep({ state: 'held' }))
166
+ })
167
+ })
168
+
169
+ describe('a schedule held by a backup Velero never stored', () => {
170
+ it('links the queued backup, and offers Delete object only where that Radar supports it', () => {
171
+ const blocker = { name: 'nightly-20261119010000', phase: 'New', created: '', ranAt: '' }
172
+ const data = workspace({ schedules: [schedule({ name: 'nightly', state: 'held', reason: 'unstartedBlocker', attention: true, blocker })] })
173
+ const rows = veleroAttention(data, null, { deleteObject: true })
174
+ expect(rows[0].related).toEqual({ lead: 'Queued backup:', refs: [{ kind: 'Backup', group: 'velero.io', namespace: 'velero', name: 'nightly-20261119010000' }] })
175
+ expect(rows[0].nextStep).toContain('Delete object')
176
+ expect(veleroAttention(data, null)[0].nextStep).not.toContain('Delete object')
177
+ })
178
+ })