@skyhook-io/radar-app 1.20.0 → 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 +18 -11
- 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 +287 -21
- package/src/api/helmInventory.test.tsx +108 -0
- 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 +5 -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/curl/ServiceCurlAvailability.test.tsx +32 -0
- package/src/components/curl/ServiceCurlButton.tsx +2 -2
- package/src/components/diagnose/InvestigationView.tsx +12 -3
- package/src/components/diagnose/investigationCase.test.tsx +41 -0
- package/src/components/diagnose/investigationEvidence/adapters/coverage.test.tsx +72 -0
- package/src/components/diagnose/investigationEvidence/adapters/helm.test.tsx +52 -0
- package/src/components/diagnose/investigationEvidence/adapters/helm.ts +61 -16
- package/src/components/diagnose/investigationEvidence/adapters/listings.ts +34 -4
- package/src/components/diagnose/investigationEvidence/adapters/resource.ts +3 -2
- 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/HelmDrawerFrame.tsx +101 -0
- package/src/components/helm/HelmDrawerRouting.test.tsx +86 -0
- package/src/components/helm/HelmReleaseDrawer.tsx +47 -98
- package/src/components/helm/HelmView.tsx +215 -71
- package/src/components/helm/NotCheckedBadge.test.tsx +62 -0
- package/src/components/helm/NotCheckedBadge.tsx +39 -0
- package/src/components/helm/ObservedHelmNotice.tsx +146 -0
- package/src/components/helm/ObservedHelmRelease.test.tsx +261 -0
- package/src/components/helm/ObservedHelmReleaseDrawer.test.tsx +80 -0
- package/src/components/helm/ObservedHelmReleaseDrawer.tsx +228 -0
- package/src/components/helm/OwnedResources.test.tsx +86 -0
- package/src/components/helm/OwnedResources.tsx +69 -10
- package/src/components/home/ClusterHealthCard.heading.test.tsx +72 -0
- package/src/components/home/ClusterHealthCard.restricted.test.tsx +76 -0
- package/src/components/home/ClusterHealthCard.test.ts +44 -1
- package/src/components/home/ClusterHealthCard.tsx +49 -14
- package/src/components/home/HelmSummary.tsx +38 -19
- package/src/components/home/HelmSummary.unread.test.ts +16 -0
- package/src/components/home/HomeAgentBlock.tsx +7 -0
- package/src/components/home/MCPSetupDialog.test.tsx +38 -12
- package/src/components/home/MCPSetupDialog.tsx +5 -2
- package/src/components/home/mcpToolCatalog.ts +45 -5
- package/src/components/issues/uncheckedSources.test.ts +2 -0
- package/src/components/issues/uncheckedSources.ts +3 -0
- 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/resources/renderers/ServiceRenderer.test.tsx +15 -2
- package/src/components/resources/renderers/ServiceRenderer.tsx +1 -1
- package/src/components/resources/renderers/ValidatingAdmissionPolicyRenderer.test.tsx +160 -0
- package/src/components/resources/renderers/ValidatingAdmissionPolicyRenderer.tsx +128 -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/whats-new/releaseNotes.ts +1 -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/contexts/CapabilitiesContext.tsx +2 -0
- package/src/hooks/useResolvedGitOpsOwner.test.ts +22 -0
- package/src/hooks/useResolvedGitOpsOwner.ts +6 -3
- package/src/integrations/resourceHosts.test.tsx +2 -2
- package/src/integrations/resourceHosts.tsx +9 -0
- package/src/utils/namespacePick.test.ts +87 -0
- package/src/utils/namespacePick.ts +88 -0
|
@@ -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
|
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { renderToStaticMarkup } from 'react-dom/server'
|
|
3
|
+
import { MemoryRouter } from 'react-router-dom'
|
|
4
|
+
import type { FileNode } from '../../types'
|
|
5
|
+
import {
|
|
6
|
+
canShowUpload,
|
|
7
|
+
fileMountHint,
|
|
8
|
+
isValidUploadName,
|
|
9
|
+
oversizeMessage,
|
|
10
|
+
POD_FILE_PERSISTENCE_NOTE,
|
|
11
|
+
uploadBlockedHint,
|
|
12
|
+
uploadResponseError,
|
|
13
|
+
uploadTarget,
|
|
14
|
+
} from './pod-file-upload'
|
|
15
|
+
import { PodFileUploadButton, PodFileUploadNotices, PodFileUploadStatus } from './PodFileUploadPanel'
|
|
16
|
+
|
|
17
|
+
describe('canShowUpload', () => {
|
|
18
|
+
it('needs exec and a server that serves the endpoint', () => {
|
|
19
|
+
expect(canShowUpload({ canExec: true, featureSupported: true })).toBe(true)
|
|
20
|
+
expect(canShowUpload({ canExec: false, featureSupported: true })).toBe(false)
|
|
21
|
+
expect(canShowUpload({ canExec: true, featureSupported: false })).toBe(false)
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const pod = {
|
|
26
|
+
spec: {
|
|
27
|
+
containers: [
|
|
28
|
+
{
|
|
29
|
+
name: 'app',
|
|
30
|
+
volumeMounts: [
|
|
31
|
+
{ name: 'cfg', mountPath: '/etc/app' },
|
|
32
|
+
{ name: 'tls', mountPath: '/etc/tls/' },
|
|
33
|
+
{ name: 'data', mountPath: '/data' },
|
|
34
|
+
{ name: 'shared', mountPath: '/shared', readOnly: true },
|
|
35
|
+
{ name: 'one', mountPath: '/etc/nginx/nginx.conf' },
|
|
36
|
+
{ name: 'proj', mountPath: '/var/run/proj' },
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
{ name: 'locked', securityContext: { readOnlyRootFilesystem: true }, volumeMounts: [{ name: 'data', mountPath: '/data' }] },
|
|
40
|
+
],
|
|
41
|
+
initContainers: [
|
|
42
|
+
{ name: 'sidecar', restartPolicy: 'Always', volumeMounts: [{ name: 'cfg', mountPath: '/config' }] },
|
|
43
|
+
],
|
|
44
|
+
volumes: [
|
|
45
|
+
{ name: 'cfg', configMap: { name: 'app-config' } },
|
|
46
|
+
{ name: 'tls', secret: { secretName: 'app-tls' } },
|
|
47
|
+
{ name: 'data', emptyDir: {} },
|
|
48
|
+
{ name: 'shared', persistentVolumeClaim: { claimName: 'shared' } },
|
|
49
|
+
{ name: 'one', configMap: { name: 'nginx' } },
|
|
50
|
+
{ name: 'proj', projected: { sources: [{ secret: { name: 'only-one' } }] } },
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
describe('uploadBlockedHint', () => {
|
|
56
|
+
it('blocks ConfigMap and Secret mounts and names their source', () => {
|
|
57
|
+
expect(uploadBlockedHint(pod, 'app', '/etc/app')?.source).toEqual({ kind: 'ConfigMap', name: 'app-config' })
|
|
58
|
+
expect(uploadBlockedHint(pod, 'app', '/etc/app/..data')?.source).toEqual({ kind: 'ConfigMap', name: 'app-config' })
|
|
59
|
+
expect(uploadBlockedHint(pod, 'app', '/etc/tls')?.source).toEqual({ kind: 'Secret', name: 'app-tls' })
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('names the single source of a projected volume', () => {
|
|
63
|
+
expect(uploadBlockedHint(pod, 'app', '/var/run/proj')?.source).toEqual({ kind: 'Secret', name: 'only-one' })
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('blocks read-only mounts', () => {
|
|
67
|
+
expect(uploadBlockedHint(pod, 'app', '/shared/x')?.reason).toMatch(/read-only/)
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('allows writable volumes and an unmounted path on a writable root', () => {
|
|
71
|
+
expect(uploadBlockedHint(pod, 'app', '/data')).toBeNull()
|
|
72
|
+
expect(uploadBlockedHint(pod, 'app', '/tmp')).toBeNull()
|
|
73
|
+
expect(uploadBlockedHint(pod, 'app', '/etc')).toBeNull()
|
|
74
|
+
expect(uploadBlockedHint(pod, 'app', '/etc/application')).toBeNull()
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('blocks a read-only root filesystem outside writable volumes', () => {
|
|
78
|
+
expect(uploadBlockedHint(pod, 'locked', '/tmp')?.reason).toMatch(/readOnlyRootFilesystem/)
|
|
79
|
+
expect(uploadBlockedHint(pod, 'locked', '/data/sub')).toBeNull()
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('reads mounts of native sidecars', () => {
|
|
83
|
+
expect(uploadBlockedHint(pod, 'sidecar', '/config')?.source).toEqual({ kind: 'ConfigMap', name: 'app-config' })
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
it('gives no hint for an unknown container or missing pod', () => {
|
|
87
|
+
expect(uploadBlockedHint(pod, 'nope', '/etc/app')).toBeNull()
|
|
88
|
+
expect(uploadBlockedHint(undefined, 'app', '/etc/app')).toBeNull()
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
describe('fileMountHint', () => {
|
|
93
|
+
it('flags a file mounted on its own', () => {
|
|
94
|
+
const hint = fileMountHint(pod, 'app', '/etc/nginx/nginx.conf')
|
|
95
|
+
expect(hint?.source).toEqual({ kind: 'ConfigMap', name: 'nginx' })
|
|
96
|
+
expect(fileMountHint(pod, 'app', '/etc/nginx/other.conf')).toBeNull()
|
|
97
|
+
})
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
describe('uploadTarget', () => {
|
|
101
|
+
const listing: FileNode = {
|
|
102
|
+
name: 'etc',
|
|
103
|
+
path: '/etc',
|
|
104
|
+
type: 'dir',
|
|
105
|
+
children: [
|
|
106
|
+
{ name: 'a.conf', path: '/etc/a.conf', type: 'file' },
|
|
107
|
+
{ name: 'conf.d', path: '/etc/conf.d', type: 'dir' },
|
|
108
|
+
{ name: 'link', path: '/etc/link', type: 'symlink', linkTarget: '/x' },
|
|
109
|
+
],
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
it('asks before replacing an existing file', () => {
|
|
113
|
+
expect(uploadTarget(listing, 'a.conf')).toEqual({ kind: 'replace' })
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it('uploads a new name straight away', () => {
|
|
117
|
+
expect(uploadTarget(listing, 'b.conf')).toEqual({ kind: 'new' })
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
it('refuses directories and symlinks', () => {
|
|
121
|
+
expect(uploadTarget(listing, 'conf.d').kind).toBe('refuse')
|
|
122
|
+
expect(uploadTarget(listing, 'link').kind).toBe('refuse')
|
|
123
|
+
})
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
describe('isValidUploadName', () => {
|
|
127
|
+
it('matches what the server accepts', () => {
|
|
128
|
+
expect(isValidUploadName('app.conf')).toBe(true)
|
|
129
|
+
expect(isValidUploadName('-rf')).toBe(true)
|
|
130
|
+
for (const bad of ['', '.', '..', 'a/b', 'a\0b', 'x'.repeat(256)]) {
|
|
131
|
+
expect(isValidUploadName(bad)).toBe(false)
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
describe('oversizeMessage', () => {
|
|
137
|
+
it('refuses a file over the advertised cap before sending it', () => {
|
|
138
|
+
expect(oversizeMessage(200 * 1024 * 1024)).toMatch(/limited to 100/)
|
|
139
|
+
expect(oversizeMessage(100 * 1024 * 1024)).toBeNull()
|
|
140
|
+
expect(oversizeMessage(10, 5)).toMatch(/limited to/)
|
|
141
|
+
})
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
describe('upload controls', () => {
|
|
145
|
+
it('disables the button under a known read-only mount and says why', () => {
|
|
146
|
+
const html = renderToStaticMarkup(
|
|
147
|
+
<PodFileUploadButton blocked={{ reason: '/etc/app is a ConfigMap volume.' }} busy={false} onClick={() => {}} />,
|
|
148
|
+
)
|
|
149
|
+
expect(html).toMatch(/<button[^>]* disabled=""/)
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
it('disables the button while the listing for the selected container loads', () => {
|
|
153
|
+
const html = renderToStaticMarkup(<PodFileUploadButton blocked={null} busy={false} loading onClick={() => {}} />)
|
|
154
|
+
expect(html).toMatch(/<button[^>]* disabled=""/)
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
it('enables the button when nothing blocks it', () => {
|
|
158
|
+
const html = renderToStaticMarkup(<PodFileUploadButton blocked={null} busy={false} onClick={() => {}} />)
|
|
159
|
+
expect(html).not.toMatch(/<button[^>]* disabled=""/)
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
it('shows the persistence note verbatim and links to the blocking source', () => {
|
|
163
|
+
const html = renderToStaticMarkup(
|
|
164
|
+
<MemoryRouter>
|
|
165
|
+
<PodFileUploadNotices
|
|
166
|
+
namespace="prod"
|
|
167
|
+
blocked={{ reason: 'ConfigMap volume', source: { kind: 'ConfigMap', name: 'app-config' } }}
|
|
168
|
+
onNavigateAway={() => {}}
|
|
169
|
+
/>
|
|
170
|
+
</MemoryRouter>,
|
|
171
|
+
)
|
|
172
|
+
expect(html).toContain(POD_FILE_PERSISTENCE_NOTE.replace(/'/g, '''))
|
|
173
|
+
expect(html).toContain('href="/resources/configmaps?resource=prod%2Fapp-config"')
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
it('asks for confirmation before replacing', () => {
|
|
177
|
+
const html = renderToStaticMarkup(
|
|
178
|
+
<PodFileUploadStatus
|
|
179
|
+
state={{ phase: 'confirm', name: 'a.conf', dir: '/etc', size: 10 }}
|
|
180
|
+
onConfirmReplace={() => {}}
|
|
181
|
+
onCancel={() => {}}
|
|
182
|
+
onDismiss={() => {}}
|
|
183
|
+
/>,
|
|
184
|
+
)
|
|
185
|
+
expect(html).toContain('Replace a.conf?')
|
|
186
|
+
expect(html).toContain('/etc/a.conf already exists')
|
|
187
|
+
expect(html).toContain('>Replace<')
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
it('keeps uploading and saved distinct', () => {
|
|
191
|
+
const uploading = renderToStaticMarkup(
|
|
192
|
+
<PodFileUploadStatus state={{ phase: 'uploading', name: 'a', dir: '/', sent: 50, total: 100 }} onConfirmReplace={() => {}} onCancel={() => {}} onDismiss={() => {}} />,
|
|
193
|
+
)
|
|
194
|
+
expect(uploading).toContain('aria-valuenow="50"')
|
|
195
|
+
expect(uploading).toContain('>Cancel<')
|
|
196
|
+
const saving = renderToStaticMarkup(
|
|
197
|
+
<PodFileUploadStatus state={{ phase: 'saving', name: 'a', dir: '/' }} onConfirmReplace={() => {}} onCancel={() => {}} onDismiss={() => {}} />,
|
|
198
|
+
)
|
|
199
|
+
expect(saving).toContain('Saving a')
|
|
200
|
+
expect(saving).not.toContain('>Cancel<')
|
|
201
|
+
const saved = renderToStaticMarkup(
|
|
202
|
+
<PodFileUploadStatus state={{ phase: 'saved', path: '/a', replaced: false }} onConfirmReplace={() => {}} onCancel={() => {}} onDismiss={() => {}} />,
|
|
203
|
+
)
|
|
204
|
+
expect(saved).toContain('Saved /a')
|
|
205
|
+
})
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
describe('uploadResponseError', () => {
|
|
209
|
+
it('blames a proxy only when a 413 carries no Radar error body', () => {
|
|
210
|
+
const fromProxy = uploadResponseError(413, null)
|
|
211
|
+
expect(fromProxy.message).toMatch(/proxy/)
|
|
212
|
+
expect(fromProxy.code).toBe('file_too_large')
|
|
213
|
+
|
|
214
|
+
const fromRadar = uploadResponseError(413, { error: 'Uploads are limited to 104857600 bytes', error_code: 'file_too_large' })
|
|
215
|
+
expect(fromRadar.message).toBe('Uploads are limited to 104857600 bytes')
|
|
216
|
+
expect(fromRadar.message).not.toMatch(/proxy/)
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
it('keeps other failures as before', () => {
|
|
220
|
+
expect(uploadResponseError(500, null).message).toBe('Upload failed (HTTP 500)')
|
|
221
|
+
expect(uploadResponseError(409, { error: 'x exists', error_code: 'file_exists' }).code).toBe('file_exists')
|
|
222
|
+
})
|
|
223
|
+
})
|