@skyhook-io/radar-app 1.20.3 → 1.21.1

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 (167) hide show
  1. package/package.json +10 -9
  2. package/src/App.tsx +67 -15
  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 +11 -0
  9. package/src/api/substrateHealth.ts +134 -0
  10. package/src/api/velero.test.ts +60 -0
  11. package/src/api/velero.ts +377 -0
  12. package/src/api/vulnerabilities.ts +313 -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 +35 -5
  16. package/src/components/audit/ChecksViewTabs.tsx +12 -1
  17. package/src/components/audit/Java4ShellPanel.test.tsx +31 -0
  18. package/src/components/audit/Java4ShellPanel.tsx +313 -0
  19. package/src/components/audit/UpgradeReadinessView.test.ts +35 -1
  20. package/src/components/audit/UpgradeReadinessView.tsx +60 -2
  21. package/src/components/audit/VulnerabilitiesView.tsx +944 -0
  22. package/src/components/cnpg/CNPGClusterTabs.tsx +3 -1
  23. package/src/components/cnpg/CNPGDrawerTrail.tsx +5 -26
  24. package/src/components/cnpg/CNPGInvestigationAction.test.tsx +27 -6
  25. package/src/components/cnpg/CNPGView.tsx +43 -117
  26. package/src/components/cnpg/CNPGWorkspace.compatibility.test.tsx +30 -0
  27. package/src/components/cnpg/host.tsx +2 -2
  28. package/src/components/cnpg/routes.ts +3 -1
  29. package/src/components/cnpg/shared.tsx +5 -53
  30. package/src/components/cnpg/useCNPGNavigate.ts +1 -21
  31. package/src/components/cnpg/useCNPGSidebarWorkspace.ts +16 -13
  32. package/src/components/community.tsx +42 -0
  33. package/src/components/diagnose/diagnoseEvidenceTypes.ts +2 -0
  34. package/src/components/diagnose/investigationMetrics.test.ts +20 -0
  35. package/src/components/diagnose/investigationMetrics.ts +2 -1
  36. package/src/components/dock/BottomDock.tsx +1 -0
  37. package/src/components/dock/LogsTab.tsx +3 -0
  38. package/src/components/gitops/FluxOperatorCard.test.tsx +37 -0
  39. package/src/components/gitops/FluxOperatorCard.tsx +27 -0
  40. package/src/components/gitops/GitOpsView.rowsSummary.test.tsx +59 -0
  41. package/src/components/gitops/GitOpsView.tsx +8 -5
  42. package/src/components/gitops/gitopsRowEvents.test.ts +48 -0
  43. package/src/components/gitops/gitopsRowEvents.ts +31 -0
  44. package/src/components/helm/HelmDrawerFrame.tsx +1 -1
  45. package/src/components/helm/HelmView.tsx +20 -16
  46. package/src/components/helm/OwnedResources.tsx +4 -3
  47. package/src/components/home/ClusterHealthCard.tsx +3 -1
  48. package/src/components/home/HomeAgentBlock.tsx +3 -0
  49. package/src/components/home/HomeView.tsx +7 -0
  50. package/src/components/home/MCPSetupDialog.test.tsx +19 -12
  51. package/src/components/home/MCPSetupDialog.tsx +4 -2
  52. package/src/components/home/mcpToolCatalog.ts +15 -2
  53. package/src/components/home/useVulnerabilitiesRow.test.ts +26 -0
  54. package/src/components/home/useVulnerabilitiesRow.ts +50 -0
  55. package/src/components/logs/LogsViewer.tsx +3 -1
  56. package/src/components/logs/MultiPodLogsTab.test.tsx +24 -4
  57. package/src/components/logs/MultiPodLogsTab.tsx +9 -5
  58. package/src/components/nav/PrimaryNavRail.test.tsx +17 -0
  59. package/src/components/nav/PrimaryNavRail.tsx +174 -29
  60. package/src/components/resource/PrometheusChartsGrid.tsx +5 -1
  61. package/src/components/resource/SubstrateHealthCharts.test.tsx +143 -0
  62. package/src/components/resource/SubstrateHealthCharts.tsx +254 -0
  63. package/src/components/resource/SubstrateVerdictLine.test.tsx +131 -0
  64. package/src/components/resource/SubstrateVerdictLine.tsx +180 -0
  65. package/src/components/resources/ResourcesView.tsx +12 -6
  66. package/src/components/resources/renderers/UpgradePlanRenderer.test.tsx +20 -0
  67. package/src/components/resources/renderers/UpgradePlanRenderer.tsx +22 -0
  68. package/src/components/resources/renderers/VeleroBackupRenderer.tsx +16 -36
  69. package/src/components/resources/renderers/VeleroRestoreRenderer.tsx +6 -19
  70. package/src/components/resources/renderers/WorkloadRenderer.tsx +8 -0
  71. package/src/components/rightsizing/RightsizingScanView.tsx +3 -2
  72. package/src/components/shared/LargeClusterNamespacePicker.test.tsx +27 -0
  73. package/src/components/shared/LargeClusterNamespacePicker.tsx +8 -2
  74. package/src/components/timeline/TimelineView.tsx +3 -1
  75. package/src/components/traffic/TrafficConnectionsTable.test.tsx +94 -0
  76. package/src/components/traffic/TrafficConnectionsTable.tsx +21 -5
  77. package/src/components/traffic/TrafficData.test.tsx +37 -0
  78. package/src/components/traffic/TrafficData.tsx +27 -0
  79. package/src/components/traffic/TrafficFlowList.tsx +9 -7
  80. package/src/components/traffic/TrafficGraph.layoutEngine.test.tsx +193 -0
  81. package/src/components/traffic/TrafficGraph.test.tsx +269 -0
  82. package/src/components/traffic/TrafficGraph.tsx +135 -64
  83. package/src/components/traffic/TrafficGraphUnavailable.tsx +57 -0
  84. package/src/components/traffic/TrafficView.layoutUnavailable.test.tsx +211 -0
  85. package/src/components/traffic/TrafficView.tsx +46 -129
  86. package/src/components/traffic/trafficFilters.test.ts +172 -1
  87. package/src/components/traffic/trafficFilters.ts +139 -0
  88. package/src/components/ui/DiagnosticsOverlay.tsx +14 -1
  89. package/src/components/ui/UpdateNotification.manual.test.tsx +5 -2
  90. package/src/components/ui/UpdateNotification.test.tsx +31 -2
  91. package/src/components/ui/UpdateNotification.tsx +34 -17
  92. package/src/components/ui/command-items.ts +24 -1
  93. package/src/components/velero/VeleroBackupNow.test.tsx +165 -0
  94. package/src/components/velero/VeleroBackupNow.tsx +143 -0
  95. package/src/components/velero/VeleroDeleteBackup.test.tsx +364 -0
  96. package/src/components/velero/VeleroDeleteBackup.tsx +306 -0
  97. package/src/components/velero/VeleroDetailPage.tsx +158 -0
  98. package/src/components/velero/VeleroKindLists.test.tsx +48 -0
  99. package/src/components/velero/VeleroKindLists.tsx +43 -0
  100. package/src/components/velero/VeleroLocations.expand.test.tsx +27 -0
  101. package/src/components/velero/VeleroLocations.test.tsx +86 -0
  102. package/src/components/velero/VeleroLocations.tsx +240 -0
  103. package/src/components/velero/VeleroOverview.test.tsx +311 -0
  104. package/src/components/velero/VeleroOverview.tsx +485 -0
  105. package/src/components/velero/VeleroPages.test.tsx +516 -0
  106. package/src/components/velero/VeleroPages.tsx +1056 -0
  107. package/src/components/velero/VeleroRunArtifacts.test.tsx +241 -0
  108. package/src/components/velero/VeleroRunArtifacts.tsx +112 -0
  109. package/src/components/velero/VeleroRunLists.tsx +309 -0
  110. package/src/components/velero/VeleroRunMessagesHost.test.tsx +25 -0
  111. package/src/components/velero/VeleroRunMessagesHost.tsx +54 -0
  112. package/src/components/velero/VeleroRunVolumes.test.tsx +247 -0
  113. package/src/components/velero/VeleroRunVolumes.tsx +122 -0
  114. package/src/components/velero/VeleroSchedulePause.test.tsx +211 -0
  115. package/src/components/velero/VeleroSchedulePause.tsx +191 -0
  116. package/src/components/velero/VeleroScheduleStatusBadge.test.tsx +28 -0
  117. package/src/components/velero/VeleroScheduleStatusBadge.tsx +21 -0
  118. package/src/components/velero/VeleroSchedules.tsx +255 -0
  119. package/src/components/velero/VeleroView.tsx +59 -0
  120. package/src/components/velero/VeleroWorkspace.gate.test.tsx +97 -0
  121. package/src/components/velero/attention.test.ts +178 -0
  122. package/src/components/velero/attention.ts +281 -0
  123. package/src/components/velero/backupDelete.test.tsx +91 -0
  124. package/src/components/velero/backupDelete.tsx +182 -0
  125. package/src/components/velero/coverage.test.ts +87 -0
  126. package/src/components/velero/coverage.ts +150 -0
  127. package/src/components/velero/host.tsx +92 -0
  128. package/src/components/velero/routes.ts +78 -0
  129. package/src/components/velero/runs.tsx +121 -0
  130. package/src/components/velero/shared.test.ts +84 -0
  131. package/src/components/velero/shared.tsx +423 -0
  132. package/src/components/velero/useVeleroSidebarWorkspace.test.tsx +28 -0
  133. package/src/components/velero/useVeleroSidebarWorkspace.ts +71 -0
  134. package/src/components/velero/velero.fixtures.ts +61 -0
  135. package/src/components/velero/workspaceRoute.ts +21 -0
  136. package/src/components/vulnerabilities/WorkloadVulnerabilitiesSection.tsx +179 -0
  137. package/src/components/vulnerabilities/parts.test.ts +72 -0
  138. package/src/components/vulnerabilities/parts.tsx +291 -0
  139. package/src/components/whats-new/WhatsNewDialog.test.tsx +6 -4
  140. package/src/components/whats-new/releaseNotes.ts +67 -1
  141. package/src/components/workload/WorkloadView.tsx +64 -27
  142. package/src/components/workspace/DrawerTrailBack.tsx +32 -0
  143. package/src/components/workspace/WorkspaceFrame.tsx +71 -0
  144. package/src/components/workspace/coverage.ts +61 -0
  145. package/src/components/workspace/layout.test.tsx +29 -1
  146. package/src/components/workspace/layout.tsx +15 -5
  147. package/src/components/workspace/sidebar.ts +9 -0
  148. package/src/components/workspace/useWorkspaceDrawer.ts +63 -0
  149. package/src/components/workspace/useWorkspaceNavigate.ts +21 -0
  150. package/src/desktop/AboutDialog.test.ts +12 -0
  151. package/src/desktop/AboutDialog.tsx +151 -0
  152. package/src/desktop/WindowsTitleBar.tsx +359 -0
  153. package/src/desktop/titleBar.test.ts +61 -0
  154. package/src/desktop/titleBar.ts +45 -0
  155. package/src/index.css +19 -0
  156. package/src/integrations/resourceHost.ts +5 -1
  157. package/src/integrations/resourceHosts.test.tsx +14 -2
  158. package/src/integrations/resourceHosts.tsx +22 -6
  159. package/src/integrations/workspaceRoute.ts +1 -1
  160. package/src/integrations/workspaceRoutes.test.ts +11 -0
  161. package/src/integrations/workspaceRoutes.ts +3 -1
  162. package/src/integrations/workspaceScreens.tsx +2 -0
  163. package/src/main.tsx +8 -0
  164. package/src/utils/desktop-zoom.test.ts +53 -0
  165. package/src/utils/desktop-zoom.ts +30 -0
  166. package/src/utils/staleAssetPrompt.test.tsx +76 -0
  167. package/src/utils/staleAssetPrompt.tsx +32 -0
