@skyhook-io/radar-app 1.20.1 → 1.20.3
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 +1 -1
- package/src/App.tsx +12 -7
- package/src/api/client.namespaceSwitch.hook.test.tsx +170 -1
- package/src/api/client.pauseDeployment.test.tsx +77 -0
- package/src/api/client.restartError.test.ts +14 -0
- package/src/api/client.revisionRefresh.test.tsx +44 -0
- package/src/api/client.rollbackError.test.ts +14 -0
- package/src/api/client.ts +218 -11
- package/src/api/networkAttachments.test.tsx +120 -0
- package/src/api/networkAttachments.ts +30 -0
- package/src/api/radarFeatures.test.ts +5 -0
- package/src/api/radarFeatures.ts +3 -0
- package/src/api/secretsStore.test.ts +33 -0
- package/src/api/secretsStore.ts +37 -0
- package/src/components/ConnectionErrorView.test.tsx +11 -0
- package/src/components/ConnectionErrorView.tsx +19 -0
- package/src/components/ContextSwitcher.tsx +9 -2
- package/src/components/applications/ApplicationsView.openResource.test.tsx +118 -0
- package/src/components/applications/ApplicationsView.tsx +8 -11
- package/src/components/cost/CostView.tsx +27 -9
- package/src/components/diagnose/InvestigationView.tsx +12 -3
- package/src/components/diagnose/investigationEvidence/adapters/helm.test.tsx +52 -0
- package/src/components/diagnose/investigationEvidence/adapters/helm.ts +10 -0
- package/src/components/diagnose/investigationEvidence/bodies/platform.tsx +82 -51
- package/src/components/diagnose/investigationEvidence/types.ts +5 -0
- package/src/components/dock/TerminalPreferences.query.test.tsx +57 -0
- package/src/components/dock/TerminalPreferences.test.tsx +68 -0
- package/src/components/dock/TerminalPreferences.tsx +73 -0
- package/src/components/gitops/GitOpsView.tsx +1 -9
- package/src/components/helm/HelmReleaseDrawer.tsx +24 -12
- package/src/components/helm/HelmView.tsx +5 -3
- package/src/components/helm/NotCheckedBadge.test.tsx +62 -0
- package/src/components/helm/NotCheckedBadge.tsx +39 -0
- package/src/components/helm/OwnedResources.test.tsx +86 -0
- package/src/components/helm/OwnedResources.tsx +65 -8
- package/src/components/home/ClusterHealthCard.heading.test.tsx +72 -0
- package/src/components/home/ClusterHealthCard.test.ts +44 -1
- package/src/components/home/ClusterHealthCard.tsx +22 -10
- package/src/components/home/HelmSummary.tsx +15 -15
- package/src/components/home/mcpToolCatalog.ts +2 -2
- package/src/components/resource/RightsizingStrip.test.ts +57 -0
- package/src/components/resource/RightsizingStrip.tsx +53 -4
- package/src/components/resources/ImageFilesystemModal.test.tsx +74 -6
- package/src/components/resources/ImageFilesystemModal.tsx +98 -6
- package/src/components/resources/PodFileUploadPanel.tsx +150 -0
- package/src/components/resources/PodFilesystemModal.tsx +246 -3
- package/src/components/resources/pod-file-upload.test.tsx +223 -0
- package/src/components/resources/pod-file-upload.ts +266 -0
- package/src/components/resources/renderers/HTTPRouteRenderer.test.tsx +50 -0
- package/src/components/resources/renderers/HTTPRouteRenderer.tsx +27 -0
- package/src/components/resources/renderers/PodRenderer.tsx +26 -1
- package/src/components/resources/renderers/SecretProviderClassRenderer.tsx +25 -0
- package/src/components/rightsizing/RightsizingScanView.tsx +16 -1
- package/src/components/rightsizing/model.test.ts +11 -0
- package/src/components/rightsizing/model.ts +3 -1
- package/src/components/rightsizing/presentation.test.ts +46 -0
- package/src/components/rightsizing/presentation.ts +17 -2
- package/src/components/traffic/TrafficView.tsx +27 -27
- package/src/components/traffic/trafficFilters.test.ts +18 -1
- package/src/components/traffic/trafficFilters.ts +30 -1
- package/src/components/ui/Omnibar.tsx +4 -1
- package/src/components/ui/RadarOmnibar.test.tsx +55 -2
- package/src/components/ui/RadarOmnibar.tsx +7 -1
- package/src/components/ui/SearchSyntaxHelp.test.tsx +9 -2
- package/src/components/ui/SearchSyntaxHelp.tsx +3 -2
- package/src/components/ui/UpdateNotification.test.tsx +23 -1
- package/src/components/ui/UpdateNotification.tsx +26 -2
- package/src/components/ui/omnibar-match.test.ts +7 -0
- package/src/components/ui/omnibar-match.ts +1 -0
- package/src/components/ui/searchCoverageNote.test.ts +17 -0
- package/src/components/ui/searchCoverageNote.ts +31 -7
- package/src/components/useContextSwitchFlow.tsx +9 -1
- package/src/components/workload/NodeCertificateEvidence.test.tsx +51 -0
- package/src/components/workload/NodeCertificateEvidence.tsx +44 -0
- package/src/components/workload/WorkloadView.tsx +51 -11
- package/src/context/ConnectionContext.test.ts +1 -0
- package/src/context/ConnectionContext.tsx +2 -2
- package/src/integrations/resourceHosts.test.tsx +2 -2
- package/src/integrations/resourceHosts.tsx +4 -0
- package/src/utils/namespacePick.test.ts +87 -0
- package/src/utils/namespacePick.ts +88 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useState, useRef, useEffect, useMemo, useCallback } from 'react'
|
|
2
2
|
import { createPortal } from 'react-dom'
|
|
3
|
-
import { X, Folder, File, Link2, ChevronRight, ChevronDown, AlertTriangle, Loader2, Search, Download, HardDrive, Shield, ShieldCheck, Terminal, Copy, Check, RefreshCw } from 'lucide-react'
|
|
3
|
+
import { X, Folder, File, Link2, ChevronRight, ChevronDown, AlertTriangle, Loader2, Search, Download, HardDrive, Shield, ShieldCheck, Terminal, Copy, Check, RefreshCw, WifiOff } from 'lucide-react'
|
|
4
4
|
import radarLoadingIcon from '@skyhook-io/k8s-ui/assets/radar/radar-icon-loading.svg'
|
|
5
5
|
import { assetUrl } from '@skyhook-io/k8s-ui'
|
|
6
6
|
import { clsx } from 'clsx'
|
|
@@ -78,6 +78,13 @@ export function ImageFilesystemModal({
|
|
|
78
78
|
// Detect auth errors from metadata fetch
|
|
79
79
|
const isAuthError = metadataError instanceof ApiError && metadataError.status === 401
|
|
80
80
|
const registryType = isAuthError ? (metadataError.data?.registryType as string) : undefined
|
|
81
|
+
const unavailable = metadataError instanceof ApiError ? registryUnavailable(metadataError.data) : undefined
|
|
82
|
+
|
|
83
|
+
// The server may pin a tag to the digest the Pod pulled. Later requests
|
|
84
|
+
// name that exact reference, so the listing and file downloads can't drift
|
|
85
|
+
// to whatever the tag points at by then.
|
|
86
|
+
const inspectImage = metadata?.image || image
|
|
87
|
+
const pulledDigest = inspectImage !== image ? inspectImage.split('@')[1] : undefined
|
|
81
88
|
|
|
82
89
|
// Use cached filesystem from metadata if available
|
|
83
90
|
const displayFilesystem: ImageFilesystem | undefined = metadata?.cached
|
|
@@ -89,14 +96,14 @@ export function ImageFilesystemModal({
|
|
|
89
96
|
setIsLoadingFilesystem(true)
|
|
90
97
|
setFilesystemError(null)
|
|
91
98
|
try {
|
|
92
|
-
const result = await fetchImageFilesystem(
|
|
99
|
+
const result = await fetchImageFilesystem(inspectImage, namespace, podName, pullSecrets)
|
|
93
100
|
setFilesystem(result)
|
|
94
101
|
} catch (err) {
|
|
95
102
|
setFilesystemError(err instanceof Error ? err : new Error('Failed to fetch filesystem'))
|
|
96
103
|
} finally {
|
|
97
104
|
setIsLoadingFilesystem(false)
|
|
98
105
|
}
|
|
99
|
-
}, [
|
|
106
|
+
}, [inspectImage, namespace, podName, pullSecrets])
|
|
100
107
|
|
|
101
108
|
// Reset state when modal closes or image changes
|
|
102
109
|
useEffect(() => {
|
|
@@ -153,6 +160,13 @@ export function ImageFilesystemModal({
|
|
|
153
160
|
{image}
|
|
154
161
|
</p>
|
|
155
162
|
</Tooltip>
|
|
163
|
+
{pulledDigest && (
|
|
164
|
+
<Tooltip content={inspectImage} wrapperClassName="!block w-full">
|
|
165
|
+
<p className="text-xs text-theme-text-tertiary mt-1 truncate">
|
|
166
|
+
Pulled digest: <span className="font-mono">{pulledDigest}</span>
|
|
167
|
+
</p>
|
|
168
|
+
</Tooltip>
|
|
169
|
+
)}
|
|
156
170
|
{(displayFilesystem?.platform || metadata?.platform) && (
|
|
157
171
|
<p className="text-xs text-theme-text-tertiary mt-1">
|
|
158
172
|
Platform: {displayFilesystem?.platform || metadata?.platform}
|
|
@@ -208,8 +222,16 @@ export function ImageFilesystemModal({
|
|
|
208
222
|
/>
|
|
209
223
|
)}
|
|
210
224
|
|
|
211
|
-
{
|
|
212
|
-
|
|
225
|
+
{unavailable && (
|
|
226
|
+
<RegistryUnavailable
|
|
227
|
+
{...unavailable}
|
|
228
|
+
liveFilesLinkShown={Boolean(onSwitchToPodFiles)}
|
|
229
|
+
onRetry={() => refetchMetadata()}
|
|
230
|
+
/>
|
|
231
|
+
)}
|
|
232
|
+
|
|
233
|
+
{/* Other errors keep the existing red error box */}
|
|
234
|
+
{error && !isAuthError && !unavailable && (
|
|
213
235
|
<div className="p-4 bg-red-500/10 border border-red-500/30 rounded-lg">
|
|
214
236
|
<div className="flex items-start gap-3">
|
|
215
237
|
<AlertTriangle className="w-5 h-5 text-red-400 shrink-0 mt-0.5" />
|
|
@@ -237,7 +259,7 @@ export function ImageFilesystemModal({
|
|
|
237
259
|
<FileTreeView
|
|
238
260
|
root={displayFilesystem.root}
|
|
239
261
|
searchQuery={searchQuery}
|
|
240
|
-
image={image}
|
|
262
|
+
image={displayFilesystem.image || inspectImage}
|
|
241
263
|
namespace={namespace}
|
|
242
264
|
podName={podName}
|
|
243
265
|
pullSecrets={pullSecrets}
|
|
@@ -513,6 +535,76 @@ function AuthenticationHelp({ image, registryType, onRetry }: AuthenticationHelp
|
|
|
513
535
|
)
|
|
514
536
|
}
|
|
515
537
|
|
|
538
|
+
// ============================================================================
|
|
539
|
+
// Registry Unavailable Component (image Radar can't download)
|
|
540
|
+
// ============================================================================
|
|
541
|
+
|
|
542
|
+
interface RegistryUnavailableInfo {
|
|
543
|
+
reason: 'node_only' | 'registry_unreachable'
|
|
544
|
+
registry: string
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
function registryUnavailable(data: Record<string, unknown> | undefined): RegistryUnavailableInfo | undefined {
|
|
548
|
+
const reason = data?.reason
|
|
549
|
+
const registry = typeof data?.registry === 'string' ? data.registry : ''
|
|
550
|
+
if (reason === 'node_only' || reason === 'registry_unreachable') return { reason, registry }
|
|
551
|
+
return undefined
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
interface RegistryUnavailableProps extends RegistryUnavailableInfo {
|
|
555
|
+
liveFilesLinkShown: boolean
|
|
556
|
+
onRetry: () => void
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
function RegistryUnavailable({ reason, registry, liveFilesLinkShown, onRetry }: RegistryUnavailableProps) {
|
|
560
|
+
const liveFiles = liveFilesLinkShown && (
|
|
561
|
+
<p className="text-xs text-theme-text-tertiary text-center max-w-md mb-2">
|
|
562
|
+
To see the files now, use Browse live files from running pod below.
|
|
563
|
+
</p>
|
|
564
|
+
)
|
|
565
|
+
|
|
566
|
+
if (reason === 'node_only') {
|
|
567
|
+
return (
|
|
568
|
+
<div className="flex flex-col items-center justify-center py-8">
|
|
569
|
+
<HardDrive className="w-16 h-16 text-amber-400 mb-4" />
|
|
570
|
+
<h4 className="text-lg font-medium text-theme-text-primary mb-2">
|
|
571
|
+
This image was added to the node, not pulled
|
|
572
|
+
</h4>
|
|
573
|
+
<p className="text-sm text-theme-text-secondary text-center max-w-md mb-2">
|
|
574
|
+
The node didn't pull this image from a registry. It was added to the node directly, for example with <span className="font-mono">kind load</span> or <span className="font-mono">ctr images import</span>. Radar can only open images it downloads from a registry, and it couldn't get this one from <span className="inline-code">{registry}</span>.
|
|
575
|
+
</p>
|
|
576
|
+
<p className="text-xs text-theme-text-tertiary text-center max-w-md mb-2">
|
|
577
|
+
To browse it here, push the image to a registry Radar can reach and run the Pod from there.
|
|
578
|
+
</p>
|
|
579
|
+
{liveFiles}
|
|
580
|
+
</div>
|
|
581
|
+
)
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
return (
|
|
585
|
+
<div className="flex flex-col items-center justify-center py-8">
|
|
586
|
+
<WifiOff className="w-16 h-16 text-amber-400 mb-4" />
|
|
587
|
+
<h4 className="text-lg font-medium text-theme-text-primary mb-2">
|
|
588
|
+
Radar can't reach this image's registry
|
|
589
|
+
</h4>
|
|
590
|
+
<p className="text-sm text-theme-text-secondary text-center max-w-md mb-2">
|
|
591
|
+
The connection failed while fetching this image from <span className="inline-code">{registry}</span>. If your nodes pull images through a mirror or an internal copy of this registry, Radar doesn't use it, so it can't open this image.
|
|
592
|
+
</p>
|
|
593
|
+
<p className="text-xs text-theme-text-tertiary text-center max-w-md mb-2">
|
|
594
|
+
If <span className="inline-code">{registry}</span> should be reachable from where Radar runs, check the connection and retry.
|
|
595
|
+
</p>
|
|
596
|
+
{liveFiles}
|
|
597
|
+
<button
|
|
598
|
+
onClick={onRetry}
|
|
599
|
+
className="flex items-center gap-2 px-4 py-2 mt-4 text-sm btn-brand rounded-lg"
|
|
600
|
+
>
|
|
601
|
+
<RefreshCw className="w-4 h-4" />
|
|
602
|
+
Retry
|
|
603
|
+
</button>
|
|
604
|
+
</div>
|
|
605
|
+
)
|
|
606
|
+
}
|
|
607
|
+
|
|
516
608
|
function formatAuthMethod(method: string): string {
|
|
517
609
|
switch (method) {
|
|
518
610
|
case 'google': return 'Google Cloud'
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { Link } from 'react-router-dom'
|
|
2
|
+
import { Upload, Loader2 } from 'lucide-react'
|
|
3
|
+
import { AlertBanner } from '@skyhook-io/k8s-ui'
|
|
4
|
+
import { formatBytes } from '../../utils/format'
|
|
5
|
+
import { resourcePath } from '../../utils/navigation'
|
|
6
|
+
import { Tooltip } from '../ui/Tooltip'
|
|
7
|
+
import { POD_FILE_PERSISTENCE_NOTE, type MountHint } from './pod-file-upload'
|
|
8
|
+
|
|
9
|
+
export type UploadState =
|
|
10
|
+
| { phase: 'idle' }
|
|
11
|
+
| { phase: 'confirm'; name: string; dir: string; size: number }
|
|
12
|
+
| { phase: 'uploading'; name: string; dir: string; sent: number; total: number }
|
|
13
|
+
| { phase: 'saving'; name: string; dir: string }
|
|
14
|
+
| { phase: 'saved'; path: string; replaced: boolean }
|
|
15
|
+
| { phase: 'error'; name: string; message: string }
|
|
16
|
+
|
|
17
|
+
export function isUploadBusy(state: UploadState): boolean {
|
|
18
|
+
return state.phase === 'uploading' || state.phase === 'saving' || state.phase === 'confirm'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface UploadButtonProps {
|
|
22
|
+
blocked: MountHint | null
|
|
23
|
+
busy: boolean
|
|
24
|
+
/** The listing for the selected container is still loading. */
|
|
25
|
+
loading?: boolean
|
|
26
|
+
onClick: () => void
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function PodFileUploadButton({ blocked, busy, loading = false, onClick }: UploadButtonProps) {
|
|
30
|
+
const disabled = busy || loading || blocked !== null
|
|
31
|
+
const tip = blocked ? blocked.reason
|
|
32
|
+
: busy ? 'An upload is in progress'
|
|
33
|
+
: loading ? 'Loading the listing…'
|
|
34
|
+
: 'Upload a file into this directory (or drop one on the list)'
|
|
35
|
+
return (
|
|
36
|
+
<Tooltip content={tip}>
|
|
37
|
+
<button
|
|
38
|
+
type="button"
|
|
39
|
+
onClick={onClick}
|
|
40
|
+
disabled={disabled}
|
|
41
|
+
aria-disabled={disabled}
|
|
42
|
+
className="btn-brand inline-flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium mr-2 disabled:opacity-50 disabled:pointer-events-none"
|
|
43
|
+
>
|
|
44
|
+
<Upload className="w-4 h-4" />
|
|
45
|
+
Upload
|
|
46
|
+
</button>
|
|
47
|
+
</Tooltip>
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface UploadNoticesProps {
|
|
52
|
+
namespace: string
|
|
53
|
+
blocked: MountHint | null
|
|
54
|
+
onNavigateAway: () => void
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The persistence note, plus why uploads are off here when the pod spec says so. */
|
|
58
|
+
export function PodFileUploadNotices({ namespace, blocked, onNavigateAway }: UploadNoticesProps) {
|
|
59
|
+
return (
|
|
60
|
+
<>
|
|
61
|
+
<AlertBanner variant="info" title="Uploads change the live container" message={POD_FILE_PERSISTENCE_NOTE} className="mb-3" />
|
|
62
|
+
{blocked && (
|
|
63
|
+
<AlertBanner
|
|
64
|
+
variant="warning"
|
|
65
|
+
title="Uploads are off in this directory"
|
|
66
|
+
message={blocked.reason}
|
|
67
|
+
className="mb-3"
|
|
68
|
+
action={blocked.source ? (
|
|
69
|
+
<Link
|
|
70
|
+
to={resourcePath({ kind: blocked.source.kind, namespace, name: blocked.source.name })}
|
|
71
|
+
onClick={onNavigateAway}
|
|
72
|
+
className="text-xs text-accent hover:underline"
|
|
73
|
+
>
|
|
74
|
+
Open {blocked.source.kind} {blocked.source.name}
|
|
75
|
+
</Link>
|
|
76
|
+
) : undefined}
|
|
77
|
+
/>
|
|
78
|
+
)}
|
|
79
|
+
</>
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
interface UploadStatusProps {
|
|
84
|
+
state: UploadState
|
|
85
|
+
onConfirmReplace: () => void
|
|
86
|
+
onCancel: () => void
|
|
87
|
+
onDismiss: () => void
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function PodFileUploadStatus({ state, onConfirmReplace, onCancel, onDismiss }: UploadStatusProps) {
|
|
91
|
+
switch (state.phase) {
|
|
92
|
+
case 'idle':
|
|
93
|
+
return null
|
|
94
|
+
case 'confirm':
|
|
95
|
+
return (
|
|
96
|
+
<AlertBanner
|
|
97
|
+
variant="warning"
|
|
98
|
+
title={`Replace ${state.name}?`}
|
|
99
|
+
message={`${state.dir === '/' ? '' : state.dir}/${state.name} already exists. Uploading ${formatBytes(state.size)} replaces it in the running container; its owner and permissions are kept, but not ACLs or extended attributes.`}
|
|
100
|
+
className="mb-3"
|
|
101
|
+
>
|
|
102
|
+
<div className="flex gap-2 mt-2">
|
|
103
|
+
<button type="button" onClick={onConfirmReplace} className="btn-brand px-3 py-1 text-xs font-medium">Replace</button>
|
|
104
|
+
<button type="button" onClick={onCancel} className="px-3 py-1 text-xs rounded border border-theme-border text-theme-text-secondary hover:bg-theme-hover">Cancel</button>
|
|
105
|
+
</div>
|
|
106
|
+
</AlertBanner>
|
|
107
|
+
)
|
|
108
|
+
case 'uploading': {
|
|
109
|
+
const pct = state.total > 0 ? Math.min(100, Math.round((state.sent / state.total) * 100)) : 0
|
|
110
|
+
return (
|
|
111
|
+
<div className="mb-3 p-3 border border-theme-border rounded-lg bg-theme-surface" role="status">
|
|
112
|
+
<div className="flex items-center justify-between gap-3 text-sm">
|
|
113
|
+
<span className="min-w-0 truncate text-theme-text-primary">Uploading {state.name}</span>
|
|
114
|
+
<span className="shrink-0 text-xs text-theme-text-tertiary">{formatBytes(state.sent)} of {formatBytes(state.total)}</span>
|
|
115
|
+
<button type="button" onClick={onCancel} className="shrink-0 px-2 py-0.5 text-xs rounded border border-theme-border text-theme-text-secondary hover:bg-theme-hover">Cancel</button>
|
|
116
|
+
</div>
|
|
117
|
+
<div className="mt-2 h-1.5 rounded bg-theme-elevated overflow-hidden" role="progressbar" aria-valuemin={0} aria-valuemax={100} aria-valuenow={pct}>
|
|
118
|
+
<div className="h-full bg-accent" style={{ width: `${pct}%` }} />
|
|
119
|
+
</div>
|
|
120
|
+
</div>
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
case 'saving':
|
|
124
|
+
return (
|
|
125
|
+
<div className="mb-3 p-3 border border-theme-border rounded-lg bg-theme-surface flex items-center gap-2 text-sm text-theme-text-primary" role="status">
|
|
126
|
+
<Loader2 className="w-4 h-4 animate-spin shrink-0" />
|
|
127
|
+
<span className="truncate">Saving {state.name} in the container…</span>
|
|
128
|
+
</div>
|
|
129
|
+
)
|
|
130
|
+
case 'saved':
|
|
131
|
+
return (
|
|
132
|
+
<AlertBanner
|
|
133
|
+
variant="success"
|
|
134
|
+
title={state.replaced ? `Replaced ${state.path}` : `Saved ${state.path}`}
|
|
135
|
+
className="mb-3"
|
|
136
|
+
action={<button type="button" onClick={onDismiss} className="text-xs text-theme-text-secondary hover:underline">Dismiss</button>}
|
|
137
|
+
/>
|
|
138
|
+
)
|
|
139
|
+
case 'error':
|
|
140
|
+
return (
|
|
141
|
+
<AlertBanner
|
|
142
|
+
variant="error"
|
|
143
|
+
title={`Could not upload ${state.name}`}
|
|
144
|
+
message={state.message}
|
|
145
|
+
className="mb-3"
|
|
146
|
+
action={<button type="button" onClick={onDismiss} className="text-xs text-theme-text-secondary hover:underline">Dismiss</button>}
|
|
147
|
+
/>
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -13,6 +13,20 @@ import { openFile, openFolder } from '../../utils/desktop-open-folder'
|
|
|
13
13
|
import { useToast } from '../ui/Toast'
|
|
14
14
|
import { Tooltip } from '../ui/Tooltip'
|
|
15
15
|
import { PodFilePreview, PREVIEW_BYTE_CAP } from './PodFilePreview'
|
|
16
|
+
import { useNamespacedCapabilities } from '../../contexts/CapabilitiesContext'
|
|
17
|
+
import { useRadarFeature } from '../../api/client'
|
|
18
|
+
import {
|
|
19
|
+
canShowUpload,
|
|
20
|
+
fileMountHint,
|
|
21
|
+
isValidUploadName,
|
|
22
|
+
oversizeMessage,
|
|
23
|
+
PodFileUploadError,
|
|
24
|
+
UPLOAD_CANCELLED,
|
|
25
|
+
uploadBlockedHint,
|
|
26
|
+
uploadPodFile,
|
|
27
|
+
uploadTarget,
|
|
28
|
+
} from './pod-file-upload'
|
|
29
|
+
import { isUploadBusy, PodFileUploadButton, PodFileUploadNotices, PodFileUploadStatus, type UploadState } from './PodFileUploadPanel'
|
|
16
30
|
|
|
17
31
|
interface PodFilesystem {
|
|
18
32
|
root: FileNode
|
|
@@ -128,6 +142,8 @@ interface PodFilesystemModalProps {
|
|
|
128
142
|
containers: string[]
|
|
129
143
|
initialContainer?: string
|
|
130
144
|
onSwitchToImageFiles?: (containerName: string) => void
|
|
145
|
+
/** The pod object; its volume mounts tell where uploads cannot work. */
|
|
146
|
+
pod?: unknown
|
|
131
147
|
}
|
|
132
148
|
|
|
133
149
|
export function PodFilesystemModal({
|
|
@@ -138,30 +154,57 @@ export function PodFilesystemModal({
|
|
|
138
154
|
containers,
|
|
139
155
|
initialContainer,
|
|
140
156
|
onSwitchToImageFiles,
|
|
157
|
+
pod,
|
|
141
158
|
}: PodFilesystemModalProps) {
|
|
142
159
|
const dialogRef = useRef<HTMLDivElement>(null)
|
|
143
160
|
const [searchQuery, setSearchQuery] = useState('')
|
|
144
161
|
const [selectedContainer, setSelectedContainer] = useState(initialContainer || containers[0] || '')
|
|
145
162
|
const [currentPath, setCurrentPath] = useState('/')
|
|
146
163
|
const [filesystem, setFilesystem] = useState<PodFilesystem | null>(null)
|
|
164
|
+
// The container the shown listing came from; it lags selectedContainer
|
|
165
|
+
// while a switch is loading.
|
|
166
|
+
const [listedContainer, setListedContainer] = useState<string | null>(null)
|
|
167
|
+
const loadSeq = useRef(0)
|
|
147
168
|
const [isLoading, setIsLoading] = useState(false)
|
|
148
169
|
const [error, setError] = useState<string | null>(null)
|
|
149
170
|
// The file being viewed in place of the listing; null shows the directory.
|
|
150
171
|
const [previewFile, setPreviewFile] = useState<FileNode | null>(null)
|
|
151
172
|
const toast = useToast()
|
|
152
173
|
|
|
174
|
+
const { canExec } = useNamespacedCapabilities(namespace)
|
|
175
|
+
const { support: uploadSupport, guard: guardUpload } = useRadarFeature('podFileUpload')
|
|
176
|
+
const uploadEnabled = canShowUpload({ canExec, featureSupported: uploadSupport === 'supported' })
|
|
177
|
+
const [upload, setUpload] = useState<UploadState>({ phase: 'idle' })
|
|
178
|
+
const [dragging, setDragging] = useState(false)
|
|
179
|
+
const pendingFile = useRef<File | null>(null)
|
|
180
|
+
const uploadAbort = useRef<AbortController | null>(null)
|
|
181
|
+
const fileInputRef = useRef<HTMLInputElement>(null)
|
|
182
|
+
const listRef = useRef<HTMLDivElement>(null)
|
|
183
|
+
const currentPathRef = useRef(currentPath)
|
|
184
|
+
useEffect(() => { currentPathRef.current = currentPath }, [currentPath])
|
|
185
|
+
const uploadRef = useRef(upload)
|
|
186
|
+
useEffect(() => { uploadRef.current = upload }, [upload])
|
|
187
|
+
// Uploads that had sent every byte when the dialog closed or the container
|
|
188
|
+
// changed. The container may already be committing them, so they run on and
|
|
189
|
+
// report through a toast instead of being cancelled.
|
|
190
|
+
const detachedUploads = useRef(new Set<AbortController>())
|
|
191
|
+
|
|
153
192
|
const loadDirectory = useCallback(async (dirPath: string) => {
|
|
193
|
+
const seq = ++loadSeq.current
|
|
154
194
|
setPreviewFile(null)
|
|
155
195
|
setIsLoading(true)
|
|
156
196
|
setError(null)
|
|
157
197
|
try {
|
|
158
198
|
const result = await fetchPodFiles(namespace, podName, selectedContainer, dirPath)
|
|
199
|
+
if (seq !== loadSeq.current) return
|
|
159
200
|
setFilesystem(result)
|
|
160
201
|
setCurrentPath(dirPath)
|
|
202
|
+
setListedContainer(selectedContainer)
|
|
161
203
|
} catch (err) {
|
|
204
|
+
if (seq !== loadSeq.current) return
|
|
162
205
|
setError(err instanceof Error ? err.message : 'Failed to list files')
|
|
163
206
|
} finally {
|
|
164
|
-
setIsLoading(false)
|
|
207
|
+
if (seq === loadSeq.current) setIsLoading(false)
|
|
165
208
|
}
|
|
166
209
|
}, [namespace, podName, selectedContainer])
|
|
167
210
|
|
|
@@ -177,6 +220,7 @@ export function PodFilesystemModal({
|
|
|
177
220
|
if (!open) {
|
|
178
221
|
setSearchQuery('')
|
|
179
222
|
setFilesystem(null)
|
|
223
|
+
setListedContainer(null)
|
|
180
224
|
setError(null)
|
|
181
225
|
setIsLoading(false)
|
|
182
226
|
setCurrentPath('/')
|
|
@@ -185,6 +229,157 @@ export function PodFilesystemModal({
|
|
|
185
229
|
}
|
|
186
230
|
}, [open, initialContainer, containers])
|
|
187
231
|
|
|
232
|
+
// Leaving the dialog or the container abandons an upload that has not
|
|
233
|
+
// finished sending; the server then writes nothing. One that is already
|
|
234
|
+
// saving is left to finish.
|
|
235
|
+
useEffect(() => {
|
|
236
|
+
if (!open) return
|
|
237
|
+
const detached = detachedUploads.current
|
|
238
|
+
return () => {
|
|
239
|
+
const abort = uploadAbort.current
|
|
240
|
+
if (abort && uploadRef.current.phase === 'saving') detached.add(abort)
|
|
241
|
+
else abort?.abort()
|
|
242
|
+
uploadAbort.current = null
|
|
243
|
+
pendingFile.current = null
|
|
244
|
+
setUpload({ phase: 'idle' })
|
|
245
|
+
}
|
|
246
|
+
}, [open, selectedContainer])
|
|
247
|
+
|
|
248
|
+
const blockedHint = useMemo(
|
|
249
|
+
() => (uploadEnabled ? uploadBlockedHint(pod, selectedContainer, currentPath) : null),
|
|
250
|
+
[uploadEnabled, pod, selectedContainer, currentPath],
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
const sendFile = useCallback(async (file: File, dir: string, overwrite: boolean) => {
|
|
254
|
+
const abort = new AbortController()
|
|
255
|
+
uploadAbort.current = abort
|
|
256
|
+
setUpload({ phase: 'uploading', name: file.name, dir, sent: 0, total: file.size })
|
|
257
|
+
try {
|
|
258
|
+
const result = await guardUpload(() => uploadPodFile({
|
|
259
|
+
namespace,
|
|
260
|
+
podName,
|
|
261
|
+
container: selectedContainer,
|
|
262
|
+
dir,
|
|
263
|
+
file,
|
|
264
|
+
name: file.name,
|
|
265
|
+
overwrite,
|
|
266
|
+
signal: abort.signal,
|
|
267
|
+
onProgress: (sent, total) => {
|
|
268
|
+
if (abort.signal.aborted) return
|
|
269
|
+
// Every byte is out; what remains is the container committing it.
|
|
270
|
+
setUpload(sent >= total
|
|
271
|
+
? { phase: 'saving', name: file.name, dir }
|
|
272
|
+
: { phase: 'uploading', name: file.name, dir, sent, total })
|
|
273
|
+
},
|
|
274
|
+
}))
|
|
275
|
+
if (detachedUploads.current.delete(abort)) {
|
|
276
|
+
toast.showSuccess(result.replaced ? 'File replaced' : 'File uploaded', result.path)
|
|
277
|
+
return
|
|
278
|
+
}
|
|
279
|
+
if (uploadAbort.current !== abort) return
|
|
280
|
+
setUpload({ phase: 'saved', path: result.path, replaced: result.replaced })
|
|
281
|
+
if (dir === currentPathRef.current) loadDirectory(dir)
|
|
282
|
+
} catch (err) {
|
|
283
|
+
if (detachedUploads.current.delete(abort)) {
|
|
284
|
+
toast.showError(`Could not upload ${file.name}`, err instanceof Error ? err.message : String(err))
|
|
285
|
+
return
|
|
286
|
+
}
|
|
287
|
+
if (uploadAbort.current !== abort) return
|
|
288
|
+
if (err instanceof PodFileUploadError && err.code === UPLOAD_CANCELLED) {
|
|
289
|
+
setUpload({ phase: 'idle' })
|
|
290
|
+
return
|
|
291
|
+
}
|
|
292
|
+
setUpload({ phase: 'error', name: file.name, message: err instanceof Error ? err.message : String(err) })
|
|
293
|
+
} finally {
|
|
294
|
+
if (uploadAbort.current === abort) uploadAbort.current = null
|
|
295
|
+
}
|
|
296
|
+
}, [guardUpload, namespace, podName, selectedContainer, loadDirectory, toast])
|
|
297
|
+
|
|
298
|
+
const listingReady = !isLoading && !!filesystem?.root && listedContainer === selectedContainer
|
|
299
|
+
|
|
300
|
+
const startUpload = useCallback((file: File) => {
|
|
301
|
+
if (!listingReady) return
|
|
302
|
+
const dir = currentPath
|
|
303
|
+
if (!isValidUploadName(file.name)) {
|
|
304
|
+
setUpload({ phase: 'error', name: file.name, message: 'That file name cannot be used in the container.' })
|
|
305
|
+
return
|
|
306
|
+
}
|
|
307
|
+
const oversize = oversizeMessage(file.size)
|
|
308
|
+
if (oversize) {
|
|
309
|
+
setUpload({ phase: 'error', name: file.name, message: oversize })
|
|
310
|
+
return
|
|
311
|
+
}
|
|
312
|
+
const filePath = dir === '/' ? `/${file.name}` : `${dir}/${file.name}`
|
|
313
|
+
const mounted = fileMountHint(pod, selectedContainer, filePath)
|
|
314
|
+
if (mounted) {
|
|
315
|
+
setUpload({ phase: 'error', name: file.name, message: mounted.reason })
|
|
316
|
+
return
|
|
317
|
+
}
|
|
318
|
+
const target = uploadTarget(filesystem?.root, file.name)
|
|
319
|
+
if (target.kind === 'refuse') {
|
|
320
|
+
setUpload({ phase: 'error', name: file.name, message: target.reason })
|
|
321
|
+
return
|
|
322
|
+
}
|
|
323
|
+
if (target.kind === 'replace') {
|
|
324
|
+
pendingFile.current = file
|
|
325
|
+
setUpload({ phase: 'confirm', name: file.name, dir, size: file.size })
|
|
326
|
+
return
|
|
327
|
+
}
|
|
328
|
+
sendFile(file, dir, false)
|
|
329
|
+
}, [listingReady, currentPath, pod, selectedContainer, filesystem, sendFile])
|
|
330
|
+
|
|
331
|
+
const confirmReplace = useCallback(() => {
|
|
332
|
+
const file = pendingFile.current
|
|
333
|
+
pendingFile.current = null
|
|
334
|
+
if (file && upload.phase === 'confirm') sendFile(file, upload.dir, true)
|
|
335
|
+
}, [sendFile, upload])
|
|
336
|
+
|
|
337
|
+
const cancelUpload = useCallback(() => {
|
|
338
|
+
pendingFile.current = null
|
|
339
|
+
const abort = uploadAbort.current
|
|
340
|
+
uploadAbort.current = null
|
|
341
|
+
abort?.abort()
|
|
342
|
+
setUpload({ phase: 'idle' })
|
|
343
|
+
}, [])
|
|
344
|
+
|
|
345
|
+
const uploadHere = uploadEnabled && !previewFile && listingReady && !blockedHint && !isUploadBusy(upload)
|
|
346
|
+
// A file dropped anywhere in the dialog must never reach the browser, which
|
|
347
|
+
// would open it in place of Radar; only a drop on the listing uploads it.
|
|
348
|
+
const ownsFileDrag = (e: React.DragEvent) => uploadEnabled && e.dataTransfer.types.includes('Files')
|
|
349
|
+
const overList = (e: React.DragEvent) => !!listRef.current?.contains(e.target as Node)
|
|
350
|
+
|
|
351
|
+
const handleDragOver = (e: React.DragEvent) => {
|
|
352
|
+
if (!ownsFileDrag(e)) return
|
|
353
|
+
e.preventDefault()
|
|
354
|
+
const accept = uploadHere && overList(e)
|
|
355
|
+
e.dataTransfer.dropEffect = accept ? 'copy' : 'none'
|
|
356
|
+
if (accept !== dragging) setDragging(accept)
|
|
357
|
+
}
|
|
358
|
+
const handleDragLeave = (e: React.DragEvent) => {
|
|
359
|
+
if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setDragging(false)
|
|
360
|
+
}
|
|
361
|
+
const handleDrop = (e: React.DragEvent) => {
|
|
362
|
+
setDragging(false)
|
|
363
|
+
if (!ownsFileDrag(e)) return
|
|
364
|
+
e.preventDefault()
|
|
365
|
+
if (!overList(e)) return
|
|
366
|
+
if (!uploadHere) {
|
|
367
|
+
if (blockedHint) setUpload({ phase: 'error', name: 'the file', message: blockedHint.reason })
|
|
368
|
+
return
|
|
369
|
+
}
|
|
370
|
+
const items = Array.from(e.dataTransfer.items ?? [])
|
|
371
|
+
if (items.some((item) => item.webkitGetAsEntry?.()?.isDirectory)) {
|
|
372
|
+
setUpload({ phase: 'error', name: 'folder', message: 'Folders cannot be uploaded; drop a single file.' })
|
|
373
|
+
return
|
|
374
|
+
}
|
|
375
|
+
const files = Array.from(e.dataTransfer.files)
|
|
376
|
+
if (files.length !== 1) {
|
|
377
|
+
setUpload({ phase: 'error', name: `${files.length} files`, message: 'Drop one file at a time.' })
|
|
378
|
+
return
|
|
379
|
+
}
|
|
380
|
+
startUpload(files[0])
|
|
381
|
+
}
|
|
382
|
+
|
|
188
383
|
// ESC steps back one level: out of a file to its listing, then out of the
|
|
189
384
|
// dialog. One listener owns both so the two can never race.
|
|
190
385
|
useEffect(() => {
|
|
@@ -225,7 +420,12 @@ export function PodFilesystemModal({
|
|
|
225
420
|
}
|
|
226
421
|
|
|
227
422
|
return createPortal(
|
|
228
|
-
<div
|
|
423
|
+
<div
|
|
424
|
+
className="fixed inset-0 z-[100] flex items-center justify-center"
|
|
425
|
+
onDragOver={handleDragOver}
|
|
426
|
+
onDragLeave={handleDragLeave}
|
|
427
|
+
onDrop={handleDrop}
|
|
428
|
+
>
|
|
229
429
|
{/* Backdrop */}
|
|
230
430
|
<div className="absolute inset-0 bg-black/60 backdrop-blur-sm" onClick={onClose} />
|
|
231
431
|
|
|
@@ -272,6 +472,29 @@ export function PodFilesystemModal({
|
|
|
272
472
|
</div>
|
|
273
473
|
)}
|
|
274
474
|
|
|
475
|
+
{uploadEnabled && !previewFile && showFilesystem && (
|
|
476
|
+
<>
|
|
477
|
+
<PodFileUploadButton
|
|
478
|
+
blocked={blockedHint}
|
|
479
|
+
busy={isUploadBusy(upload)}
|
|
480
|
+
loading={!listingReady}
|
|
481
|
+
onClick={() => fileInputRef.current?.click()}
|
|
482
|
+
/>
|
|
483
|
+
<input
|
|
484
|
+
ref={fileInputRef}
|
|
485
|
+
type="file"
|
|
486
|
+
className="hidden"
|
|
487
|
+
aria-hidden="true"
|
|
488
|
+
tabIndex={-1}
|
|
489
|
+
onChange={(e) => {
|
|
490
|
+
const file = e.target.files?.[0]
|
|
491
|
+
e.target.value = ''
|
|
492
|
+
if (file) startUpload(file)
|
|
493
|
+
}}
|
|
494
|
+
/>
|
|
495
|
+
</>
|
|
496
|
+
)}
|
|
497
|
+
|
|
275
498
|
{/* Container selector */}
|
|
276
499
|
{!previewFile && containers.length > 1 && (
|
|
277
500
|
<select
|
|
@@ -347,7 +570,27 @@ export function PodFilesystemModal({
|
|
|
347
570
|
/>
|
|
348
571
|
</div>
|
|
349
572
|
) : (
|
|
350
|
-
<div
|
|
573
|
+
<div
|
|
574
|
+
ref={listRef}
|
|
575
|
+
className={clsx('relative flex-1 min-h-0 overflow-y-auto p-4', dragging && 'ring-2 ring-inset ring-accent')}
|
|
576
|
+
>
|
|
577
|
+
{uploadEnabled && showFilesystem && (
|
|
578
|
+
<>
|
|
579
|
+
<PodFileUploadNotices namespace={namespace} blocked={blockedHint} onNavigateAway={onClose} />
|
|
580
|
+
<PodFileUploadStatus
|
|
581
|
+
state={upload}
|
|
582
|
+
onConfirmReplace={confirmReplace}
|
|
583
|
+
onCancel={cancelUpload}
|
|
584
|
+
onDismiss={() => setUpload({ phase: 'idle' })}
|
|
585
|
+
/>
|
|
586
|
+
</>
|
|
587
|
+
)}
|
|
588
|
+
{dragging && (
|
|
589
|
+
<div className="pointer-events-none absolute inset-0 flex items-center justify-center bg-theme-base/80 text-sm font-medium text-theme-text-primary">
|
|
590
|
+
Drop to upload into {currentPath}
|
|
591
|
+
</div>
|
|
592
|
+
)}
|
|
593
|
+
|
|
351
594
|
{/* Loading */}
|
|
352
595
|
{isLoading && <PaneLoader label="Loading files…" className="h-full" />}
|
|
353
596
|
|