@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,306 @@
|
|
|
1
|
+
import { useEffect, useState, type ReactNode } from 'react'
|
|
2
|
+
import { useQueryClient } from '@tanstack/react-query'
|
|
3
|
+
import { Loader2, Trash2 } from 'lucide-react'
|
|
4
|
+
import { ActionConfirmDialog, Badge, FactRow, Tooltip, formatRelativeAgeTime, toneTextClass, veleroLocalTime, veleroLocationRefusal, veleroPlainReason, type VeleroLocationRefusal } from '@skyhook-io/k8s-ui'
|
|
5
|
+
import { showApiError } from '../ui/Toast'
|
|
6
|
+
import { useRadarFeature } from '../../api/client'
|
|
7
|
+
import { getApiBase } from '../../api/config'
|
|
8
|
+
import { actionDialogResult } from '../../api/actions'
|
|
9
|
+
import { INCOMPLETE_COVERAGE_STATES } from '../workspace/coverage'
|
|
10
|
+
import { VeleroDeleteObject, veleroBackupDeletePath, veleroLocationMissing } from './backupDelete'
|
|
11
|
+
import { VELERO_DELETE_BUTTON } from './shared'
|
|
12
|
+
import { useVeleroBackupDeletion, useVeleroDeleteBackup, useVeleroRuns, useVeleroWorkspace, type VeleroDeletion } from '../../api/velero'
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
// The phases Velero's backup tracker holds a backup in (pkg/velero.BackupStillRunning).
|
|
16
|
+
const RUNNING = new Set(['InProgress', 'WaitingForPluginOperations', 'WaitingForPluginOperationsPartiallyFailed', 'Finalizing', 'FinalizingPartiallyFailed'])
|
|
17
|
+
const SETTLED = new Set<VeleroDeletion['state']>(['refused', 'failed', 'unknown', 'deleted'])
|
|
18
|
+
// A Restore Velero has not finished: it is still reading the backup.
|
|
19
|
+
const RESTORING = new Set(['', 'New', 'InProgress', 'WaitingForPluginOperations', 'WaitingForPluginOperationsPartiallyFailed', 'Finalizing', 'FinalizingPartiallyFailed'])
|
|
20
|
+
|
|
21
|
+
/** Why Velero would refuse to delete this backup now, from what Radar can see. */
|
|
22
|
+
export function deleteRefusal(backup: any, location: { accessMode?: string; phase?: string } | undefined, serverStopped: boolean, deletionDisabled = false): string | undefined {
|
|
23
|
+
const phase: string = backup?.status?.phase ?? ''
|
|
24
|
+
if (RUNNING.has(phase)) return `This backup is still running (${phase}). Velero deletes a backup only once it has finished.`
|
|
25
|
+
if (serverStopped) return 'The Velero server isn’t running, so nothing would be deleted now. Start it first.'
|
|
26
|
+
if (deletionDisabled) return 'Velero runs with its backup-deletion controller disabled (--restore-only or --disable-controllers=backup-deletion), so it would never process the deletion.'
|
|
27
|
+
const name: string = backup?.spec?.storageLocation ?? ''
|
|
28
|
+
if (!name) return 'This backup has no storage location yet; wait for Velero to start it before deleting.'
|
|
29
|
+
if (location?.accessMode === 'ReadOnly') return `Its storage location ${name} is read-only, and Velero does not delete backups from a read-only location.`
|
|
30
|
+
if (location && location.phase !== 'Available') return `Its storage location ${name} is not available, and Velero deletes a backup only from an available location.`
|
|
31
|
+
return undefined
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const PARTLY = 'Some of its data may already have been removed.'
|
|
35
|
+
|
|
36
|
+
function stateText(d: VeleroDeletion): string {
|
|
37
|
+
switch (d.state) {
|
|
38
|
+
case 'waiting':
|
|
39
|
+
return d.serverStopped ? 'Waiting for the Velero server, which isn’t running.' : 'Waiting for Velero to start deleting.'
|
|
40
|
+
case 'inProgress':
|
|
41
|
+
return 'Velero is deleting the backup.'
|
|
42
|
+
case 'refused':
|
|
43
|
+
return `Velero refused to delete the backup, and nothing was deleted: ${(d.errors ?? []).join('; ')}`
|
|
44
|
+
case 'failed':
|
|
45
|
+
return `Velero’s deletion failed. ${PARTLY} Velero reported: ${(d.errors ?? []).join('; ')}`
|
|
46
|
+
case 'unknown':
|
|
47
|
+
return 'Velero no longer has the request and the backup is still here, so how the deletion ended can’t be told. Check the backup, or delete it again.'
|
|
48
|
+
case 'deleted':
|
|
49
|
+
return 'Deleted.'
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// A settled deletion's state, for the At a glance's Deletion row.
|
|
54
|
+
const SETTLED_LABEL: Partial<Record<VeleroDeletion['state'], string>> = {
|
|
55
|
+
refused: 'Refused',
|
|
56
|
+
failed: 'Failed',
|
|
57
|
+
unknown: 'Outcome unknown',
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Velero's reasons in plain words where Radar recognises them, as written otherwise. */
|
|
61
|
+
function plainErrors(errors: string[] | undefined): string {
|
|
62
|
+
return (errors ?? []).map((e) => veleroPlainReason(e) ?? e).join('; ')
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function lowerFirst(text: string): string {
|
|
66
|
+
return /^[A-Z][a-z]/.test(text) && !text.startsWith('Velero') ? text[0].toLowerCase() + text.slice(1) : text
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** "2h ago" for when the request was made, from a Radar that reports it. */
|
|
70
|
+
function requestedAgo(d: VeleroDeletion): string | undefined {
|
|
71
|
+
return d.created ? formatRelativeAgeTime(d.created) : undefined
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const deletionNoticeKey = (namespace: string, request: string) => ['velero', 'deletion-notice', getApiBase(), namespace, request]
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* "Delete backup…" for a Velero Backup, in the header. A deletion Velero
|
|
78
|
+
* settled without deleting is said in the At a glance's Deletion row. Velero deletes
|
|
79
|
+
* a backup through a DeleteBackupRequest: its files in the bucket, its volume
|
|
80
|
+
* snapshots and uploaded data, and the restores made from it. Deleting the
|
|
81
|
+
* Backup object instead removes none of that, and Velero recreates the object
|
|
82
|
+
* from the bucket, so the generic Delete is not offered for these.
|
|
83
|
+
*/
|
|
84
|
+
export function VeleroDeleteBackup({ backup }: { backup: any }) {
|
|
85
|
+
const { support } = useRadarFeature('veleroDeleteBackup')
|
|
86
|
+
const workspaceSupport = useRadarFeature('veleroWorkspace').support
|
|
87
|
+
const namespace: string = backup?.metadata?.namespace ?? ''
|
|
88
|
+
const name: string = backup?.metadata?.name ?? ''
|
|
89
|
+
const uid: string = backup?.metadata?.uid ?? ''
|
|
90
|
+
const queryClient = useQueryClient()
|
|
91
|
+
const workspace = useVeleroWorkspace({ enabled: support === 'supported' && workspaceSupport === 'supported' })
|
|
92
|
+
const [reviewing, setReviewing] = useState<string | null>(null)
|
|
93
|
+
const deleteBackup = useVeleroDeleteBackup()
|
|
94
|
+
const deletion = useVeleroBackupDeletion(namespace, name, uid, support === 'supported')
|
|
95
|
+
// Read when the confirmation opens; the backup's page already holds them.
|
|
96
|
+
const restores = useVeleroRuns('restores', namespace, { backup: name }, { enabled: support === 'supported' && reviewing !== null && !!namespace && !!name })
|
|
97
|
+
const request = deletion.data?.request ?? deleteBackup.data?.request
|
|
98
|
+
const started = !!request || backup?.status?.phase === 'Deleting'
|
|
99
|
+
const preconditions = useRadarFeature('resourceDeletePreconditions').support
|
|
100
|
+
|
|
101
|
+
const state = deletion.data?.state
|
|
102
|
+
// Announced once, and only for a request sent from this browser session: a
|
|
103
|
+
// refusal found on opening the page is the header's badge, not news.
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
if (!request || (state !== 'failed' && state !== 'refused')) return
|
|
106
|
+
const key = deletionNoticeKey(namespace, request)
|
|
107
|
+
if (queryClient.getQueryData(key) !== 'sent') return
|
|
108
|
+
queryClient.setQueryData(key, 'announced')
|
|
109
|
+
if (state === 'refused') showApiError(`Velero refused to delete backup ${name}`, (deletion.data?.errors ?? []).join('; '))
|
|
110
|
+
if (state === 'failed') showApiError(`Deleting backup ${name} failed`, `${PARTLY} ${(deletion.data?.errors ?? []).join('; ')}`)
|
|
111
|
+
}, [queryClient, request, state, name, namespace, deletion.data?.errors])
|
|
112
|
+
|
|
113
|
+
if (!namespace || !name || !uid) return null
|
|
114
|
+
// Where Velero would never act on a request, Delete object takes Delete backup's place.
|
|
115
|
+
// A failed refresh leaves older data behind; for Delete object that reads as unknown.
|
|
116
|
+
const requestState = support !== 'supported' ? 'none' : !deletion.data && !deletion.error ? 'unknown' : deletion.error || (started && !(state && SETTLED.has(state))) ? 'open' : 'none'
|
|
117
|
+
const pathInput = { deleteBackup: support, preconditions, locationMissing: (n: string) => veleroLocationMissing(workspace.data, namespace, n) }
|
|
118
|
+
const path = veleroBackupDeletePath(backup, { ...pathInput, request: requestState })
|
|
119
|
+
// A backup only Delete object could remove, whose requests can't be read now:
|
|
120
|
+
// say so rather than fall back to a Delete backup Velero would refuse.
|
|
121
|
+
const objectUnreadable = !!deletion.error && veleroBackupDeletePath(backup, { ...pathInput, request: 'none' }).kind === 'object'
|
|
122
|
+
if (path.kind === 'object') return <VeleroDeleteObject backup={backup} reason={path.reason} />
|
|
123
|
+
if (support !== 'supported') return null
|
|
124
|
+
|
|
125
|
+
const locationName: string = backup?.spec?.storageLocation ?? ''
|
|
126
|
+
const location = workspace.data?.locations.find((l) => l.namespace === namespace && l.name === locationName)
|
|
127
|
+
const installation = workspace.data?.installations.find((i) => i.namespace === namespace)
|
|
128
|
+
const serverStopped = installation?.server.replicas === 0
|
|
129
|
+
const unavailable = deleteRefusal(backup, location, serverStopped, installation?.server.deletionDisabled === true)
|
|
130
|
+
const restoring = (restores.data?.runs ?? []).filter((r) => RESTORING.has(r.phase ?? ''))
|
|
131
|
+
// The warning must not arrive after the confirmation, nor its absence read as "none".
|
|
132
|
+
const checkingRestores = reviewing !== null && restores.isPending
|
|
133
|
+
const restoresUnchecked =
|
|
134
|
+
!checkingRestores &&
|
|
135
|
+
(!restores.data
|
|
136
|
+
? restores.error
|
|
137
|
+
? `Radar couldn’t check the restores of this backup (${restores.error.message}), so one may still be reading from it.`
|
|
138
|
+
: undefined
|
|
139
|
+
: INCOMPLETE_COVERAGE_STATES.has(restores.data.coverage.state) || restores.data.truncated
|
|
140
|
+
? 'Radar couldn’t check every restore of this backup, so one may still be reading from it.'
|
|
141
|
+
: undefined)
|
|
142
|
+
|
|
143
|
+
if (state === 'deleted') {
|
|
144
|
+
return null
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Asked, and not settled: follow it. A status Radar can't read is said as
|
|
148
|
+
// such; it is never a reason to offer the deletion again.
|
|
149
|
+
if ((deletion.error && !deletion.data) || objectUnreadable || (started && !(state && SETTLED.has(state)))) {
|
|
150
|
+
const unreadable = deletion.error && (!deletion.data || objectUnreadable)
|
|
151
|
+
const tooltip = unreadable
|
|
152
|
+
? started
|
|
153
|
+
? `Velero was asked to delete this backup, but Radar can’t read how it is going: ${deletion.error.message}`
|
|
154
|
+
: `Radar can’t read this backup’s deletion requests: ${deletion.error.message}`
|
|
155
|
+
: deletion.data
|
|
156
|
+
? stateText(deletion.data)
|
|
157
|
+
: 'Velero was asked to delete this backup.'
|
|
158
|
+
return (
|
|
159
|
+
<Tooltip content={tooltip} position="bottom">
|
|
160
|
+
<span>
|
|
161
|
+
{unreadable ? (
|
|
162
|
+
<Badge severity="warning">{started && !objectUnreadable ? 'Deletion requested' : 'Deletion status unreadable'}</Badge>
|
|
163
|
+
) : (
|
|
164
|
+
<Badge severity="neutral">
|
|
165
|
+
<Loader2 className="mr-1 inline h-3 w-3 animate-spin" aria-hidden />
|
|
166
|
+
{deletion.data?.state === 'waiting' && deletion.data.serverStopped ? 'Waiting for Velero' : 'Deleting…'}
|
|
167
|
+
</Badge>
|
|
168
|
+
)}
|
|
169
|
+
</span>
|
|
170
|
+
</Tooltip>
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Until the deletion requests are read, which delete applies is not known.
|
|
175
|
+
if (path.kind === 'pending') return null
|
|
176
|
+
|
|
177
|
+
const open = () => {
|
|
178
|
+
deleteBackup.reset()
|
|
179
|
+
setReviewing(uid)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const button = (
|
|
183
|
+
<button type="button" onClick={open} disabled={unavailable !== undefined} className={VELERO_DELETE_BUTTON}>
|
|
184
|
+
<Trash2 className="h-3.5 w-3.5" aria-hidden />
|
|
185
|
+
Delete backup
|
|
186
|
+
</button>
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
return (
|
|
190
|
+
<>
|
|
191
|
+
{unavailable ? (
|
|
192
|
+
<Tooltip content={unavailable} position="bottom">
|
|
193
|
+
<span>{button}</span>
|
|
194
|
+
</Tooltip>
|
|
195
|
+
) : (
|
|
196
|
+
button
|
|
197
|
+
)}
|
|
198
|
+
<ActionConfirmDialog
|
|
199
|
+
open={reviewing !== null}
|
|
200
|
+
onClose={() => setReviewing(null)}
|
|
201
|
+
onConfirm={() => {
|
|
202
|
+
if (!reviewing) return
|
|
203
|
+
deleteBackup.mutate(
|
|
204
|
+
{ namespace, name, uid: reviewing },
|
|
205
|
+
{
|
|
206
|
+
onSuccess: (sent) => {
|
|
207
|
+
const key = deletionNoticeKey(namespace, sent.request)
|
|
208
|
+
queryClient.setQueryDefaults(key, { gcTime: Infinity })
|
|
209
|
+
queryClient.setQueryData(key, 'sent')
|
|
210
|
+
void queryClient.invalidateQueries({ queryKey: ['velero', 'deletion'] })
|
|
211
|
+
setReviewing(null)
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
)
|
|
215
|
+
}}
|
|
216
|
+
title={`Delete backup ${name}?`}
|
|
217
|
+
subject={{ kind: 'Backup', namespace, name }}
|
|
218
|
+
effect={
|
|
219
|
+
<>
|
|
220
|
+
Velero deletes this backup: its files in {locationName ? `storage location ${locationName}` : 'its storage location'}, its
|
|
221
|
+
volume snapshots and uploaded volume data, and the restores made from it. Then the Backup itself is removed. This can’t be
|
|
222
|
+
undone.
|
|
223
|
+
</>
|
|
224
|
+
}
|
|
225
|
+
notes={[
|
|
226
|
+
'Deleting only the Backup object would leave all of this in place, and Velero would bring the object back from storage. Velero does the deletion here, as velero backup delete does.',
|
|
227
|
+
...(backup?.status?.phase === 'Deleting' ? ['Velero has marked this backup Deleting: a deletion is under way, or an earlier one failed.'] : []),
|
|
228
|
+
...(restoring.length > 0
|
|
229
|
+
? [
|
|
230
|
+
`${restoring.length === 1 ? `Restore ${restoring[0].name} is` : `Restores ${restoring.map((r) => r.name).join(', ')} are`} still restoring from this backup. Deleting it removes the data ${restoring.length === 1 ? 'it reads' : 'they read'}, so ${restoring.length === 1 ? 'it' : 'they'} may fail.`,
|
|
231
|
+
]
|
|
232
|
+
: []),
|
|
233
|
+
...(restoresUnchecked ? [restoresUnchecked] : []),
|
|
234
|
+
]}
|
|
235
|
+
incompleteReason={checkingRestores ? 'Checking restores of this backup…' : undefined}
|
|
236
|
+
writes={[{ summary: `create DeleteBackupRequest in namespace ${namespace}`, detail: `spec.backupName: ${name}` }]}
|
|
237
|
+
typedConfirmation={name}
|
|
238
|
+
confirmLabel="Delete backup"
|
|
239
|
+
disruptive
|
|
240
|
+
disabledReason={reviewing && reviewing !== uid ? 'This backup was recreated under the same name while this was open. Close it and review the backup again.' : unavailable}
|
|
241
|
+
isLoading={deleteBackup.isPending}
|
|
242
|
+
result={actionDialogResult(deleteBackup.error, { unknown: 'Velero may already have been asked to delete this backup. Open Delete backup again to retry: it sends the same request, never a second one.' })}
|
|
243
|
+
/>
|
|
244
|
+
</>
|
|
245
|
+
)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// A refusal is about the request: the location may have changed since.
|
|
249
|
+
const LOCATION_THEN: Record<VeleroLocationRefusal['problem'], string> = {
|
|
250
|
+
missing: 'didn’t exist',
|
|
251
|
+
unavailable: 'was unavailable',
|
|
252
|
+
readOnly: 'was read-only',
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function MonoName({ name }: { name: string }) {
|
|
256
|
+
return <span className="whitespace-nowrap font-mono text-[0.95em]">{name}</span>
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* The At a glance row for a deletion Velero settled without deleting:
|
|
261
|
+
* refused, failed, or ended where Radar can't tell. Velero keeps a processed
|
|
262
|
+
* request for a day, so the row says how long ago it was asked. `renderName`
|
|
263
|
+
* shows a storage location's name the way the rest of the page does.
|
|
264
|
+
*/
|
|
265
|
+
export function VeleroBackupDeletionRow({ backup, renderName = (n) => <MonoName name={n} /> }: { backup: any; renderName?: (name: string) => ReactNode }) {
|
|
266
|
+
const { support } = useRadarFeature('veleroDeleteBackup')
|
|
267
|
+
const namespace: string = backup?.metadata?.namespace ?? ''
|
|
268
|
+
const name: string = backup?.metadata?.name ?? ''
|
|
269
|
+
const uid: string = backup?.metadata?.uid ?? ''
|
|
270
|
+
const deletion = useVeleroBackupDeletion(namespace, name, uid, support === 'supported')
|
|
271
|
+
const d = deletion.data
|
|
272
|
+
const label = d && SETTLED_LABEL[d.state]
|
|
273
|
+
if (support !== 'supported' || !d || !label || (d.state === 'unknown' && !d.request && backup?.status?.phase !== 'Deleting')) return null
|
|
274
|
+
const ago = requestedAgo(d)
|
|
275
|
+
const reason = plainErrors(d.errors)
|
|
276
|
+
const raw = (d.errors ?? []).join('; ')
|
|
277
|
+
const refusal = d.state === 'refused' && d.errors?.length === 1 ? veleroLocationRefusal(d.errors[0]) : undefined
|
|
278
|
+
const detail: ReactNode = refusal ? (
|
|
279
|
+
<>
|
|
280
|
+
at the time, storage location {renderName(refusal.name)} {LOCATION_THEN[refusal.problem]}; nothing was deleted
|
|
281
|
+
</>
|
|
282
|
+
) : d.state === 'refused' ? (
|
|
283
|
+
`${reason ? lowerFirst(reason) : 'Velero gave no reason'}; nothing was deleted`
|
|
284
|
+
) : d.state === 'failed' ? (
|
|
285
|
+
`${PARTLY} ${reason}`.trim()
|
|
286
|
+
) : (
|
|
287
|
+
'Velero no longer has the request and the backup is still here; check the backup, or delete it again'
|
|
288
|
+
)
|
|
289
|
+
return (
|
|
290
|
+
<FactRow label="Deletion">
|
|
291
|
+
<span className={toneTextClass(d.state === 'unknown' ? 'degraded' : 'unhealthy')}>{label}</span>
|
|
292
|
+
{ago && (
|
|
293
|
+
<>
|
|
294
|
+
{' '}
|
|
295
|
+
<Tooltip content={d.created ? veleroLocalTime(d.created) : undefined}>
|
|
296
|
+
<span className="text-theme-text-secondary">{ago}</span>
|
|
297
|
+
</Tooltip>
|
|
298
|
+
</>
|
|
299
|
+
)}
|
|
300
|
+
{' — '}
|
|
301
|
+
<Tooltip content={`Velero’s message: ${raw}`} disabled={!raw || (raw === reason && !refusal)}>
|
|
302
|
+
<span>{detail}</span>
|
|
303
|
+
</Tooltip>
|
|
304
|
+
</FactRow>
|
|
305
|
+
)
|
|
306
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo } from 'react'
|
|
2
|
+
import { useQueryClient } from '@tanstack/react-query'
|
|
3
|
+
import { useLocation, useSearchParams } from 'react-router-dom'
|
|
4
|
+
import { Archive, CalendarClock, History, Unplug } from 'lucide-react'
|
|
5
|
+
import type { WorkloadExtraTab } from '@skyhook-io/k8s-ui'
|
|
6
|
+
import type { SelectedResource } from '../../types'
|
|
7
|
+
import { useConnection } from '../../context/ConnectionContext'
|
|
8
|
+
import { useContexts } from '../../api/client'
|
|
9
|
+
import { useContextSwitchFlow } from '../useContextSwitchFlow'
|
|
10
|
+
import { WorkloadView } from '../workload/WorkloadView'
|
|
11
|
+
import { ScreenEmptyState } from '../workspace/layout'
|
|
12
|
+
import { useWorkspaceNavigate } from '../workspace/useWorkspaceNavigate'
|
|
13
|
+
import { currentPageLabel } from '../../utils/page-links'
|
|
14
|
+
import { kindToPluralWithGroup } from '../../utils/navigation'
|
|
15
|
+
import { VELERO_DETAIL_KINDS, veleroDetailKindFor, veleroDetailPath, type VeleroDetailTarget, VELERO_GROUP } from './routes'
|
|
16
|
+
import { VeleroBackupRestores, VeleroBackupRestoresMark, VeleroLocationBackups, VeleroLocationBackupsMark, VeleroScheduleRuns, VeleroScheduleRunsMark } from './VeleroPages'
|
|
17
|
+
|
|
18
|
+
interface ReturnState {
|
|
19
|
+
returnLabel?: string
|
|
20
|
+
returnCtx?: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A Velero object's page: Radar's detail view framed by Velero, with a
|
|
25
|
+
* composed Overview (from the Velero host) and tabs for what the object
|
|
26
|
+
* relates to: a schedule's runs, a backup's restores, a location's backups.
|
|
27
|
+
*
|
|
28
|
+
* `ctx` pins the Kubernetes context; when the active context is another one,
|
|
29
|
+
* the page says so rather than loading a same-named object.
|
|
30
|
+
*/
|
|
31
|
+
export function VeleroDetailPage({ target, onOpenResource }: { target: VeleroDetailTarget; onOpenResource: (resource: SelectedResource) => void }) {
|
|
32
|
+
const location = useLocation()
|
|
33
|
+
const navigate = useWorkspaceNavigate()
|
|
34
|
+
const [searchParams, setSearchParams] = useSearchParams()
|
|
35
|
+
const { connection } = useConnection()
|
|
36
|
+
const activeContext = connection.context
|
|
37
|
+
const pinnedContext = searchParams.get('ctx')
|
|
38
|
+
const spec = VELERO_DETAIL_KINDS[target.plural]
|
|
39
|
+
const queryClient = useQueryClient()
|
|
40
|
+
// The page's own reads (activity, runs, a location's backups) beside the object.
|
|
41
|
+
const refresh = useCallback(() => queryClient.refetchQueries({ type: 'active', queryKey: ['velero'] }), [queryClient])
|
|
42
|
+
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (pinnedContext || !activeContext) return
|
|
45
|
+
const params = new URLSearchParams(searchParams)
|
|
46
|
+
params.set('ctx', activeContext)
|
|
47
|
+
setSearchParams(params, { replace: true, state: location.state })
|
|
48
|
+
}, [pinnedContext, activeContext]) // eslint-disable-line react-hooks/exhaustive-deps
|
|
49
|
+
|
|
50
|
+
const returnState = (location.state ?? {}) as ReturnState
|
|
51
|
+
const returnLabel = returnState.returnLabel && (!returnState.returnCtx || returnState.returnCtx === activeContext) ? returnState.returnLabel : null
|
|
52
|
+
|
|
53
|
+
// A related Velero object opens on its own page; anything else in the drawer.
|
|
54
|
+
const openRelated = useCallback(
|
|
55
|
+
(res: SelectedResource) => {
|
|
56
|
+
const plural = veleroDetailKindFor(kindToPluralWithGroup(res.kind, res.group ?? ''), res.group)
|
|
57
|
+
if (plural) {
|
|
58
|
+
navigate(veleroDetailPath({ plural, namespace: res.namespace, name: res.name }, activeContext), {
|
|
59
|
+
state: { returnLabel: currentPageLabel(), returnCtx: activeContext } satisfies ReturnState,
|
|
60
|
+
})
|
|
61
|
+
} else {
|
|
62
|
+
onOpenResource(res)
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
[navigate, activeContext, onOpenResource],
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
const extraTabs = useMemo<WorkloadExtraTab[] | undefined>(() => {
|
|
69
|
+
const { namespace, name } = target
|
|
70
|
+
switch (target.plural) {
|
|
71
|
+
case 'schedules':
|
|
72
|
+
return [{ id: 'runs', label: 'Runs', after: 'overview', icon: <History className="h-4 w-4" />, badge: <VeleroScheduleRunsMark namespace={namespace} name={name} />, render: () => <VeleroScheduleRuns namespace={namespace} name={name} onNavigate={openRelated} /> }]
|
|
73
|
+
case 'backups':
|
|
74
|
+
return [{ id: 'restores', label: 'Restores', after: 'overview', icon: <History className="h-4 w-4" />, badge: <VeleroBackupRestoresMark namespace={namespace} name={name} />, render: () => <VeleroBackupRestores namespace={namespace} name={name} onNavigate={openRelated} /> }]
|
|
75
|
+
case 'backupstoragelocations':
|
|
76
|
+
return [{ id: 'backups', label: 'Backups', after: 'overview', icon: <Archive className="h-4 w-4" />, badge: <VeleroLocationBackupsMark namespace={namespace} name={name} />, render: () => <VeleroLocationBackups namespace={namespace} name={name} onNavigate={openRelated} /> }]
|
|
77
|
+
default:
|
|
78
|
+
return undefined
|
|
79
|
+
}
|
|
80
|
+
}, [target, openRelated])
|
|
81
|
+
|
|
82
|
+
if (pinnedContext && activeContext && pinnedContext !== activeContext) {
|
|
83
|
+
return <NotInContext target={target} pinnedContext={pinnedContext} activeContext={activeContext} />
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Where the object lives: Velero / <its kind's list> /.
|
|
87
|
+
const titlePrefix = (
|
|
88
|
+
<nav aria-label="Location" className="flex shrink-0 items-center gap-1.5 text-sm text-theme-text-tertiary">
|
|
89
|
+
<CalendarClock className="h-3.5 w-3.5" />
|
|
90
|
+
<button type="button" onClick={() => navigate('/velero')} className="hover:text-theme-text-primary hover:underline">Velero</button>
|
|
91
|
+
<span>/</span>
|
|
92
|
+
<button type="button" onClick={() => navigate(spec.listPath)} className="hover:text-theme-text-primary hover:underline">{spec.label}</button>
|
|
93
|
+
<span>/</span>
|
|
94
|
+
</nav>
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<div className="flex h-full min-h-0 min-w-0 flex-1 flex-col">
|
|
99
|
+
<WorkloadView
|
|
100
|
+
key={`${target.plural}/${target.namespace}/${target.name}`}
|
|
101
|
+
kind={target.plural}
|
|
102
|
+
namespace={target.namespace}
|
|
103
|
+
name={target.name}
|
|
104
|
+
group={VELERO_GROUP}
|
|
105
|
+
expanded
|
|
106
|
+
onBack={() => (returnLabel ? navigate(-1) : navigate(spec.listPath))}
|
|
107
|
+
hideBackButton
|
|
108
|
+
titlePrefix={titlePrefix}
|
|
109
|
+
inlineBadges
|
|
110
|
+
// The crumb names the kind.
|
|
111
|
+
hideKindBadge
|
|
112
|
+
truncateName
|
|
113
|
+
onNavigateToResource={openRelated}
|
|
114
|
+
onRefresh={refresh}
|
|
115
|
+
extraTabs={extraTabs}
|
|
116
|
+
/>
|
|
117
|
+
</div>
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function NotInContext({ target, pinnedContext, activeContext }: { target: VeleroDetailTarget; pinnedContext: string; activeContext: string }) {
|
|
122
|
+
const navigate = useWorkspaceNavigate()
|
|
123
|
+
const { data: contexts } = useContexts()
|
|
124
|
+
const { requestSwitch, confirmDialog } = useContextSwitchFlow()
|
|
125
|
+
const pinned = contexts?.find((c) => c.name === pinnedContext)
|
|
126
|
+
return (
|
|
127
|
+
<>
|
|
128
|
+
<ScreenEmptyState
|
|
129
|
+
icon={Unplug}
|
|
130
|
+
title={`${target.name} is not in ${activeContext}`}
|
|
131
|
+
detail={`This link points at ${VELERO_DETAIL_KINDS[target.plural].kind} ${target.name} in context ${pinnedContext}. Radar does not open a same-named object from another cluster.`}
|
|
132
|
+
action={
|
|
133
|
+
<div className="mt-4 flex flex-wrap justify-center gap-2">
|
|
134
|
+
{pinned && (
|
|
135
|
+
<button type="button" onClick={() => requestSwitch(pinned)} className="btn-brand px-3 py-1.5 text-sm font-medium">
|
|
136
|
+
Switch back to {pinnedContext}
|
|
137
|
+
</button>
|
|
138
|
+
)}
|
|
139
|
+
<button type="button" onClick={() => navigate('/velero')} className="btn-secondary px-3 py-1.5 text-sm">
|
|
140
|
+
Go to the Velero Overview
|
|
141
|
+
</button>
|
|
142
|
+
</div>
|
|
143
|
+
}
|
|
144
|
+
/>
|
|
145
|
+
{confirmDialog}
|
|
146
|
+
</>
|
|
147
|
+
)
|
|
148
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot } from 'react-dom/client'
|
|
4
|
+
import { parse } from 'yaml'
|
|
5
|
+
import { afterEach, expect, it, vi } from 'vitest'
|
|
6
|
+
import { workspace } from './velero.fixtures'
|
|
7
|
+
import { VeleroBackupsKindList, VeleroRestoresKindList } from './VeleroKindLists'
|
|
8
|
+
|
|
9
|
+
const state = vi.hoisted(() => ({ namespaces: [] as string[] }))
|
|
10
|
+
vi.mock('../../api/velero', () => ({
|
|
11
|
+
useVeleroWorkspace: () => ({
|
|
12
|
+
data: workspace({
|
|
13
|
+
installations: state.namespaces.map(namespace => ({ namespace, server: { source: 'unread' }, defaultSource: 'unknown' })),
|
|
14
|
+
}),
|
|
15
|
+
}),
|
|
16
|
+
useVeleroRuns: () => ({ data: { runs: [], total: 0, coverage: { state: 'full' } } }),
|
|
17
|
+
}))
|
|
18
|
+
vi.mock('../../context/ConnectionContext', () => ({ useConnection: () => ({ connection: { context: 'test' } }) }))
|
|
19
|
+
|
|
20
|
+
afterEach(() => vi.unstubAllGlobals())
|
|
21
|
+
|
|
22
|
+
it.each([
|
|
23
|
+
{ kind: 'Backup', namespaces: ['velero'], target: 'velero' },
|
|
24
|
+
{ kind: 'Restore', namespaces: ['velero', 'kommander'], pick: 'kommander', target: 'kommander' },
|
|
25
|
+
{ kind: 'Backup', namespaces: ['velero', 'kommander'], target: '<velero-installation-namespace>' },
|
|
26
|
+
{ kind: 'Restore', namespaces: [], target: '<velero-installation-namespace>' },
|
|
27
|
+
])('seeds the $kind draft with $target for $namespaces (selection $pick)', ({ kind, namespaces, pick, target }) => {
|
|
28
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
29
|
+
state.namespaces = namespaces
|
|
30
|
+
const host = document.createElement('div')
|
|
31
|
+
const root = createRoot(host)
|
|
32
|
+
const List = kind === 'Backup' ? VeleroBackupsKindList : VeleroRestoresKindList
|
|
33
|
+
const create = vi.fn()
|
|
34
|
+
const click = (label: string) => {
|
|
35
|
+
const button = [...host.querySelectorAll('button')].find(b => b.textContent?.trim() === label)
|
|
36
|
+
if (!button) throw new Error(`No button for ${label}`)
|
|
37
|
+
act(() => button.click())
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
act(() => root.render(<List namespaces={['application']} inspected={null} onClearNamespaces={() => {}} onInspect={() => {}} onCreate={create} />))
|
|
41
|
+
if (pick) click(pick)
|
|
42
|
+
click(`Create ${kind}`)
|
|
43
|
+
expect(create).toHaveBeenCalledOnce()
|
|
44
|
+
expect(parse(create.mock.calls[0][1])).toMatchObject({ apiVersion: 'velero.io/v1', kind, metadata: { namespace: target } })
|
|
45
|
+
} finally {
|
|
46
|
+
act(() => root.unmount())
|
|
47
|
+
}
|
|
48
|
+
})
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ComponentType } from 'react'
|
|
2
|
+
import { parseDocument } from 'yaml'
|
|
3
|
+
import type { HostKind, KindListProps } from '../../integrations/resourceHost'
|
|
4
|
+
import { useVeleroWorkspace } from '../../api/velero'
|
|
5
|
+
import { getSkeletonYaml } from '../../utils/skeleton-yaml'
|
|
6
|
+
import { VeleroLocations } from './VeleroLocations'
|
|
7
|
+
import { VeleroSchedules } from './VeleroSchedules'
|
|
8
|
+
import { VeleroBackups, VeleroRestores } from './VeleroRunLists'
|
|
9
|
+
import { VELERO_BACKUP_KIND, VELERO_RESTORE_KIND } from './routes'
|
|
10
|
+
import { VeleroScreenGate, useVeleroInstallation, type VeleroScreenProps } from './shared'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A Velero kind's list on its Resources route, as Radar reads it rather than
|
|
14
|
+
* as a bare table: the same workspace data as /velero, rows opening the
|
|
15
|
+
* Resources page's drawer. The namespace filter does not apply, as on /velero.
|
|
16
|
+
*/
|
|
17
|
+
function veleroKindList(Screen: ComponentType<VeleroScreenProps>, kind?: HostKind) {
|
|
18
|
+
return function VeleroKindList({ inspected, onInspect, onCreate }: KindListProps) {
|
|
19
|
+
const query = useVeleroWorkspace()
|
|
20
|
+
const [installation, setInstallation] = useVeleroInstallation(query.data?.installations)
|
|
21
|
+
return (
|
|
22
|
+
<div className="flex min-h-0 min-w-0 flex-1 flex-col bg-theme-base">
|
|
23
|
+
<VeleroScreenGate query={query} discoveryPending={false} discovered>
|
|
24
|
+
{(data) => {
|
|
25
|
+
const create = kind && (() => {
|
|
26
|
+
const selected = data.installations.find((i) => i.namespace === installation)
|
|
27
|
+
const target = selected ?? (data.installations.length === 1 ? data.installations[0] : undefined)
|
|
28
|
+
const draft = parseDocument(getSkeletonYaml(kind.kind, kind.group))
|
|
29
|
+
draft.setIn(['metadata', 'namespace'], target?.namespace ?? '<velero-installation-namespace>')
|
|
30
|
+
onCreate(kind, draft.toString())
|
|
31
|
+
})
|
|
32
|
+
return <Screen data={data} installation={installation} onInstallation={setInstallation} onInspect={onInspect} inspected={inspected} onCreate={create} />
|
|
33
|
+
}}
|
|
34
|
+
</VeleroScreenGate>
|
|
35
|
+
</div>
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const VeleroSchedulesKindList = veleroKindList(VeleroSchedules)
|
|
41
|
+
export const VeleroLocationsKindList = veleroKindList(VeleroLocations)
|
|
42
|
+
export const VeleroBackupsKindList = veleroKindList(VeleroBackups, VELERO_BACKUP_KIND)
|
|
43
|
+
export const VeleroRestoresKindList = veleroKindList(VeleroRestores, VELERO_RESTORE_KIND)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot } from 'react-dom/client'
|
|
4
|
+
import { expect, it, vi } from 'vitest'
|
|
5
|
+
import { VeleroLocations } from './VeleroLocations'
|
|
6
|
+
import { location, workspace } from './velero.fixtures'
|
|
7
|
+
|
|
8
|
+
;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
|
|
9
|
+
|
|
10
|
+
it('expands a folded schedule list and opens a schedule that was folded', () => {
|
|
11
|
+
const host = document.createElement('div')
|
|
12
|
+
document.body.append(host)
|
|
13
|
+
const root = createRoot(host)
|
|
14
|
+
const onInspect = vi.fn()
|
|
15
|
+
const schedules = ['a', 'b', 'c', 'd'].map((name) => ({ name }))
|
|
16
|
+
act(() => root.render(
|
|
17
|
+
<VeleroLocations data={workspace({ locations: [location({ schedules })] })} installation={null} onInstallation={() => {}} onInspect={onInspect} inspected={null} />,
|
|
18
|
+
))
|
|
19
|
+
const button = (label: string) => [...host.querySelectorAll('button')].find((b) => b.textContent === label)
|
|
20
|
+
expect(button('d')).toBeUndefined()
|
|
21
|
+
act(() => button('and 1 more')!.click())
|
|
22
|
+
act(() => button('d')!.click())
|
|
23
|
+
expect(onInspect).toHaveBeenCalledTimes(1)
|
|
24
|
+
expect(onInspect.mock.calls[0][0]).toMatchObject({ kind: 'schedules', name: 'd', namespace: 'velero' })
|
|
25
|
+
act(() => root.unmount())
|
|
26
|
+
host.remove()
|
|
27
|
+
})
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { renderToStaticMarkup } from 'react-dom/server'
|
|
2
|
+
import { MemoryRouter } from 'react-router-dom'
|
|
3
|
+
import { describe, expect, it } from 'vitest'
|
|
4
|
+
import type { VeleroWorkspaceResponse } from '@skyhook-io/k8s-ui'
|
|
5
|
+
import { VeleroLocations } from './VeleroLocations'
|
|
6
|
+
import { VeleroOverview } from './VeleroOverview'
|
|
7
|
+
import { hoursAgo, location, workspace } from './velero.fixtures'
|
|
8
|
+
|
|
9
|
+
const text = (html: string) => html.replace(/'/g, "'").replace(/"/g, '"').replace(/&/g, '&')
|
|
10
|
+
|
|
11
|
+
function render(data: VeleroWorkspaceResponse) {
|
|
12
|
+
return text(renderToStaticMarkup(
|
|
13
|
+
<VeleroLocations data={data} installation={null} onInstallation={() => {}} onInspect={() => {}} inspected={null} />,
|
|
14
|
+
))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe('Velero storage locations', () => {
|
|
18
|
+
it('shows unread backups and schedules as unknown, never as zero or none', () => {
|
|
19
|
+
const html = render(workspace({
|
|
20
|
+
coverage: { schedules: { state: 'denied' }, backups: { state: 'denied' }, backupStorageLocations: { state: 'full' }, restores: { state: 'full' }, backupRepositories: { state: 'full' } },
|
|
21
|
+
installations: [{ namespace: 'velero', server: { source: 'unread' }, defaultSource: 'unknown' }],
|
|
22
|
+
locations: [location({ backups: null, schedules: null, default: false, defaultSource: 'unknown', frequency: undefined })],
|
|
23
|
+
}))
|
|
24
|
+
expect(html).toContain('Unknown — backups were not read')
|
|
25
|
+
expect(html).toContain('Unknown — no access to schedules')
|
|
26
|
+
expect(html).toContain('frequency unknown')
|
|
27
|
+
expect(html).toContain('default unknown')
|
|
28
|
+
expect(html).not.toMatch(/tabular-nums">0</)
|
|
29
|
+
expect(html).toContain('Radar couldn’t read some of the Velero data on this screen')
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('counts the backups each location is named by and flags overdue validation', () => {
|
|
33
|
+
const data = workspace({
|
|
34
|
+
installations: [{ namespace: 'velero', server: { source: 'deployment' }, defaultLocation: 'default', defaultSource: 'spec' }],
|
|
35
|
+
locations: [location({ validationOverdue: true, attention: true, lastValidation: hoursAgo(2), schedules: [{ name: 'nightly' }, { name: 'weekly', viaDefault: true }] })],
|
|
36
|
+
})
|
|
37
|
+
const html = render(data)
|
|
38
|
+
expect(html).toContain('overdue')
|
|
39
|
+
expect(html).toContain('(as the default)')
|
|
40
|
+
// The usual frequency lives in the overdue badge's tooltip, not on every row.
|
|
41
|
+
expect(html).not.toContain('server flag')
|
|
42
|
+
|
|
43
|
+
const overview = text(renderToStaticMarkup(
|
|
44
|
+
<MemoryRouter>
|
|
45
|
+
<VeleroOverview data={data} installation={null} onInstallation={() => {}} onInspect={() => {}} inspected={null} />
|
|
46
|
+
</MemoryRouter>,
|
|
47
|
+
))
|
|
48
|
+
expect(overview).toContain('Velero last validated this location 2h ago; it validates every 1m.')
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('says validation is disabled when its frequency is zero', () => {
|
|
52
|
+
const html = render(workspace({ locations: [location({ frequency: { seconds: 0, source: 'spec', disabled: true } })] }))
|
|
53
|
+
expect(html).toContain('validation disabled')
|
|
54
|
+
})
|
|
55
|
+
it('says when Velero never validated a location', () => {
|
|
56
|
+
const html = text(render(workspace({ locations: [location({ neverValidated: true, attention: true, lastValidation: undefined })] })))
|
|
57
|
+
expect(html).toContain('Not validated yet')
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('says why a location is unavailable in plain words, and marks the default once, under its name', () => {
|
|
61
|
+
const html = render(workspace({
|
|
62
|
+
locations: [
|
|
63
|
+
location(),
|
|
64
|
+
location({ name: 'dr', phase: 'Unavailable', default: false, message: 'rpc error: code = Unknown desc = NoSuchBucket: The specified bucket does not exist' }),
|
|
65
|
+
],
|
|
66
|
+
}))
|
|
67
|
+
expect(html).toContain('The bucket doesn’t exist')
|
|
68
|
+
// The default location named "default" reads once as its name and once as a note on a line of its own, not as a badge beside it.
|
|
69
|
+
expect(html).not.toMatch(/badge[^"]*">default</)
|
|
70
|
+
expect(html.match(/>default</g)?.length).toBe(1)
|
|
71
|
+
expect(html).toMatch(/<div class="mt-0\.5 text-xs[^"]*"><span[^>]*><span>the default location<\/span>/)
|
|
72
|
+
// On one line, the reason on hover; jsdom has no matchMedia, so this is the narrow table, whose counts share a column.
|
|
73
|
+
expect(html).toMatch(/whitespace-nowrap[^"]*">not restorable</)
|
|
74
|
+
expect(html).toContain('Last checked')
|
|
75
|
+
expect(html).toMatch(/— <span class="text-red[^"]*">failed</)
|
|
76
|
+
expect(html).toContain('completed · ')
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('marks the default location and folds a long schedule list into a count', () => {
|
|
80
|
+
const schedules = ['a', 'b', 'c', 'd', 'e'].map((name) => ({ name }))
|
|
81
|
+
const html = render(workspace({ locations: [location({ schedules })] }))
|
|
82
|
+
expect(html).toContain('>the default location<')
|
|
83
|
+
expect(html).toContain('and 2 more')
|
|
84
|
+
expect(html).not.toContain('>d<')
|
|
85
|
+
})
|
|
86
|
+
})
|