@@ -0,0 +1,281 @@
1
+ import {
2
+ veleroLocationReasonText,
3
+ veleroScheduleReasonText,
4
+ veleroScheduleStateLabel,
5
+ veleroScheduleTone,
6
+ type VeleroKindCoverage,
7
+ type VeleroLocationReading,
8
+ type VeleroScheduleReading,
9
+ type VeleroWorkspaceKey,
10
+ type VeleroWorkspaceResponse,
11
+ type WorkspaceProblem,
12
+ } from '@skyhook-io/k8s-ui'
13
+ import { INCOMPLETE_COVERAGE_STATES } from '../workspace/coverage'
14
+ import { VELERO_GROUP } from './routes'
15
+ import { VELERO_CHECK_HELD_BACKUP, VELERO_CHECK_SERVER, VELERO_DELETE_OBJECT, VELERO_SHORTEN_NAME, VELERO_START_SERVER, VELERO_WRITABLE_LOCATION, inInstallation, namesAndMore, veleroIssueProblem } from './shared'
16
+
17
+ export function readInPart(cov: VeleroKindCoverage | undefined): boolean {
18
+ return !cov || INCOMPLETE_COVERAGE_STATES.has(cov.state)
19
+ }
20
+
21
+ /**
22
+ * What the Velero views can say about deleting objects. `deleteObject`: the
23
+ * connected Radar binds a delete to the reviewed object
24
+ * (resourceDeletePreconditions) and reports schedule runs' storageLocation,
25
+ * both of which Delete object rests on.
26
+ */
27
+ export interface VeleroAttentionOptions {
28
+ deleteObject?: boolean
29
+ }
30
+
31
+ /**
32
+ * Whether the run holding a schedule is one Velero never started and gave no
33
+ * location, whose page offers Delete object (backupDelete.tsx).
34
+ */
35
+ function unstoredBlocker(s: Partial<Pick<VeleroScheduleReading, 'blocker'>>, opts: VeleroAttentionOptions): boolean {
36
+ const b = s.blocker
37
+ return !!opts.deleteObject && !!b && (!b.phase || b.phase === 'New') && !b.storageLocation
38
+ }
39
+
40
+ /** What to do about a schedule that needs attention, in one plain line. */
41
+ export function veleroScheduleNextStep(s: Pick<VeleroScheduleReading, 'state' | 'reason'> & Partial<Pick<VeleroScheduleReading, 'blocker'>>, opts: VeleroAttentionOptions = {}): string | undefined {
42
+ if (s.reason === 'serverDown') return VELERO_START_SERVER
43
+ switch (s.state) {
44
+ case 'cannotRun':
45
+ return s.reason === 'locationReadOnly' ? VELERO_WRITABLE_LOCATION : VELERO_SHORTEN_NAME
46
+ case 'alwaysDue':
47
+ return 'Change the cron expression to one with a future time'
48
+ case 'rejected':
49
+ return 'Fix what Velero rejected in the schedule; Velero validates it again when it changes'
50
+ case 'held':
51
+ return unstoredBlocker(s, opts)
52
+ ? `Check that the Velero server is running with its backup controller enabled, or open the queued backup and use ${VELERO_DELETE_OBJECT}: nothing of it is in storage.`
53
+ : VELERO_CHECK_HELD_BACKUP
54
+ case 'late':
55
+ case 'probablyLate':
56
+ case 'lateOrHeld':
57
+ return 'Check that the Velero server is running with its schedule controller, and read its logs'
58
+ case 'notValidated':
59
+ return VELERO_CHECK_SERVER
60
+ }
61
+ return undefined
62
+ }
63
+
64
+ function scheduleProblem(s: VeleroScheduleReading, serverShown: boolean, opts: VeleroAttentionOptions): WorkspaceProblem {
65
+ const tone = veleroScheduleTone(s)
66
+ return {
67
+ id: `schedule:${s.namespace}/${s.name}`,
68
+ category: 'schedule',
69
+ title: veleroScheduleStateLabel(s.state),
70
+ detail: veleroScheduleReasonText(s, { serverShown }),
71
+ nextStep: veleroScheduleNextStep(s, opts),
72
+ subject: { kind: 'Schedule', group: VELERO_GROUP, namespace: s.namespace, name: s.name },
73
+ ...(s.state === 'held' && s.blocker
74
+ ? { related: { lead: 'Queued backup:', refs: [{ kind: 'Backup', group: VELERO_GROUP, namespace: s.namespace, name: s.blocker.name }] } }
75
+ : {}),
76
+ source: 'reading',
77
+ tone: tone === 'healthy' ? 'neutral' : tone,
78
+ }
79
+ }
80
+
81
+ function serverProblem(namespace: string, deployment: string | undefined, late: VeleroScheduleReading[]): WorkspaceProblem {
82
+ const missed =
83
+ late.length === 0
84
+ ? ''
85
+ : ` ${late.length === 1 ? '1 schedule has' : `${late.length} schedules have`} missed runs: ${namesAndMore(late.map((s) => s.name))}.`
86
+ return {
87
+ id: `server:${namespace}`,
88
+ category: 'server',
89
+ title: 'Velero server not running',
90
+ // The subject link below names the Deployment.
91
+ detail: `No pods, so no new scheduled backups are submitted and no storage location is validated.${missed}`,
92
+ nextStep: VELERO_START_SERVER,
93
+ subject: { kind: 'Deployment', group: 'apps', namespace, name: deployment ?? 'velero' },
94
+ source: 'reading',
95
+ tone: 'unhealthy',
96
+ }
97
+ }
98
+
99
+ function backupsDisabledProblem(namespace: string, deployment: string | undefined, schedules: VeleroScheduleReading[]): WorkspaceProblem {
100
+ return {
101
+ id: `backups-disabled:${namespace}`,
102
+ category: 'server',
103
+ title: 'Velero backups disabled',
104
+ detail: `The server runs without its backup controller (--restore-only, or --disable-controllers naming backup or backup-queue), so no backup runs: ${
105
+ schedules.length === 1 ? 'schedule' : `${schedules.length} schedules,`
106
+ } ${namesAndMore(schedules.map((s) => s.name))} ${schedules.length === 1 ? 'backs' : 'back'} up nothing.`,
107
+ nextStep: 'Enable the backup controller on the Velero server, or pause the schedules',
108
+ subject: { kind: 'Deployment', group: 'apps', namespace, name: deployment ?? 'velero' },
109
+ source: 'reading',
110
+ tone: 'unhealthy',
111
+ }
112
+ }
113
+
114
+ function locationProblem(l: VeleroLocationReading): WorkspaceProblem {
115
+ return {
116
+ id: `location:${l.namespace}/${l.name}`,
117
+ category: 'location',
118
+ title: l.neverValidated ? 'Never validated' : 'Validation overdue',
119
+ detail: veleroLocationReasonText(l) || undefined,
120
+ nextStep: l.reason === 'serverDown' ? VELERO_START_SERVER : VELERO_CHECK_SERVER,
121
+ subject: { kind: 'BackupStorageLocation', group: VELERO_GROUP, namespace: l.namespace, name: l.name },
122
+ source: 'reading',
123
+ tone: 'degraded',
124
+ }
125
+ }
126
+
127
+ /**
128
+ * The Overview's Needs attention list: a stopped server, a server with backups
129
+ * disabled while schedules are not paused, schedule and location readings,
130
+ * then Velero's Issues. One fault is one row, as on the Issues page: a stopped
131
+ * server's row names the schedules it leaves late, and a backups-disabled
132
+ * row the schedules it leaves holding unstarted runs, which get no row of
133
+ * their own; storage a stopped server leaves unchecked is not listed. An
134
+ * unavailable location's issue names the runs Velero rejected because of it.
135
+ */
136
+ export function veleroAttention(data: VeleroWorkspaceResponse, installation: string | null, opts: VeleroAttentionOptions = {}): WorkspaceProblem[] {
137
+ const issues = installation === null ? data.issues : data.issues.filter((i) => (i.namespace ?? '') === installation)
138
+ const down = data.installations.filter((i) => (installation === null || i.namespace === installation) && i.server.replicas === 0)
139
+ const downIn = new Set(down.map((i) => i.namespace))
140
+ const lateWhileDown = (s: VeleroScheduleReading) => downIn.has(s.namespace) && s.state === 'late'
141
+ const schedules = inInstallation(data.schedules, installation).filter((s) => s.attention)
142
+ // A stopped server is the one fault there; backups disabled is said once it runs.
143
+ const disabled = data.installations
144
+ .filter((i) => (installation === null || i.namespace === installation) && !downIn.has(i.namespace) && i.server.backupsDisabled === true)
145
+ .map((i) => ({ installation: i, schedules: data.schedules.filter((s) => s.namespace === i.namespace && s.state !== 'paused') }))
146
+ .filter((d) => d.schedules.length > 0)
147
+ const disabledIn = new Set(disabled.map((d) => d.installation.namespace))
148
+ const heldWhileDisabled = (s: VeleroScheduleReading) => disabledIn.has(s.namespace) && s.state === 'held'
149
+ return [
150
+ ...down.map((i) => serverProblem(i.namespace, i.server.deployment, schedules.filter((s) => s.namespace === i.namespace && lateWhileDown(s)))),
151
+ ...disabled.map((d) => backupsDisabledProblem(d.installation.namespace, d.installation.server.deployment, d.schedules)),
152
+ ...schedules.filter((s) => !lateWhileDown(s) && !heldWhileDisabled(s)).map((s) => scheduleProblem(s, downIn.has(s.namespace), opts)),
153
+ ...inInstallation(data.locations, installation)
154
+ .filter((l) => l.attention && !(l.reason === 'serverDown' && downIn.has(l.namespace)))
155
+ .map(locationProblem),
156
+ ...issues.map((i) => veleroIssueProblem(i)),
157
+ ]
158
+ }
159
+
160
+ /**
161
+ * What Radar has for one Velero object, as banners for its page: its schedule
162
+ * or location reading when that needs attention (with the stopped server named
163
+ * in it), then Velero's Issues about it or naming it among the runs a fault
164
+ * rejected. Each says what to do next.
165
+ */
166
+ export function veleroObjectProblems(data: VeleroWorkspaceResponse, kind: string, namespace: string, name: string, opts: VeleroAttentionOptions = {}): WorkspaceProblem[] {
167
+ const out: WorkspaceProblem[] = []
168
+ if (kind === 'Schedule') {
169
+ const s = data.schedules.find((r) => r.namespace === namespace && r.name === name)
170
+ if (s?.attention) out.push({ ...scheduleProblem(s, false, opts), title: `Schedule ${veleroScheduleStateLabel(s.state).toLowerCase()}` })
171
+ }
172
+ if (kind === 'BackupStorageLocation') {
173
+ const l = data.locations.find((r) => r.namespace === namespace && r.name === name)
174
+ if (l?.attention) {
175
+ const p = locationProblem(l)
176
+ out.push({ ...p, title: `Storage location ${p.title[0].toLowerCase()}${p.title.slice(1)}` })
177
+ }
178
+ }
179
+ const issues = data.issues.filter((i) => {
180
+ const ns = i.namespace ?? ''
181
+ if (i.kind === kind && ns === namespace && i.name === name) return true
182
+ return !!i.affected?.some((a) => a.kind === kind && (a.namespace ?? ns) === namespace && a.name === name)
183
+ })
184
+ return [...out, ...issues.map((i) => veleroIssueProblem(i, { withNextStep: true }))]
185
+ }
186
+
187
+ export interface VeleroAttentionCount {
188
+ /** `null` when nothing was found but the read was partial, so zero would claim too much. */
189
+ count: number | null
190
+ lowerBound: boolean
191
+ title: string
192
+ }
193
+
194
+ /** The Issues the server counted but did not send (it sends the newest 50 per installation). */
195
+ function cappedIssues(data: VeleroWorkspaceResponse): number {
196
+ return Object.entries(data.issueTotals ?? {}).reduce(
197
+ (n, [ns, total]) => n + Math.max(0, total - data.issues.filter((i) => (i.namespace ?? '') === ns).length),
198
+ 0,
199
+ )
200
+ }
201
+
202
+ const OVERVIEW_KINDS: readonly VeleroWorkspaceKey[] = ['schedules', 'backups', 'restores', 'backupStorageLocations', 'backupRepositories']
203
+
204
+ /**
205
+ * The Overview's sidebar badge: how many rows Needs attention lists. Issues
206
+ * the server capped still count: it sends their total. A count over data read
207
+ * only in part is a lower bound, and its zero is unknown.
208
+ */
209
+ /**
210
+ * Whether Needs attention may be missing rows: a kind read in part, or a
211
+ * server Deployment Radar could not read, which hides a stopped server and
212
+ * disabled backups. `installation` narrows it as veleroAttention does.
213
+ */
214
+ export function veleroAttentionPartial(data: VeleroWorkspaceResponse, installation: string | null): boolean {
215
+ return OVERVIEW_KINDS.some((k) => readInPart(data.coverage[k])) || inInstallation(data.installations, installation).some((i) => i.server.source === 'unread')
216
+ }
217
+
218
+ /**
219
+ * Rows that may fold into one where a server Deployment is unread: a stopped
220
+ * server takes the late schedules into its row, disabled backups the held
221
+ * ones. Subtracted, the count stays a lower bound whichever is true.
222
+ */
223
+ function foldableWhileServerUnread(data: VeleroWorkspaceResponse): number {
224
+ return data.installations
225
+ .filter((i) => i.server.source === 'unread')
226
+ .reduce((n, i) => {
227
+ const rows = data.schedules.filter((s) => s.namespace === i.namespace && s.attention)
228
+ const late = rows.filter((s) => s.state === 'late').length
229
+ const held = rows.filter((s) => s.state === 'held').length
230
+ return n + Math.max(late - 1, held - 1, 0)
231
+ }, 0)
232
+ }
233
+
234
+ export function veleroAttentionCount(data: VeleroWorkspaceResponse): VeleroAttentionCount {
235
+ const count = veleroAttention(data, null).length + cappedIssues(data) - foldableWhileServerUnread(data)
236
+ const partial = veleroAttentionPartial(data, null)
237
+ if (partial && count === 0) {
238
+ return { count: null, lowerBound: true, title: 'Unknown: some Velero data could not be read, so nothing found does not mean nothing needs attention.' }
239
+ }
240
+ const note = partial ? ' Some Velero data could not be read, so there may be more.' : ''
241
+ return { count, lowerBound: partial, title: `${partial ? 'At least ' : ''}${count} in Needs attention.${note}` }
242
+ }
243
+
244
+ const SCREEN_KINDS = {
245
+ backups: { kind: 'Backup', coverage: 'backups', noun: ['backup', 'backups'] },
246
+ schedules: { kind: 'Schedule', coverage: 'schedules', noun: ['schedule', 'schedules'] },
247
+ restores: { kind: 'Restore', coverage: 'restores', noun: ['restore', 'restores'] },
248
+ backupstoragelocations: { kind: 'BackupStorageLocation', coverage: 'backupStorageLocations', noun: ['storage location', 'storage locations'] },
249
+ } as const satisfies Record<string, { kind: string; coverage: VeleroWorkspaceKey; noun: readonly [string, string] }>
250
+
251
+ export type VeleroScreen = keyof typeof SCREEN_KINDS
252
+
253
+ /**
254
+ * Each list screen's sidebar badge: the rows Needs attention lists about that
255
+ * screen's kind, so the screens' badges add up to the Overview's total less
256
+ * what belongs to no screen (a stopped server, disabled backups, Issues the
257
+ * server capped).
258
+ * Issues the server capped may be about any kind, so while there are some
259
+ * every screen's count is a lower bound.
260
+ */
261
+ export function veleroScreenCounts(data: VeleroWorkspaceResponse): Record<VeleroScreen, VeleroAttentionCount> {
262
+ const problems = veleroAttention(data, null)
263
+ const capped = cappedIssues(data) > 0
264
+ const out = {} as Record<VeleroScreen, VeleroAttentionCount>
265
+ for (const [screen, { kind, coverage, noun }] of Object.entries(SCREEN_KINDS) as [VeleroScreen, (typeof SCREEN_KINDS)[VeleroScreen]][]) {
266
+ const count = problems.filter((p) => p.subject?.kind === kind).length
267
+ const unread = readInPart(data.coverage[coverage])
268
+ const partial = unread || capped
269
+ const why = unread ? `Radar couldn’t read every ${noun[0]}` : 'Radar lists only the newest issues'
270
+ if (partial && count === 0) {
271
+ out[screen] = { count: null, lowerBound: true, title: `Unknown: ${why}.` }
272
+ continue
273
+ }
274
+ out[screen] = {
275
+ count,
276
+ lowerBound: partial,
277
+ title: `${partial ? 'At least ' : ''}${count} ${count === 1 ? `${noun[0]} needs` : `${noun[1]} need`} attention.${unread ? ' Some could not be read.' : capped ? ' Radar lists only the newest issues, so there may be more.' : ''}`,
278
+ }
279
+ }
280
+ return out
281
+ }
@@ -0,0 +1,91 @@
1
+ import { renderToStaticMarkup } from 'react-dom/server'
2
+ import { describe, expect, it, vi } from 'vitest'
3
+ import { location, workspace } from './velero.fixtures'
4
+
5
+ vi.mock('../../api/client', () => ({ useDeleteResource: () => ({}), useCascadeDeletePreview: () => ({}) }))
6
+ const { VELERO_DELETE_OBJECT_DETAILS, VeleroObjectDeleteNotice, veleroBackupDeletePath, veleroLocationMissing } = await import('./backupDelete')
7
+
8
+ const backup = (phase: string, storageLocation?: string, meta: Record<string, unknown> = {}) => ({
9
+ metadata: { namespace: 'velero', name: 'nightly-1', ...meta },
10
+ spec: storageLocation ? { storageLocation } : {},
11
+ status: phase ? { phase } : {},
12
+ })
13
+ const input = (over: Partial<Parameters<typeof veleroBackupDeletePath>[1]> = {}): Parameters<typeof veleroBackupDeletePath>[1] => ({
14
+ deleteBackup: 'supported',
15
+ preconditions: 'supported',
16
+ locationMissing: () => undefined,
17
+ request: 'none',
18
+ ...over,
19
+ })
20
+
21
+ describe('how a Velero Backup is deleted', () => {
22
+ it('deletes the object of a backup Velero never started and gave no location', () => {
23
+ for (const phase of ['', 'New']) {
24
+ expect(veleroBackupDeletePath(backup(phase), input())).toEqual({ kind: 'object', reason: 'unstored' })
25
+ }
26
+ // A schedule's template can name the location before Velero processes the run: Velero acts on a request for it.
27
+ expect(veleroBackupDeletePath(backup('New', 'default'), input())).toEqual({ kind: 'request' })
28
+ // Velero's queue may be handing these to the backup controller.
29
+ for (const phase of ['Queued', 'ReadyToStart']) expect(veleroBackupDeletePath(backup(phase), input()), phase).toEqual({ kind: 'request' })
30
+ })
31
+
32
+ it('deletes the object of a rejected backup only when its location is known not to exist', () => {
33
+ expect(veleroBackupDeletePath(backup('FailedValidation', 'gone'), input({ locationMissing: () => true }))).toEqual({ kind: 'object', reason: 'rejectedNoLocation' })
34
+ expect(veleroBackupDeletePath(backup('FailedValidation'), input())).toEqual({ kind: 'object', reason: 'rejectedNoLocation' })
35
+ expect(veleroBackupDeletePath(backup('FailedValidation', 'gone'), input())).toEqual({ kind: 'request' })
36
+ expect(veleroBackupDeletePath(backup('FailedValidation', 'default'), input({ locationMissing: () => false }))).toEqual({ kind: 'request' })
37
+ })
38
+
39
+ it('asks Velero for every other backup', () => {
40
+ for (const phase of ['Completed', 'PartiallyFailed', 'Failed', 'InProgress', 'Deleting']) {
41
+ expect(veleroBackupDeletePath(backup(phase, 'default'), input()), phase).toEqual({ kind: 'request' })
42
+ }
43
+ })
44
+
45
+ it('never doubles an open request, and waits until the requests are read', () => {
46
+ expect(veleroBackupDeletePath(backup('New'), input({ request: 'open' }))).toEqual({ kind: 'request' })
47
+ expect(veleroBackupDeletePath(backup('New'), input({ request: 'unknown' }))).toEqual({ kind: 'pending' })
48
+ })
49
+
50
+ it('offers it only where the delete is bound to the reviewed object, and not for one being deleted or holding finalizers', () => {
51
+ expect(veleroBackupDeletePath(backup('New'), input({ preconditions: 'unsupported' }))).toEqual({ kind: 'request' })
52
+ expect(veleroBackupDeletePath(backup('New', undefined, { deletionTimestamp: '2026-11-19T00:00:00Z' }), input())).toEqual({ kind: 'request' })
53
+ expect(veleroBackupDeletePath(backup('New', undefined, { finalizers: ['example.io/hold'] }), input())).toEqual({ kind: 'request' })
54
+ })
55
+
56
+ it('offers nothing on a Radar without Delete backup, and decides nothing before it loads', () => {
57
+ for (const phase of ['', 'New', 'Completed', 'FailedValidation']) {
58
+ expect(veleroBackupDeletePath(backup(phase), input({ deleteBackup: 'unsupported' })), phase).toEqual({ kind: 'pending' })
59
+ }
60
+ expect(veleroBackupDeletePath(backup('New'), input({ deleteBackup: 'unknown' }))).toEqual({ kind: 'pending' })
61
+ expect(veleroBackupDeletePath(undefined, input())).toEqual({ kind: 'pending' })
62
+ })
63
+
64
+ it('knows a location is missing only where every location in its namespace was read', () => {
65
+ const read = workspace({ locations: [location({ name: 'default' })] })
66
+ expect(veleroLocationMissing(read, 'velero', 'default')).toBe(false)
67
+ expect(veleroLocationMissing(read, 'velero', 'gone')).toBe(true)
68
+ const partial = (allowedNamespaces?: string[]) => ({ ...read, coverage: { ...read.coverage, backupStorageLocations: { state: 'partial' as const, allowedNamespaces } } })
69
+ expect(veleroLocationMissing(partial(), 'velero', 'gone')).toBeUndefined()
70
+ expect(veleroLocationMissing(partial(['velero']), 'velero', 'gone')).toBe(true)
71
+ expect(veleroLocationMissing(undefined, 'velero', 'gone')).toBeUndefined()
72
+ })
73
+ })
74
+
75
+ describe('the Delete object confirmation', () => {
76
+ it('says one thing for a backup Velero never stored: the object goes, nothing is in storage', () => {
77
+ expect(VELERO_DELETE_OBJECT_DETAILS).toBe('Deletes the Backup object. Nothing of it is in storage.')
78
+ const unstored = renderToStaticMarkup(<VeleroObjectDeleteNotice reason="unstored" backup={backup('New')} />)
79
+ expect(unstored).toContain('Nothing of this backup is in storage')
80
+ expect(unstored).toContain('never started this backup')
81
+ const rejected = renderToStaticMarkup(<VeleroObjectDeleteNotice reason="rejectedNoLocation" backup={backup('FailedValidation', 'gone')} />)
82
+ expect(rejected).toContain('so it wrote nothing')
83
+ expect(rejected).toContain('its storage location gone doesn’t exist')
84
+ })
85
+
86
+ it('says a schedule’s queued run holds it, and deleting it removes the hold', () => {
87
+ const queued = backup('New', undefined, { labels: { 'velero.io/schedule-name': 'nightly' } })
88
+ expect(renderToStaticMarkup(<VeleroObjectDeleteNotice reason="unstored" backup={queued} />)).toContain('While it is queued, Velero holds schedule nightly; deleting it removes that hold.')
89
+ expect(renderToStaticMarkup(<VeleroObjectDeleteNotice reason="unstored" backup={backup('New')} />)).not.toContain('holds schedule')
90
+ })
91
+ })
@@ -0,0 +1,182 @@
1
+ import { useState } from 'react'
2
+ import { useQueryClient } from '@tanstack/react-query'
3
+ import { Loader2, Trash2 } from 'lucide-react'
4
+ import { AlertBanner, ForceDeleteConfirmDialog, type VeleroWorkspaceResponse } from '@skyhook-io/k8s-ui'
5
+ import type { RadarFeatureSupport } from '../../api/radarFeatures'
6
+ import { useCascadeDeletePreview, useDeleteResource, useRadarFeature } from '../../api/client'
7
+ import { useVeleroBackupDeletion, useVeleroWorkspace } from '../../api/velero'
8
+ import { VELERO_BACKUP_KIND, VELERO_GROUP } from './routes'
9
+ import { VELERO_DELETE_BUTTON, VELERO_DELETE_OBJECT } from './shared'
10
+
11
+ /**
12
+ * How a Velero Backup is deleted from Radar:
13
+ * - `request`: Delete backup, a DeleteBackupRequest, as `velero backup delete`
14
+ * does. Velero removes the backup's data and then the object.
15
+ * - `object`: Delete object, a DELETE of the Backup object, offered only where
16
+ * Velero would never act on a request (`reason` says why).
17
+ * - `pending`: not decided yet; neither is offered.
18
+ */
19
+ export type VeleroBackupDeletePath =
20
+ | { kind: 'request' }
21
+ | { kind: 'object'; reason: VeleroObjectDeleteReason }
22
+ | { kind: 'pending' }
23
+
24
+ /**
25
+ * - `unstored`: Velero never started it (phase empty or New) and it names no
26
+ * storage location, so nothing of it was stored, and Velero refuses a
27
+ * request for a backup without a location. Queued and ReadyToStart are not
28
+ * included: Velero's queue may be handing the backup to its controller.
29
+ * - `rejectedNoLocation`: Velero rejected it before it ran (a rejected run
30
+ * writes nothing), and the location it names does not exist (or it names
31
+ * none), so Velero refuses the request.
32
+ */
33
+ export type VeleroObjectDeleteReason = 'unstored' | 'rejectedNoLocation'
34
+
35
+ export interface VeleroBackupDeleteInput {
36
+ deleteBackup: RadarFeatureSupport
37
+ /** The connected Radar binds a DELETE to the reviewed UID and resourceVersion. */
38
+ preconditions: RadarFeatureSupport
39
+ /** Whether a named storage location is known not to exist; undefined when that can't be said. */
40
+ locationMissing: (name: string) => boolean | undefined
41
+ /** Its DeleteBackupRequests: one open (or unreadable), none open, or not read yet. */
42
+ request: 'open' | 'none' | 'unknown'
43
+ }
44
+
45
+ /** The delete path for one Backup. */
46
+ export function veleroBackupDeletePath(backup: any, input: VeleroBackupDeleteInput): VeleroBackupDeletePath {
47
+ // An unloaded object reads as phase "" with no location; nothing is decided from that.
48
+ if (!backup || input.deleteBackup !== 'supported') return { kind: 'pending' }
49
+ // Without the reviewed-object binding, Velero could start it between review
50
+ // and delete, so a Radar without it keeps Delete backup.
51
+ if (input.preconditions !== 'supported') return { kind: 'request' }
52
+ if (backup.metadata?.deletionTimestamp || (backup.metadata?.finalizers ?? []).length > 0) return { kind: 'request' }
53
+ const phase: string = backup.status?.phase ?? ''
54
+ const location: string = backup.spec?.storageLocation ?? ''
55
+ const reason: VeleroObjectDeleteReason | undefined =
56
+ (phase === '' || phase === 'New') && !location
57
+ ? 'unstored'
58
+ : phase === 'FailedValidation' && (!location || input.locationMissing(location) === true)
59
+ ? 'rejectedNoLocation'
60
+ : undefined
61
+ if (!reason) return { kind: 'request' }
62
+ // A request already sent is followed where it is, never doubled by a second delete.
63
+ if (input.request === 'unknown') return { kind: 'pending' }
64
+ if (input.request === 'open') return { kind: 'request' }
65
+ return { kind: 'object', reason }
66
+ }
67
+
68
+ /** Whether a storage location is known not to exist: the workspace read every location in its namespace and it is not among them. */
69
+ export function veleroLocationMissing(workspace: VeleroWorkspaceResponse | undefined, namespace: string, name: string): boolean | undefined {
70
+ if (!workspace) return undefined
71
+ if (workspace.locations.some((l) => l.namespace === namespace && l.name === name)) return false
72
+ const cov = workspace.coverage.backupStorageLocations
73
+ const read = cov?.state === 'full' || (cov?.state === 'partial' && !!cov.allowedNamespaces?.includes(namespace))
74
+ return read ? true : undefined
75
+ }
76
+
77
+ /** The confirmation's consequence line, in place of the generic "This will permanently delete…". */
78
+ export const VELERO_DELETE_OBJECT_DETAILS = 'Deletes the Backup object. Nothing of it is in storage.'
79
+
80
+ /** Why this is Delete object and not Delete backup, said first in the confirmation. */
81
+ export function VeleroObjectDeleteNotice({ reason, backup }: { reason: VeleroObjectDeleteReason; backup: any }) {
82
+ const location: string = backup?.spec?.storageLocation ?? ''
83
+ const schedule: string | undefined = backup?.metadata?.labels?.['velero.io/schedule-name']
84
+ const why =
85
+ reason === 'unstored'
86
+ ? 'Velero never started this backup and gave it no storage location, so it won’t act on a deletion request for it.'
87
+ : `Velero rejected this backup before it ran, so it wrote nothing, and ${location ? `its storage location ${location} doesn’t exist` : 'it has no storage location'}, so Velero won’t act on a deletion request for it.`
88
+ // Velero submits nothing new for a schedule while one of its runs is New.
89
+ const held = reason === 'unstored' && schedule ? ` While it is queued, Velero holds schedule ${schedule}; deleting it removes that hold.` : ''
90
+ return <AlertBanner variant="info" title="Nothing of this backup is in storage" message={`${why}${held}`} className="mb-0" />
91
+ }
92
+
93
+ /**
94
+ * Delete object, in the Backup header where Delete backup otherwise is: the
95
+ * generic delete (DELETE /api/resources/...) bound to the object the user
96
+ * reviewed, so a backup Velero picked up meanwhile is refused (409) rather
97
+ * than deleted. No Force delete: these Backups carry no finalizer to strip.
98
+ * Dependents are listed only when the preview finds some: the only objects
99
+ * Velero owns by a Backup are the PodVolumeBackups and DataUploads it creates
100
+ * while the backup runs (Velero v1.18.2 podvolume/backupper.go,
101
+ * backup/actions/csi/pvc_action.go), and these never ran, so the generic
102
+ * preview's coverage caveats would only warn about nothing.
103
+ */
104
+ export function VeleroDeleteObject({ backup, reason }: { backup: any; reason: VeleroObjectDeleteReason }) {
105
+ const namespace: string = backup?.metadata?.namespace ?? ''
106
+ const name: string = backup?.metadata?.name ?? ''
107
+ const [reviewed, setReviewed] = useState<{ uid: string; resourceVersion: string } | null>(null)
108
+ const queryClient = useQueryClient()
109
+ // Deleted, refused (it changed since review) or failed: show the backup as it is now, even if this button is gone by then.
110
+ const preview = useCascadeDeletePreview(VELERO_BACKUP_KIND.name, namespace, name, VELERO_GROUP, reviewed !== null)
111
+ const deleteResource = useDeleteResource({
112
+ onSettled: () => {
113
+ void queryClient.invalidateQueries({ queryKey: ['resource'] })
114
+ void queryClient.invalidateQueries({ queryKey: ['velero'] })
115
+ },
116
+ })
117
+ return (
118
+ <>
119
+ <button
120
+ type="button"
121
+ disabled={deleteResource.isPending}
122
+ onClick={() => setReviewed({ uid: backup?.metadata?.uid ?? '', resourceVersion: backup?.metadata?.resourceVersion ?? '' })}
123
+ className={VELERO_DELETE_BUTTON}
124
+ >
125
+ {deleteResource.isPending ? <Loader2 className="h-3.5 w-3.5 animate-spin" aria-hidden /> : <Trash2 className="h-3.5 w-3.5" aria-hidden />}
126
+ {VELERO_DELETE_OBJECT}
127
+ </button>
128
+ <ForceDeleteConfirmDialog
129
+ open={reviewed !== null}
130
+ onClose={() => setReviewed(null)}
131
+ onConfirm={() => {
132
+ if (!reviewed) return
133
+ deleteResource.mutate({
134
+ kind: VELERO_BACKUP_KIND.name,
135
+ group: VELERO_GROUP,
136
+ namespace,
137
+ name,
138
+ uid: reviewed.uid,
139
+ resourceVersion: reviewed.resourceVersion,
140
+ })
141
+ setReviewed(null)
142
+ }}
143
+ resourceName={name}
144
+ resourceKind="Backup"
145
+ namespaceName={namespace}
146
+ resourceData={backup}
147
+ isLoading={deleteResource.isPending}
148
+ cascadeDetail={preview.data ? { ...preview.data, coverage: undefined } : undefined}
149
+ cascadeDependents={preview.data?.dependents}
150
+ cascadeLoading={preview.isFetching}
151
+ actionLabel={VELERO_DELETE_OBJECT}
152
+ details={VELERO_DELETE_OBJECT_DETAILS}
153
+ notice={<VeleroObjectDeleteNotice reason={reason} backup={backup} />}
154
+ allowForce={false}
155
+ />
156
+ </>
157
+ )
158
+ }
159
+
160
+ /**
161
+ * Why Delete object is offered for this Backup, or undefined: the header's
162
+ * decision for surfaces that only name the action (the page's next step). It
163
+ * reads the same features, workspace and deletion requests, so it agrees with
164
+ * the header once they are loaded.
165
+ */
166
+ export function useVeleroDeleteObjectReason(backup: any): VeleroObjectDeleteReason | undefined {
167
+ const deleteBackup = useRadarFeature('veleroDeleteBackup').support
168
+ const preconditions = useRadarFeature('resourceDeletePreconditions').support
169
+ const workspaceSupport = useRadarFeature('veleroWorkspace').support
170
+ const namespace: string = backup?.metadata?.namespace ?? ''
171
+ const workspace = useVeleroWorkspace({ enabled: !!backup && deleteBackup === 'supported' && workspaceSupport === 'supported' })
172
+ const deletion = useVeleroBackupDeletion(namespace, backup?.metadata?.name ?? '', backup?.metadata?.uid ?? '', !!backup && deleteBackup === 'supported')
173
+ const settled = deletion.data && ['refused', 'failed', 'unknown', 'deleted'].includes(deletion.data.state)
174
+ const request = deletion.error ? 'open' : !deletion.data ? 'unknown' : deletion.data.request && !settled ? 'open' : 'none'
175
+ const path = veleroBackupDeletePath(backup, {
176
+ deleteBackup,
177
+ preconditions,
178
+ locationMissing: (n) => veleroLocationMissing(workspace.data, namespace, n),
179
+ request,
180
+ })
181
+ return path.kind === 'object' ? path.reason : undefined
182
+ }
@@ -0,0 +1,87 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { namespacesNoScheduleIncludes, scheduleIncludes, veleroGlobMatch, veleroSelectionProblem } from './coverage'
3
+
4
+ const sel = (includedNamespaces: string[], excludedNamespaces: string[] = []) => ({ includedNamespaces, excludedNamespaces })
5
+
6
+ describe('veleroGlobMatch', () => {
7
+ it.each([
8
+ ['shop', 'shop', true],
9
+ ['shop', 'shop-2', false],
10
+ ['shop-*', 'shop-eu', true],
11
+ ['shop-?', 'shop-1', true],
12
+ ['shop-?', 'shop-12', false],
13
+ ['db-[ab]', 'db-a', true],
14
+ ['db-[a-c]', 'db-b', true],
15
+ ['ns-[ab-d]-prod', 'ns-c-prod', false],
16
+ ['ns-[ab-d]-prod', 'ns---prod', true],
17
+ ['*-prod-*', 'eu-prod-1', true],
18
+ ['*a*', 'bbb', false],
19
+ ['a.b', 'axb', false],
20
+ // Patterns Velero refuses, so a schedule using them backs up nothing.
21
+ ['[unclosed', '[unclosed', true],
22
+ ['db-[]', 'db-a', false],
23
+ ['db-[!ab]', 'db-c', false],
24
+ ['{shop,db}-prod', 'db-prod', false],
25
+ ['[z-a]*', 'shop', false],
26
+ ])('%s against %s is %s', (pattern, name, want) => {
27
+ expect(veleroGlobMatch(pattern, name)).toBe(want)
28
+ })
29
+ })
30
+
31
+ describe('veleroGlobMatch on hostile patterns', () => {
32
+ it('matches many stars against a long name without backtracking', () => {
33
+ const start = performance.now()
34
+ expect(veleroGlobMatch('*a'.repeat(24) + 'b', 'a'.repeat(63))).toBe(false)
35
+ expect(performance.now() - start).toBeLessThan(200)
36
+ })
37
+ it('matches a pattern longer than a namespace name only as written', () => {
38
+ const pattern = '*'.repeat(10_000) + '?'
39
+ expect(veleroGlobMatch(pattern, 'shop')).toBe(false)
40
+ expect(veleroGlobMatch(pattern, pattern)).toBe(true)
41
+ })
42
+ })
43
+
44
+ describe('scheduleIncludes', () => {
45
+ it('reads an empty or * include list as every namespace, with exclusions winning', () => {
46
+ expect(scheduleIncludes(sel([]), 'shop')).toBe(true)
47
+ expect(scheduleIncludes(sel(['*']), 'shop')).toBe(true)
48
+ expect(scheduleIncludes(sel([], ['shop']), 'shop')).toBe(false)
49
+ expect(scheduleIncludes(sel(['shop-*'], ['shop-scratch']), 'shop-scratch')).toBe(false)
50
+ expect(scheduleIncludes(sel(['shop-*'], ['shop-scratch']), 'shop-eu')).toBe(true)
51
+ })
52
+ })
53
+
54
+ describe('namespacesNoScheduleIncludes', () => {
55
+ const schedule = (included: string[], excluded: string[] = []) => ({ ...sel(included, excluded) }) as any
56
+ it('lists what no schedule selects, leaving out Kubernetes’ own and Velero’s namespaces', () => {
57
+ const got = namespacesNoScheduleIncludes(
58
+ ['shop', 'db', 'web', 'kube-system', 'kube-flannel', 'velero'],
59
+ [schedule(['shop']), schedule(['d*'])],
60
+ ['velero'],
61
+ )
62
+ expect(got).toEqual({ uncovered: ['web'], leftOut: 3 })
63
+ })
64
+ it('lists every namespace when there is no schedule', () => {
65
+ expect(namespacesNoScheduleIncludes(['b', 'a'], [], []).uncovered).toEqual(['a', 'b'])
66
+ })
67
+ })
68
+
69
+ describe('veleroSelectionProblem', () => {
70
+ it.each([
71
+ [['*', 'payments'], [], 'it includes “*” beside other namespaces'],
72
+ [[], ['*'], 'it excludes “*”'],
73
+ [['shop'], ['shop'], 'it both includes and excludes shop'],
74
+ [['Shop'], [], 'Shop is not a namespace name or pattern Velero accepts'],
75
+ [['shop-{a,b}'], [], 'shop-{a,b} is not a namespace name or pattern Velero accepts'],
76
+ [['prod-**'], [], 'prod-** is not a namespace name or pattern Velero accepts'],
77
+ [['db-[]'], [], 'db-[] is not a namespace name or pattern Velero accepts'],
78
+ [['db-a]'], [], 'db-a] is not a namespace name or pattern Velero accepts'],
79
+ ])('refuses %j excluding %j', (inc, exc, problem) => {
80
+ expect(veleroSelectionProblem(sel(inc, exc))).toBe(problem)
81
+ expect(scheduleIncludes(sel(inc, exc), 'shop')).toBe(false)
82
+ })
83
+
84
+ it.each([[[], []], [['*'], ['kube-*']], [['shop-*', 'db-[ab]'], ['']], [['*', '*'], []], [['shop', 'shop'], ['db']]])('accepts %j excluding %j', (inc, exc) => {
85
+ expect(veleroSelectionProblem(sel(inc, exc))).toBeUndefined()
86
+ })
87
+ })