@skyhook-io/radar-app 1.21.6 → 1.21.7
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/README.md +1 -1
- package/package.json +7 -7
- package/src/App.tsx +19 -1
- package/src/RadarApp.tsx +8 -2
- package/src/api/client.discoverMetrics.test.tsx +69 -0
- package/src/api/client.issueCorrelation.test.tsx +244 -0
- package/src/api/client.issueRowChanges.test.tsx +129 -0
- package/src/api/client.pendingOwnership.test.tsx +197 -0
- package/src/api/client.prometheusStatus.test.ts +4 -0
- package/src/api/client.restartError.test.ts +36 -1
- package/src/api/client.stopWorkflow.test.tsx +133 -0
- package/src/api/client.submitWorkflowTemplate.test.tsx +127 -0
- package/src/api/client.ts +572 -111
- package/src/api/connectionBinding.test.tsx +3 -1
- package/src/api/connectionBinding.ts +14 -2
- package/src/api/gitOpsPermissions.render.test.tsx +155 -0
- package/src/api/gitOpsPermissions.test.ts +90 -0
- package/src/api/gitOpsPermissions.ts +51 -0
- package/src/api/httpErrors.test.ts +30 -1
- package/src/api/httpErrors.ts +17 -0
- package/src/api/openobserveSetup.ts +85 -0
- package/src/api/podDebug.test.tsx +137 -0
- package/src/api/podDebug.ts +82 -0
- package/src/api/prometheusCharts.test.ts +23 -0
- package/src/api/prometheusCharts.ts +25 -0
- package/src/api/radarFeatures.render.test.tsx +43 -2
- package/src/api/radarFeatures.test.ts +18 -1
- package/src/api/radarFeatures.ts +17 -4
- package/src/api/reviewedActionMutation.ts +9 -2
- package/src/api/workloadMetrics.ts +2 -0
- package/src/components/applications/ApplicationsView.openResource.test.tsx +137 -11
- package/src/components/applications/ApplicationsView.tsx +56 -31
- package/src/components/cnpg/host.test.tsx +1 -1
- package/src/components/cnpg/host.tsx +0 -2
- package/src/components/dock/BottomDock.tsx +7 -3
- package/src/components/dock/MissingShellDebug.test.tsx +193 -0
- package/src/components/dock/MissingShellDebug.tsx +114 -0
- package/src/components/dock/PodDebugSession.test.tsx +60 -0
- package/src/components/dock/PodDebugSession.tsx +96 -0
- package/src/components/dock/TerminalTab.test.tsx +48 -4
- package/src/components/dock/TerminalTab.tsx +47 -25
- package/src/components/dock/WorkloadLogsTab.test.tsx +24 -1
- package/src/components/dock/WorkloadLogsTab.tsx +16 -0
- package/src/components/execution/BatchExecutionView.command.test.tsx +69 -0
- package/src/components/execution/BatchExecutionView.tsx +88 -5
- package/src/components/execution/BatchExecutionView.workflow-stop.test.tsx +69 -0
- package/src/components/execution/WorkflowRunStopAction.tsx +8 -0
- package/src/components/gitops/GitOpsPermissionRowActions.test.tsx +100 -0
- package/src/components/gitops/GitOpsPermissionRowActions.tsx +27 -0
- package/src/components/gitops/GitOpsView.identity.test.tsx +1 -0
- package/src/components/gitops/GitOpsView.permissions.test.tsx +102 -0
- package/src/components/gitops/GitOpsView.syncRequest.test.tsx +95 -7
- package/src/components/gitops/GitOpsView.tsx +93 -32
- package/src/components/helm/OwnedResources.tsx +1 -0
- package/src/components/home/mcpToolCatalog.ts +1 -0
- package/src/components/issues/IssuesPane.render.test.tsx +1 -1
- package/src/components/issues/IssuesPane.tsx +11 -0
- package/src/components/issues/useIssueExpansion.ts +91 -0
- package/src/components/resource/MetricsNotConnected.test.tsx +50 -0
- package/src/components/resource/MetricsNotConnected.tsx +114 -0
- package/src/components/resource/PVCUsageBar.tsx +2 -1
- package/src/components/resource/PrometheusCharts.render.test.tsx +47 -0
- package/src/components/resource/PrometheusCharts.tsx +14 -2
- package/src/components/resource/PrometheusChartsGrid.render.test.tsx +91 -1
- package/src/components/resource/PrometheusChartsGrid.tsx +28 -52
- package/src/components/resource/RestartChart.tsx +4 -3
- package/src/components/resource/RightsizingPanel.source.test.tsx +34 -0
- package/src/components/resource/RightsizingStrip.tsx +5 -3
- package/src/components/resource/WorkloadMetricsSection.render.test.tsx +6 -0
- package/src/components/resource/WorkloadMetricsSection.tsx +14 -11
- package/src/components/resource/nameMatchedScope.ts +9 -3
- package/src/components/resources/EmptyNamespaceHint.tsx +42 -0
- package/src/components/resources/PodDebugAction.test.tsx +157 -0
- package/src/components/resources/PodDebugAction.tsx +207 -0
- package/src/components/resources/PodDebugPermission.tsx +21 -0
- package/src/components/resources/ResourcesView.empty-hint.test.tsx +132 -0
- package/src/components/resources/ResourcesView.tsx +39 -5
- package/src/components/resources/namespaceHint.test.ts +34 -0
- package/src/components/resources/namespaceHint.ts +19 -0
- package/src/components/resources/renderers/AdmissionPolicyRenderers.tsx +135 -0
- package/src/components/resources/renderers/NodeRenderer.tsx +2 -1
- package/src/components/resources/renderers/PodRenderer.tsx +12 -5
- package/src/components/resources/renderers/ValidatingAdmissionPolicyRenderer.test.tsx +24 -1
- package/src/components/settings/LocalIntegrationStatus.tsx +14 -3
- package/src/components/settings/MetricsBackendSwitch.tsx +167 -0
- package/src/components/settings/OpenObserveSetup.test.tsx +343 -0
- package/src/components/settings/OpenObserveSetup.tsx +358 -0
- package/src/components/settings/SettingsDialog.tsx +21 -7
- package/src/components/settings/openobserveStatus.test.ts +34 -0
- package/src/components/settings/openobserveStatus.ts +55 -0
- package/src/components/timeline/TimelineList.selection.test.tsx +40 -0
- package/src/components/timeline/TimelineList.test.ts +18 -0
- package/src/components/timeline/TimelineList.tsx +19 -5
- package/src/components/timeline/TimelineView.tsx +2 -0
- package/src/components/workload/WorkloadView.pendingOwnership.test.tsx +34 -0
- package/src/components/workload/WorkloadView.tabUrl.test.tsx +44 -0
- package/src/components/workload/WorkloadView.tsx +95 -10
- package/src/context/TimelineNavigation.test.ts +59 -0
- package/src/context/TimelineNavigation.tsx +86 -0
- package/src/contexts/CapabilitiesContext.tsx +3 -1
- package/src/hooks/useResourceCounts.ts +2 -1
- package/src/hooks/useWorkflowStopAction.ts +31 -0
- package/src/index.css +1 -0
- package/src/integrations/resourceHosts.test.tsx +2 -2
- package/src/integrations/resourceHosts.tsx +4 -2
- package/src/k8s-ui-exports.test.ts +10 -0
- package/src/components/resources/renderers/ValidatingAdmissionPolicyRenderer.tsx +0 -128
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
2
|
import { useNavigate, useSearchParams } from "react-router-dom";
|
|
3
3
|
import {
|
|
4
|
+
AlertBanner,
|
|
4
5
|
ApplicationsList,
|
|
5
6
|
ApplicationDetail,
|
|
6
7
|
ArgoSyncDetailsContext,
|
|
@@ -9,6 +10,7 @@ import {
|
|
|
9
10
|
CenteredEmpty,
|
|
10
11
|
getRadarUpgradeRequirement,
|
|
11
12
|
PageHeader,
|
|
13
|
+
PaneLoader,
|
|
12
14
|
RadarUpgradeAction,
|
|
13
15
|
radarUpgradeDetail,
|
|
14
16
|
radarUpgradeHeadline,
|
|
@@ -18,6 +20,7 @@ import {
|
|
|
18
20
|
useToast,
|
|
19
21
|
orderEnvs,
|
|
20
22
|
matchWorkloadAcrossInstances,
|
|
23
|
+
resolveAppWorkloadSelection,
|
|
21
24
|
workloadKey,
|
|
22
25
|
healthOf,
|
|
23
26
|
compareVersions,
|
|
@@ -270,27 +273,37 @@ function AppDetailRoute({
|
|
|
270
273
|
// workload. A single-workload app does not expose app scope.
|
|
271
274
|
const [searchParams, setSearchParams] = useSearchParams();
|
|
272
275
|
const viewParam = searchParams.get("view");
|
|
273
|
-
const selectedRouteView = parseApplicationView(viewParam);
|
|
274
|
-
const selectedView: ApplicationView =
|
|
275
|
-
selectedRouteView === "cost" ? "overview" : selectedRouteView;
|
|
276
276
|
const selectedWorkloadParam = searchParams.get("workload");
|
|
277
277
|
const appWorkloads = app.workloads ?? [];
|
|
278
278
|
const singleWorkloadKey =
|
|
279
279
|
appWorkloads.length === 1 ? workloadKey(appWorkloads[0]) : null;
|
|
280
280
|
const selectedWorkloadKey = singleWorkloadKey ?? selectedWorkloadParam;
|
|
281
|
+
const deploysTab = searchParams.get("tab") === "deploys";
|
|
282
|
+
const appDeploysAlias = selectedWorkloadKey === null && !viewParam && deploysTab;
|
|
283
|
+
const selectedRouteView = appDeploysAlias ? "deploys" : parseApplicationView(viewParam);
|
|
284
|
+
const selectedView: ApplicationView =
|
|
285
|
+
selectedRouteView === "cost" ? "overview" : selectedRouteView;
|
|
281
286
|
const applicationCostAvailable =
|
|
282
287
|
!singleWorkloadKey &&
|
|
283
288
|
appWorkloads.some((workload) => isOpenCostWorkloadKind(workload.kind));
|
|
284
289
|
const applicationCostSelected =
|
|
285
290
|
selectedRouteView === "cost" && applicationCostAvailable;
|
|
291
|
+
const requestedDeploys = selectedView === "deploys" || deploysTab;
|
|
292
|
+
const deploysInWorkloadScope = requestedDeploys && !singleWorkloadKey &&
|
|
293
|
+
resolveAppWorkloadSelection(appWorkloads.map(workloadKey), selectedWorkloadParam).selected !== null;
|
|
286
294
|
const historyQuery = useApplicationHistory(app.key, appHistoryNamespaces, {
|
|
287
|
-
enabled: !selectedWorkloadKey || Boolean(app.sourceRef),
|
|
295
|
+
enabled: !selectedWorkloadKey || Boolean(app.sourceRef) || (requestedDeploys && !deploysInWorkloadScope),
|
|
288
296
|
});
|
|
289
297
|
const readableHistory = historyQuery.isError ? undefined : historyQuery.data;
|
|
290
|
-
const deliveryRecords = useMemo(() => applicationDeliveryRecords(
|
|
291
|
-
const
|
|
292
|
-
const
|
|
293
|
-
const
|
|
298
|
+
const deliveryRecords = useMemo(() => applicationDeliveryRecords(readableHistory), [readableHistory]);
|
|
299
|
+
const partialSources = readableHistory?.partialSources;
|
|
300
|
+
const sourceUnavailable = !readableHistory?.sourceRef && !!partialSources?.length;
|
|
301
|
+
const deliverySource = sourceUnavailable ? undefined : readableHistory?.sourceRef ?? app.sourceRef;
|
|
302
|
+
const needsDeploySource = requestedDeploys && !deploysInWorkloadScope && !deliverySource;
|
|
303
|
+
const waitingForDeploySource = needsDeploySource && !sourceUnavailable && (historyQuery.isPending || historyQuery.isFetching);
|
|
304
|
+
const clearDeploySelection = deploysInWorkloadScope || (needsDeploySource && !sourceUnavailable && historyQuery.isSuccess && !historyQuery.isFetching);
|
|
305
|
+
const normalizeSingleWorkload = Boolean(singleWorkloadKey && (selectedWorkloadParam !== singleWorkloadKey || viewParam));
|
|
306
|
+
const clearCostSelection = !singleWorkloadKey && selectedRouteView === "cost" && !applicationCostAvailable;
|
|
294
307
|
const [retainedHistoryRange, setRetainedHistoryRange] =
|
|
295
308
|
useState<ApplicationHistoryRange>("7d");
|
|
296
309
|
const historyRangeOptions = useMemo(
|
|
@@ -395,7 +408,8 @@ function AppDetailRoute({
|
|
|
395
408
|
);
|
|
396
409
|
useEffect(() => {
|
|
397
410
|
// Deploys belongs to the app scope, including its single-workload shell.
|
|
398
|
-
if (
|
|
411
|
+
if (waitingForDeploySource) return;
|
|
412
|
+
if (clearDeploySelection) {
|
|
399
413
|
const params = new URLSearchParams(searchParams);
|
|
400
414
|
if (viewParam === "deploys") params.delete("view");
|
|
401
415
|
if (params.get("tab") === "deploys") params.delete("tab");
|
|
@@ -403,8 +417,7 @@ function AppDetailRoute({
|
|
|
403
417
|
setSearchParams(params, { replace: true });
|
|
404
418
|
return;
|
|
405
419
|
}
|
|
406
|
-
if (!singleWorkloadKey) return;
|
|
407
|
-
if (selectedWorkloadParam === singleWorkloadKey && !viewParam) return;
|
|
420
|
+
if (!singleWorkloadKey || !normalizeSingleWorkload) return;
|
|
408
421
|
const params = new URLSearchParams(searchParams);
|
|
409
422
|
params.delete("view");
|
|
410
423
|
params.delete("run");
|
|
@@ -414,33 +427,28 @@ function AppDetailRoute({
|
|
|
414
427
|
setSearchParams(params, { replace: true });
|
|
415
428
|
}, [
|
|
416
429
|
searchParams,
|
|
417
|
-
|
|
418
|
-
|
|
430
|
+
waitingForDeploySource,
|
|
431
|
+
clearDeploySelection,
|
|
432
|
+
normalizeSingleWorkload,
|
|
419
433
|
selectedRouteView,
|
|
420
|
-
selectedWorkloadParam,
|
|
421
434
|
setSearchParams,
|
|
422
435
|
singleWorkloadKey,
|
|
423
436
|
viewParam,
|
|
424
437
|
]);
|
|
425
438
|
useEffect(() => {
|
|
426
|
-
if (
|
|
427
|
-
singleWorkloadKey ||
|
|
428
|
-
selectedRouteView !== "cost" ||
|
|
429
|
-
applicationCostAvailable
|
|
430
|
-
)
|
|
431
|
-
return;
|
|
439
|
+
if (waitingForDeploySource || clearDeploySelection || !clearCostSelection) return;
|
|
432
440
|
const params = new URLSearchParams(searchParams);
|
|
433
441
|
params.delete("view");
|
|
434
442
|
setSearchParams(params, { replace: true });
|
|
435
443
|
}, [
|
|
436
|
-
|
|
444
|
+
clearCostSelection,
|
|
445
|
+
waitingForDeploySource,
|
|
446
|
+
clearDeploySelection,
|
|
437
447
|
searchParams,
|
|
438
|
-
selectedRouteView,
|
|
439
448
|
setSearchParams,
|
|
440
|
-
singleWorkloadKey,
|
|
441
449
|
]);
|
|
442
450
|
const selectView = useCallback(
|
|
443
|
-
(view: ApplicationRouteView) => {
|
|
451
|
+
(view: ApplicationRouteView, options?: { replace?: boolean }) => {
|
|
444
452
|
const params = new URLSearchParams(searchParams);
|
|
445
453
|
params.delete("tab");
|
|
446
454
|
params.delete("run");
|
|
@@ -457,12 +465,12 @@ function AppDetailRoute({
|
|
|
457
465
|
params.set("view", view === "history" ? "timeline" : view);
|
|
458
466
|
params.delete("workload");
|
|
459
467
|
}
|
|
460
|
-
setSearchParams(params);
|
|
468
|
+
setSearchParams(params, { replace: options?.replace });
|
|
461
469
|
},
|
|
462
470
|
[searchParams, setSearchParams, singleWorkloadKey],
|
|
463
471
|
);
|
|
464
472
|
const selectWorkload = useCallback(
|
|
465
|
-
(key: string | null, options?: { tab?: string }) => {
|
|
473
|
+
(key: string | null, options?: { tab?: string; replace?: boolean }) => {
|
|
466
474
|
const params = new URLSearchParams(searchParams);
|
|
467
475
|
params.delete("run");
|
|
468
476
|
if (key) {
|
|
@@ -477,9 +485,13 @@ function AppDetailRoute({
|
|
|
477
485
|
} else {
|
|
478
486
|
params.delete("workload");
|
|
479
487
|
params.delete("tab");
|
|
480
|
-
|
|
488
|
+
if (!options?.replace) {
|
|
489
|
+
params.delete("view");
|
|
490
|
+
} else if (!params.get("view") && searchParams.get("tab") === "deploys") {
|
|
491
|
+
params.set("view", "deploys");
|
|
492
|
+
}
|
|
481
493
|
}
|
|
482
|
-
setSearchParams(params);
|
|
494
|
+
setSearchParams(params, { replace: options?.replace });
|
|
483
495
|
},
|
|
484
496
|
[searchParams, selectedWorkloadKey, setSearchParams, singleWorkloadKey],
|
|
485
497
|
);
|
|
@@ -663,6 +675,16 @@ function AppDetailRoute({
|
|
|
663
675
|
[apps],
|
|
664
676
|
);
|
|
665
677
|
|
|
678
|
+
const renderDeploys = deliverySource && (deliveryRecords.length > 0 || requestedDeploys)
|
|
679
|
+
? () => <ApplicationDeploys source={deliverySource} records={deliveryRecords} loading={historyQuery.isLoading} unavailable={historyQuery.isError} partialSources={partialSources} onOpenSource={openSource} />
|
|
680
|
+
: needsDeploySource && (historyQuery.isError || sourceUnavailable)
|
|
681
|
+
? () => <AlertBanner className="m-4" variant="warning" title={sourceUnavailable ? "Delivery records are unavailable" : "Delivery records could not be refreshed"} items={partialSources} />
|
|
682
|
+
: undefined;
|
|
683
|
+
const normalizeDeploysAlias = appDeploysAlias && !!renderDeploys;
|
|
684
|
+
useEffect(() => {
|
|
685
|
+
if (normalizeDeploysAlias) selectView("deploys", { replace: true });
|
|
686
|
+
}, [normalizeDeploysAlias, selectView]);
|
|
687
|
+
|
|
666
688
|
return (
|
|
667
689
|
<div className="flex min-h-0 flex-1 flex-col overflow-hidden">
|
|
668
690
|
<ArgoSyncDetailsContext.Provider value={ArgoSyncDetails}>
|
|
@@ -697,8 +719,8 @@ function AppDetailRoute({
|
|
|
697
719
|
onSelectWorkload={selectWorkload}
|
|
698
720
|
selectedView={selectedView}
|
|
699
721
|
onSelectView={selectView}
|
|
700
|
-
|
|
701
|
-
|
|
722
|
+
selectionLoading={waitingForDeploySource || clearDeploySelection || clearCostSelection}
|
|
723
|
+
renderDeploys={renderDeploys}
|
|
702
724
|
renderWorkloadRevisions={(workload) => <WorkloadRevisionsButton {...workload} />}
|
|
703
725
|
costViewSelected={applicationCostSelected}
|
|
704
726
|
onSelectCostView={() => selectView("cost")}
|
|
@@ -725,7 +747,10 @@ function AppDetailRoute({
|
|
|
725
747
|
/>
|
|
726
748
|
)}
|
|
727
749
|
hasOverviewIssues={appIssues.length > 0}
|
|
728
|
-
renderWorkload={(workload: SelectedAppWorkload, context) =>
|
|
750
|
+
renderWorkload={(workload: SelectedAppWorkload, context) => requestedDeploys &&
|
|
751
|
+
(waitingForDeploySource || clearDeploySelection || normalizeSingleWorkload) ? (
|
|
752
|
+
<PaneLoader label="Loading workload view…" className="h-full" />
|
|
753
|
+
) : (
|
|
729
754
|
<div className="h-full overflow-hidden">
|
|
730
755
|
<WorkloadView
|
|
731
756
|
{...context}
|
|
@@ -9,7 +9,7 @@ describe('CNPG host composition', () => {
|
|
|
9
9
|
const path = cnpgHost.detailRedirect(resource, search)!
|
|
10
10
|
const url = new URL(path, 'http://radar.test')
|
|
11
11
|
expect(url.pathname).toBe('/cnpg/clusters/db/pg')
|
|
12
|
-
expect(Object.fromEntries(url.searchParams)).toEqual({ ctx: 'kind-demo', tab: '
|
|
12
|
+
expect(Object.fromEntries(url.searchParams)).toEqual({ ctx: 'kind-demo', tab: 'timeline', drawer: 'pods:pg-1' })
|
|
13
13
|
expect(search.get('tab')).toBe('timeline')
|
|
14
14
|
expect(search.get('apiGroup')).toBe('postgresql.cnpg.io')
|
|
15
15
|
})
|
|
@@ -34,8 +34,6 @@ export const cnpgHost = {
|
|
|
34
34
|
if (!plural) return null
|
|
35
35
|
const params = new URLSearchParams(search)
|
|
36
36
|
params.delete('apiGroup')
|
|
37
|
-
const tab = params.get('tab')
|
|
38
|
-
if (plural === 'clusters' && (tab === 'timeline' || tab === 'events')) params.set('tab', 'activity')
|
|
39
37
|
const base = cnpgDetailPath({ plural, namespace: resource.namespace, name: resource.name })
|
|
40
38
|
const qs = params.toString()
|
|
41
39
|
return qs ? `${base}?${qs}` : base
|
|
@@ -9,17 +9,21 @@ import { TrafficFlowListTab } from './TrafficFlowListTab'
|
|
|
9
9
|
import { useFlowSearch } from '../traffic/TrafficFlowListContext'
|
|
10
10
|
import { Search } from 'lucide-react'
|
|
11
11
|
|
|
12
|
-
function renderTabContent(tab: DockTab, isActive: boolean, viewNamespaces: string[]) {
|
|
12
|
+
function renderTabContent(tab: DockTab, isActive: boolean, viewNamespaces: string[], removeTab: (id: string) => void, setTerminalContainer: (id: string, name: string) => void) {
|
|
13
13
|
if (tab.type === 'terminal') {
|
|
14
14
|
return (
|
|
15
15
|
<TerminalTab
|
|
16
16
|
namespace={tab.namespace!}
|
|
17
17
|
podName={tab.podName!}
|
|
18
|
+
podUID={tab.podUID}
|
|
18
19
|
containerName={tab.containerName!}
|
|
20
|
+
onContainerChange={name => setTerminalContainer(tab.id, name)}
|
|
19
21
|
containers={tab.containers!}
|
|
20
22
|
isActive={isActive}
|
|
21
23
|
shell={tab.shell}
|
|
22
24
|
note={tab.sessionNote}
|
|
25
|
+
debugSession={tab.debugSession}
|
|
26
|
+
onLeaveTerminal={() => removeTab(tab.id)}
|
|
23
27
|
/>
|
|
24
28
|
)
|
|
25
29
|
}
|
|
@@ -94,8 +98,8 @@ function renderTabHeaderExtra(tab: DockTab) {
|
|
|
94
98
|
}
|
|
95
99
|
|
|
96
100
|
export function BottomDock({ viewNamespaces }: { viewNamespaces: string[] }) {
|
|
97
|
-
const { leftOffset, tabs } = useDock()
|
|
101
|
+
const { leftOffset, tabs, removeTab, setTerminalContainer } = useDock()
|
|
98
102
|
const hasTrafficFlows = tabs.some(t => t.type === 'traffic-flows')
|
|
99
|
-
const renderContent = useCallback((tab: DockTab, isActive: boolean) => renderTabContent(tab, isActive, viewNamespaces), [viewNamespaces])
|
|
103
|
+
const renderContent = useCallback((tab: DockTab, isActive: boolean) => renderTabContent(tab, isActive, viewNamespaces, removeTab, setTerminalContainer), [viewNamespaces, removeTab, setTerminalContainer])
|
|
100
104
|
return <K8sBottomDock renderTabContent={renderContent} renderTabHeaderExtra={renderTabHeaderExtra} leftOffset={leftOffset} defaultHeight={hasTrafficFlows ? 300 : undefined} />
|
|
101
105
|
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot } from 'react-dom/client'
|
|
4
|
+
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
|
5
|
+
import { usePodDetailAccess } from '../resources/PodDebugAction'
|
|
6
|
+
import { observeConnectionStatus, resetConnectionBindingForTest } from '../../api/connectionBinding'
|
|
7
|
+
import { MissingShellDebug } from './MissingShellDebug'
|
|
8
|
+
|
|
9
|
+
const f = vi.hoisted(() => ({
|
|
10
|
+
pod: {} as any, installation: {} as Record<string, unknown>, checkError: undefined as Error | undefined, namedExec: false, embedded: false, support: 'supported', access: 'denied', image: undefined as string | undefined,
|
|
11
|
+
recheck: vi.fn(), open: vi.fn(), probe: vi.fn(),
|
|
12
|
+
}))
|
|
13
|
+
vi.mock('../../context/ConnectionContext', () => ({ useConnection: () => ({connection:{context:'fixture-cluster'}}) }))
|
|
14
|
+
vi.mock('../../context/NavCustomization', () => ({ useNavCustomization: () => ({ embedded: f.embedded }) }))
|
|
15
|
+
vi.mock('../../contexts/CapabilitiesContext', () => ({ useCapabilitiesContext: () => f.installation, useNamespacedCapabilities: () => ({ podDebugImage: f.image }) }))
|
|
16
|
+
vi.mock('../../api/client', async original => ({ ...await original<typeof import('../../api/client')>(), useResource: () => ({ data: f.pod }) }))
|
|
17
|
+
vi.mock('../../api/podDebug', () => ({ usePodDebugAccess: (...args: unknown[]) => {
|
|
18
|
+
f.probe(...args)
|
|
19
|
+
return {support: f.support, recheckAccess: f.recheck, unverifiedReview: !args[4] && f.access === 'unknown' && f.namedExec && !f.checkError ? {} : undefined, unverifiedImage: !args[4] && f.access === 'unknown' && f.namedExec && !f.checkError ? 'operator-tools' : undefined, query: { error: f.checkError, data: {state: f.access, image: 'toolbox', exec: f.namedExec}, refetch: f.recheck }}
|
|
20
|
+
} }))
|
|
21
|
+
vi.mock('@skyhook-io/k8s-ui', async original => ({ ...await original<typeof import('@skyhook-io/k8s-ui')>(), useOpenTerminal: () => f.open }))
|
|
22
|
+
vi.mock('../resources/PodDebugAction', async original => ({ ...await original<typeof import('../resources/PodDebugAction')>(),
|
|
23
|
+
PodDebugAction: ({ failedContainer, unverifiedReview, hideLauncher }: { failedContainer: string; unverifiedReview?: object; hideLauncher?: boolean }) => hideLauncher ? null : <button>{unverifiedReview ? 'Review attempt for' : 'Start for'} {failedContainer}</button> }))
|
|
24
|
+
|
|
25
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
|
|
26
|
+
let host: HTMLDivElement, root: ReturnType<typeof createRoot>
|
|
27
|
+
const render = () => act(() => root.render(<MissingShellDebug namespace="payments" name="checkout" uid="uid-1" target="app" base="/api"/>))
|
|
28
|
+
const button = (label: string) => [...host.querySelectorAll('button')].find(b => b.textContent === label)
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
vi.clearAllMocks()
|
|
31
|
+
resetConnectionBindingForTest()
|
|
32
|
+
Object.assign(f, { installation: {}, checkError: undefined, embedded: false, namedExec: false, support: 'supported', access: 'denied', image: undefined,
|
|
33
|
+
pod: { apiVersion: 'v1', kind: 'Pod', metadata: {uid:'uid-1', namespace:'payments', name:'checkout'},
|
|
34
|
+
spec: {containers:[{name:'app'}]}, status:{phase:'Running',containerStatuses:[{name:'app', state:{running:{}}}] } } })
|
|
35
|
+
host = document.createElement('div')
|
|
36
|
+
root = createRoot(host)
|
|
37
|
+
})
|
|
38
|
+
afterEach(() => act(() => root.unmount()))
|
|
39
|
+
|
|
40
|
+
it('offers only running debuggers targeting the failed container, with no access probe', () => {
|
|
41
|
+
const names = ['already-running','second','wrong-target','stopped']
|
|
42
|
+
f.pod.spec.ephemeralContainers = names.map(name => ({ name, image:'toolbox', targetContainerName:name === 'wrong-target' ? 'other' : 'app' }))
|
|
43
|
+
f.pod.status.ephemeralContainerStatuses = names.map(name => ({ name, state:name === 'stopped' ? {terminated:{}} : {running:{}} }))
|
|
44
|
+
render()
|
|
45
|
+
const select = host.querySelector('select')!
|
|
46
|
+
expect([...select.options].map(o=>o.value)).toEqual(names.slice(0,2).reverse())
|
|
47
|
+
act(() => { select.value='second'; select.dispatchEvent(new Event('change',{bubbles:true})) })
|
|
48
|
+
act(() => button('Open debug terminal')!.click())
|
|
49
|
+
expect(f.open).toHaveBeenCalledWith(expect.objectContaining({containerName:'second',debugSession:expect.objectContaining({podUID:'uid-1'})}))
|
|
50
|
+
expect(f.probe.mock.lastCall?.[3]).toBe(false)
|
|
51
|
+
expect(button('Start for app')).toBeUndefined()
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('shows the exact missing permission and rechecks an updated grant', () => {
|
|
55
|
+
render()
|
|
56
|
+
expect(host.textContent).toContain('Ask your cluster admin for access to update pods/ephemeralcontainers for Pod payments/checkout.')
|
|
57
|
+
expect([...host.querySelectorAll('code.inline-code')].map(code => code.textContent)).toEqual(['update pods/ephemeralcontainers', 'payments/checkout'])
|
|
58
|
+
act(() => button('Recheck access')!.click())
|
|
59
|
+
expect(f.recheck).toHaveBeenCalledOnce()
|
|
60
|
+
f.access='allowed'; render()
|
|
61
|
+
expect(button('Start for app')).toBeDefined()
|
|
62
|
+
})
|
|
63
|
+
it('offers a recheck when Kubernetes returns no decision', () => {
|
|
64
|
+
f.access='unknown'; render()
|
|
65
|
+
expect(host.textContent).toContain('Kubernetes couldn’t confirm permission to update pods/ephemeralcontainers for Pod payments/checkout.')
|
|
66
|
+
expect(host.textContent).not.toContain('Ask your cluster admin for access')
|
|
67
|
+
expect(button('Recheck access')).toBeDefined()
|
|
68
|
+
})
|
|
69
|
+
it('distinguishes a failed request from an inconclusive cluster answer', () => {
|
|
70
|
+
f.access = 'unknown'
|
|
71
|
+
render()
|
|
72
|
+
expect(host.textContent).toContain('Kubernetes couldn’t confirm permission to update pods/ephemeralcontainers for Pod payments/checkout.')
|
|
73
|
+
f.checkError = new Error('request timed out')
|
|
74
|
+
render()
|
|
75
|
+
expect(host.textContent).toContain('Radar couldn’t check permission to update pods/ephemeralcontainers for Pod payments/checkout.')
|
|
76
|
+
expect(host.textContent).not.toContain('Ask your cluster admin for access')
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it.each(['embedded', 'replaced', 'windows', 'stopped', 'old', 'disabled'])('suppresses the grant request on %s', mode => {
|
|
80
|
+
if(mode==='embedded')f.embedded=true
|
|
81
|
+
if(mode==='replaced')f.pod.metadata.uid='replacement'
|
|
82
|
+
if(mode==='windows')f.pod.spec.os={name:'windows'}
|
|
83
|
+
if(mode==='stopped')f.pod.status.containerStatuses[0].state={terminated:{}}
|
|
84
|
+
if(mode==='old')f.support='unsupported'
|
|
85
|
+
if(mode==='disabled')f.access='unavailable'
|
|
86
|
+
render()
|
|
87
|
+
expect(host.textContent).not.toContain('Ask your cluster admin for access')
|
|
88
|
+
expect(button('Start for app')).toBeUndefined()
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('uses a positive namespace grant when named access is unknown, but honors an exact denial', () => {
|
|
92
|
+
f.image = 'operator-debug'; f.access = 'unknown'
|
|
93
|
+
render()
|
|
94
|
+
expect(button('Start for app')).toBeDefined()
|
|
95
|
+
expect(f.probe.mock.lastCall?.[3]).toBe(false)
|
|
96
|
+
f.access = 'denied'; render()
|
|
97
|
+
expect(host.textContent).toContain('Ask your cluster admin for access')
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
it('updates a previously open recovery screen when the connection changes', () => {
|
|
101
|
+
render()
|
|
102
|
+
act(() => observeConnectionStatus({connectionId:'new-cluster'}))
|
|
103
|
+
expect(host.textContent).toContain('Open the Pod on the current cluster')
|
|
104
|
+
expect(host.textContent).not.toContain('Ask your cluster admin for access')
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
it('supplies named-only exec to the Pod header and existing terminals independently of update', () => {
|
|
108
|
+
function Consumer() {
|
|
109
|
+
const access = usePodDetailAccess(f.pod, {canExec:false, canOpenEphemeralTerminal:false})
|
|
110
|
+
return <>{access.canExec && 'Terminal '}{access.canOpenEphemeralTerminal && 'Reopen '}{access.debugImage && 'Debug'}</>
|
|
111
|
+
}
|
|
112
|
+
f.namedExec = true; f.access = 'denied'
|
|
113
|
+
act(() => root.render(<Consumer/>))
|
|
114
|
+
expect(host.textContent).toBe('Terminal Reopen ')
|
|
115
|
+
f.access = 'allowed'
|
|
116
|
+
act(() => root.render(<Consumer/>))
|
|
117
|
+
expect(host.textContent).toBe('Terminal Reopen Debug')
|
|
118
|
+
f.embedded = true
|
|
119
|
+
act(() => root.render(<Consumer/>))
|
|
120
|
+
expect(host.textContent).toBe('Terminal Reopen ')
|
|
121
|
+
expect(f.probe.mock.lastCall?.[4]).toBe(true)
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
it('names Radar’s ServiceAccount for a shared installation without authentication', () => {
|
|
125
|
+
f.installation = { deployment: { mode: 'in-cluster' } }
|
|
126
|
+
render()
|
|
127
|
+
expect(host.textContent).toContain('Ask your cluster admin to grant Radar’s ServiceAccount access to update pods/ephemeralcontainers for Pod payments/checkout.')
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
it('explains how to start a debugger outside a hosted session without issuing a named check', () => {
|
|
131
|
+
f.embedded = true
|
|
132
|
+
render()
|
|
133
|
+
expect(host.textContent).toContain('standalone Radar')
|
|
134
|
+
expect(f.probe.mock.lastCall?.[3]).toBe(false)
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
it.each(['unknown', 'unavailable'])('rechecks hosted exec access to a running debugger when %s', state => {
|
|
138
|
+
f.embedded = true
|
|
139
|
+
f.access = state
|
|
140
|
+
f.pod.spec.ephemeralContainers = [{ name: 'debugger', image: 'tools', targetContainerName: 'app' }]
|
|
141
|
+
f.pod.status.ephemeralContainerStatuses = [{ name: 'debugger', state: { running: {} } }]
|
|
142
|
+
render()
|
|
143
|
+
expect(f.probe.mock.lastCall?.slice(3, 5)).toEqual([true, true])
|
|
144
|
+
expect(host.textContent).not.toContain('Ask your cluster admin for access')
|
|
145
|
+
act(() => button('Recheck access')!.click())
|
|
146
|
+
expect(f.recheck).toHaveBeenCalledOnce()
|
|
147
|
+
f.namedExec = true
|
|
148
|
+
render()
|
|
149
|
+
expect(button('Open debug terminal')).toBeDefined()
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
it('offers confirmation only while the named response verifies exec, on a writable Radar', () => {
|
|
153
|
+
f.namedExec = true
|
|
154
|
+
f.access = 'unknown'
|
|
155
|
+
render()
|
|
156
|
+
expect(button('Review attempt for app')).toBeDefined()
|
|
157
|
+
f.checkError = new Error('transport failure')
|
|
158
|
+
render()
|
|
159
|
+
expect(button('Review attempt for app')).toBeUndefined()
|
|
160
|
+
f.checkError = undefined
|
|
161
|
+
f.access = 'denied'
|
|
162
|
+
render()
|
|
163
|
+
expect(button('Review attempt for app')).toBeUndefined()
|
|
164
|
+
f.access = 'unknown'
|
|
165
|
+
f.embedded = true
|
|
166
|
+
render()
|
|
167
|
+
expect(button('Review attempt for app')).toBeUndefined()
|
|
168
|
+
})
|
|
169
|
+
it('keeps unrelated containers out of the shell recovery actions', () => {
|
|
170
|
+
f.pod.spec.containers.push({ name: 'worker' })
|
|
171
|
+
f.pod.status.containerStatuses.push({ name: 'worker', state: { running: {} } })
|
|
172
|
+
f.pod.spec.ephemeralContainers = [{ name: 'network-tools', image: 'tools' }]
|
|
173
|
+
f.pod.status.ephemeralContainerStatuses = [{ name: 'network-tools', state: { running: {} } }]
|
|
174
|
+
render()
|
|
175
|
+
expect(host.textContent).not.toContain('worker')
|
|
176
|
+
expect(host.textContent).not.toContain('network-tools')
|
|
177
|
+
expect(button('Open debug terminal')).toBeUndefined()
|
|
178
|
+
})
|
|
179
|
+
it('keeps verified named exec when the separate update review failed, with no write preview', async () => {
|
|
180
|
+
f.access = 'check_failed'
|
|
181
|
+
f.namedExec = true
|
|
182
|
+
render()
|
|
183
|
+
expect(host.textContent).toContain('Kubernetes couldn’t complete the check')
|
|
184
|
+
expect(button('Recheck access')).toBeDefined()
|
|
185
|
+
expect(button('Review debug container')).toBeUndefined()
|
|
186
|
+
expect(host.textContent).not.toContain('Ask your cluster admin for access')
|
|
187
|
+
function Details() {
|
|
188
|
+
const access = usePodDetailAccess(f.pod, { canExec: false, canOpenEphemeralTerminal: false })
|
|
189
|
+
return <output>{String(access.canExec)} {access.debugImage ?? 'no preview'}</output>
|
|
190
|
+
}
|
|
191
|
+
act(() => root.render(<Details/>))
|
|
192
|
+
expect(host.textContent).toBe('true no preview')
|
|
193
|
+
})
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { type ReactNode, useState } from 'react'
|
|
2
|
+
import { Terminal } from 'lucide-react'
|
|
3
|
+
import { formatAge, getRunningEphemeralContainers, useOpenTerminal } from '@skyhook-io/k8s-ui'
|
|
4
|
+
import { PodDebugPermission } from '../resources/PodDebugPermission'
|
|
5
|
+
import { useResource } from '../../api/client'
|
|
6
|
+
import { connectionHeaderValue, useCurrentConnectionId } from '../../api/connectionBinding'
|
|
7
|
+
import { getApiBase } from '../../api/config'
|
|
8
|
+
import { usePodDebugAccess } from '../../api/podDebug'
|
|
9
|
+
import { useNavCustomization } from '../../context/NavCustomization'
|
|
10
|
+
import { useCapabilitiesContext, useNamespacedCapabilities } from '../../contexts/CapabilitiesContext'
|
|
11
|
+
import { PodDebugAction, debugAccessMessage, runningPodDebugTargets, type PodDebugTarget } from '../resources/PodDebugAction'
|
|
12
|
+
|
|
13
|
+
interface RecoveryTarget {
|
|
14
|
+
namespace: string; name: string; uid: string; target: string; connection?: string; base: string; podDetailsLink?: ReactNode
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function MissingShellDebug(props: RecoveryTarget) {
|
|
18
|
+
const { namespace, name, uid, target, connection, base, podDetailsLink } = props
|
|
19
|
+
const currentConnection = useCurrentConnectionId()
|
|
20
|
+
const sameCluster = currentConnection === connection && getApiBase() === base
|
|
21
|
+
const podQuery = useResource<PodDebugTarget>('pods', namespace, name, undefined, { enabled: sameCluster })
|
|
22
|
+
const pod = podQuery.data
|
|
23
|
+
if (!sameCluster) return <p className="text-xs text-theme-text-secondary">The cluster connection changed. Open the Pod on the current cluster to start a terminal.</p>
|
|
24
|
+
if (podQuery.error) return <div className="space-y-2 text-xs text-theme-text-secondary">
|
|
25
|
+
<p>Radar couldn’t read the Pod to check its debug options.</p>
|
|
26
|
+
<button className="btn-secondary px-2 py-1" onClick={() => void podQuery.refetch()}>Check Pod again</button>
|
|
27
|
+
</div>
|
|
28
|
+
if (!pod) return <p className="text-xs text-theme-text-secondary">Checking debug options…</p>
|
|
29
|
+
if (pod.metadata.uid !== uid) return <p className="text-xs text-theme-text-secondary">This Pod was replaced. Open its details to start a new terminal. {podDetailsLink}</p>
|
|
30
|
+
const targets = runningPodDebugTargets(pod)
|
|
31
|
+
if (!targets?.includes(target)) return <p className="max-w-md text-xs text-theme-text-secondary">Debug recovery needs a running Linux container. Check the container state in Pod details.</p>
|
|
32
|
+
return <DebugOptions {...props} pod={pod}/>
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function DebugOptions({ namespace, name, uid, target, connection, base, pod }: RecoveryTarget & {pod: PodDebugTarget}) {
|
|
36
|
+
const { embedded } = useNavCustomization()
|
|
37
|
+
const { deployment } = useCapabilitiesContext()
|
|
38
|
+
const { podDebugImage, canOpenEphemeralTerminal } = useNamespacedCapabilities(namespace)
|
|
39
|
+
const execOnly = !!embedded || deployment?.mode === 'cloud'
|
|
40
|
+
const current = () => getApiBase() === base && connectionHeaderValue() === connection
|
|
41
|
+
const running = getRunningEphemeralContainers(pod).filter(c => c.targetContainerName === target)
|
|
42
|
+
const { query, support, recheckSupport, unverifiedImage, unverifiedReview, recheckAccess } = usePodDebugAccess(namespace, name, uid,
|
|
43
|
+
execOnly ? !!running.length && !canOpenEphemeralTerminal : !running.length && !podDebugImage,
|
|
44
|
+
execOnly, !execOnly && !running.length ? podDebugImage : undefined)
|
|
45
|
+
const openTerminal = useOpenTerminal()
|
|
46
|
+
const [choice, setChoice] = useState('')
|
|
47
|
+
const access = query.error ? undefined : query.data
|
|
48
|
+
const allowedImage = query.error ? undefined : access?.state === 'allowed' ? access.image :
|
|
49
|
+
access?.state === 'denied' || access?.state === 'unavailable' || access?.state === 'check_failed' ? undefined : podDebugImage
|
|
50
|
+
const accessMessage = debugAccessMessage(execOnly, query.error, access?.state, pod)
|
|
51
|
+
const denied = access?.state === 'denied'
|
|
52
|
+
const canCreate = !execOnly && !running.length
|
|
53
|
+
const image = canCreate ? allowedImage || unverifiedImage : undefined
|
|
54
|
+
const showRecheck = canCreate && (!unverifiedImage || !!unverifiedReview?.refused) && !allowedImage && support === 'supported' && (!query.isPending || !!query.error) && access?.state !== 'unavailable'
|
|
55
|
+
return <div className="flex w-full min-w-0 max-w-md flex-col items-center gap-2 text-xs text-theme-text-secondary">
|
|
56
|
+
{renderOptions()}
|
|
57
|
+
<PodDebugAction pod={pod} defaultImage={image} failedContainer={target} unverifiedReview={image ? unverifiedReview : undefined}
|
|
58
|
+
debugDenial={canCreate && denied ? { refusal: access.refusedAttempt?.message } : undefined}
|
|
59
|
+
hideLauncher={!image || (!!unverifiedReview?.refused && !unverifiedReview.refused.rechecked)}
|
|
60
|
+
reviewStatus={{ message: accessMessage, refusal: query.data?.refusedAttempt?.message,
|
|
61
|
+
recheck: execOnly ? undefined : recheckAccess, checking: query.isFetching }} />
|
|
62
|
+
{showRecheck && <button className="btn-secondary rounded px-2 py-1" disabled={query.isFetching} onClick={() => void recheckAccess()}>{query.isFetching ? 'Checking…' : 'Recheck access'}</button>}
|
|
63
|
+
</div>
|
|
64
|
+
|
|
65
|
+
function renderOptions() {
|
|
66
|
+
if (running.length && support === 'supported' && (!execOnly || canOpenEphemeralTerminal || (!query.error && query.data?.exec))) {
|
|
67
|
+
const selected = running.find(c => c.name === choice) ?? running[0]
|
|
68
|
+
return <div className="flex w-full min-w-0 max-w-md flex-col items-center gap-2">
|
|
69
|
+
<p className="text-xs text-theme-text-secondary [overflow-wrap:anywhere]">{running.length === 1 ? <>A debug container using <code className="inline-code">{selected.image}</code> is running</> : `${running.length} debug containers are running`} for container <code className="inline-code">{target}</code>.</p>
|
|
70
|
+
{running.length > 1 && <select aria-label="Running debug container" className="w-full min-w-0 max-w-full rounded border border-theme-border bg-theme-surface px-2 py-1 text-xs"
|
|
71
|
+
value={selected.name} onChange={event => setChoice(event.target.value)}>
|
|
72
|
+
{running.map(c => <option key={c.name} value={c.name}>{c.startedAt && `${formatAge(c.startedAt)} ago · `}{c.name} · {c.image}</option>)}
|
|
73
|
+
</select>}
|
|
74
|
+
<button className="btn-brand flex items-center gap-2 rounded px-3 py-1.5 text-xs" onClick={() => {
|
|
75
|
+
if (current()) openTerminal({ namespace, podName: name, containerName: selected.name, containers: [selected.name],
|
|
76
|
+
debugSession: { podUID: uid, image: selected.image, connectionId: connection, apiBase: base } })
|
|
77
|
+
}}><Terminal className="h-3.5 w-3.5"/>Open debug terminal</button>
|
|
78
|
+
</div>
|
|
79
|
+
}
|
|
80
|
+
if (execOnly) {
|
|
81
|
+
if (running.length && support === 'unknown') return <div className="flex flex-col items-center gap-2 text-xs text-theme-text-secondary">
|
|
82
|
+
<p>Radar hasn’t confirmed whether this cluster can reopen the running debugger.</p>
|
|
83
|
+
<button className="btn-secondary rounded px-2 py-1" onClick={() => void recheckSupport()}>Recheck support</button>
|
|
84
|
+
</div>
|
|
85
|
+
if (running.length && support === 'supported' && !canOpenEphemeralTerminal) {
|
|
86
|
+
return <div className="flex flex-col items-center gap-2 text-xs text-theme-text-secondary">
|
|
87
|
+
<p>{query.isFetching ? 'Checking whether you can open this debugger…' : query.data?.state === 'unavailable' && !query.error ? 'A debugger is already running. Ask your administrator to check your Pod exec access and whether this Radar allows exec.' : 'Radar couldn’t verify terminal access to this running debugger.'}</p>
|
|
88
|
+
{!query.isFetching && <button className="btn-secondary rounded px-2 py-1" onClick={() => void query.refetch()}>Recheck access</button>}
|
|
89
|
+
</div>
|
|
90
|
+
}
|
|
91
|
+
if (running.length && support === 'unsupported') return <p className="max-w-md text-xs text-theme-text-secondary">A debug container is already running. Upgrade this cluster’s Radar to reopen it here, or open a terminal to that container with kubectl.</p>
|
|
92
|
+
return <p className="max-w-md text-xs text-theme-text-secondary">Run <code className="inline-code">kubectl debug</code> against this cluster with an approved image, or open this Pod in standalone Radar. Your kubectl identity needs permission to patch <code className="inline-code">pods/ephemeralcontainers</code>. <code className="mt-2 block select-all break-all rounded bg-theme-elevated p-2 text-left">kubectl --context CONTEXT -n {namespace} debug {name} --target={target} --image=APPROVED_IMAGE -it</code></p>
|
|
93
|
+
}
|
|
94
|
+
if (allowedImage) return null
|
|
95
|
+
if (support !== 'supported') {
|
|
96
|
+
return support === 'unsupported' ? <p className="max-w-sm text-xs text-theme-text-secondary">Upgrade Radar to check debug access for this Pod, or ask your cluster administrator to help start a debug container.</p> : <div className="flex flex-col items-center gap-2 text-xs text-theme-text-secondary">
|
|
97
|
+
<p>Radar hasn’t confirmed debug support for this cluster.</p>
|
|
98
|
+
<button className="btn-secondary rounded px-2 py-1" onClick={() => void recheckSupport()}>Recheck support</button>
|
|
99
|
+
</div>
|
|
100
|
+
}
|
|
101
|
+
if (query.isPending && !query.error) return <p className="text-xs text-theme-text-secondary">Checking access for this Pod…</p>
|
|
102
|
+
if (access?.state === 'unavailable') return <div className="flex max-w-md flex-col items-center gap-2 text-xs text-theme-text-secondary">
|
|
103
|
+
<p>A debug terminal is unavailable for this Pod. Ask your administrator to check Pod exec access and whether exec is enabled on this Radar.</p>
|
|
104
|
+
<button className="btn-secondary rounded px-2 py-1" disabled={query.isFetching} onClick={() => void query.refetch()}>Recheck access</button>
|
|
105
|
+
</div>
|
|
106
|
+
return <div className="flex max-w-md flex-col items-center gap-2 text-xs text-theme-text-secondary">
|
|
107
|
+
<p>{denied ? <PodDebugPermission namespace={namespace} name={name} /> : accessMessage}</p>
|
|
108
|
+
{query.data?.refusedAttempt && !denied && <div role="status" className="max-w-full break-words text-warning-text">
|
|
109
|
+
<p>The last debug request was refused.</p><p>{query.data.refusedAttempt.message}</p>
|
|
110
|
+
{unverifiedImage && !query.data.refusedAttempt.rechecked && <p className="text-theme-text-secondary">Recheck access to review another attempt.</p>}
|
|
111
|
+
</div>}
|
|
112
|
+
</div>
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot } from 'react-dom/client'
|
|
4
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
5
|
+
import { afterEach, expect, it, vi } from 'vitest'
|
|
6
|
+
import { PodDebugSession } from './PodDebugSession'
|
|
7
|
+
|
|
8
|
+
;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
|
|
9
|
+
const session = { apiBase: '/api', podUID: 'reviewed', image: 'mirror.example/tools' }
|
|
10
|
+
const opts = { namespace: 'demo', podName: 'api', containerName: 'debug-fixture', session }
|
|
11
|
+
const key = ['pod-debug-startup', '/api', undefined, 'reviewed', 'debug-fixture']
|
|
12
|
+
const client = new QueryClient()
|
|
13
|
+
let root: ReturnType<typeof createRoot>
|
|
14
|
+
async function mount() {
|
|
15
|
+
const host = document.createElement('div')
|
|
16
|
+
document.body.append(host)
|
|
17
|
+
root = createRoot(host)
|
|
18
|
+
await act(async () => {
|
|
19
|
+
root.render(<QueryClientProvider client={client}><PodDebugSession {...opts}><b>attached</b></PodDebugSession></QueryClientProvider>)
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
act(() => root.unmount())
|
|
24
|
+
document.body.replaceChildren()
|
|
25
|
+
client.clear()
|
|
26
|
+
vi.unstubAllGlobals()
|
|
27
|
+
})
|
|
28
|
+
function reply(state: object, uid = 'reviewed') {
|
|
29
|
+
return new Response(JSON.stringify({ resource: {
|
|
30
|
+
metadata: { uid }, status: { phase: 'Running', ephemeralContainerStatuses: [{ name: 'debug-fixture', state }] },
|
|
31
|
+
} }))
|
|
32
|
+
}
|
|
33
|
+
async function until(phrase: string) {
|
|
34
|
+
await act(async () => { await vi.waitFor(() => expect(client.getQueryState(key)?.fetchStatus).toBe('idle')) })
|
|
35
|
+
await vi.waitFor(() => expect(document.body.textContent).toContain(phrase))
|
|
36
|
+
}
|
|
37
|
+
it('keeps watching a pull backoff and opens only the accepted container once it runs', async () => {
|
|
38
|
+
const fetch = vi.fn().mockResolvedValueOnce(reply({ waiting: { reason: 'ImagePullBackOff', message: 'registry unavailable' } }))
|
|
39
|
+
.mockResolvedValueOnce(reply({ running: {} }))
|
|
40
|
+
vi.stubGlobal('fetch', fetch)
|
|
41
|
+
await mount()
|
|
42
|
+
await until('ImagePullBackOff')
|
|
43
|
+
expect(document.body.textContent).toContain('registry unavailable')
|
|
44
|
+
expect(document.body.textContent).not.toContain('attached')
|
|
45
|
+
await act(async () => { await client.invalidateQueries({ queryKey: key }) })
|
|
46
|
+
await until('attached')
|
|
47
|
+
expect(fetch.mock.calls.every(([, init]) => !init.method || init.method === 'GET')).toBe(true)
|
|
48
|
+
})
|
|
49
|
+
it.each([
|
|
50
|
+
[() => reply({ waiting: { reason: 'InvalidImageName' } }), 'Start a new debug session with a valid image reference'],
|
|
51
|
+
[() => reply({ waiting: { reason: 'CreateContainerConfigError', message: 'image runs as root' } }), 'Kubernetes could not start the debug container'],
|
|
52
|
+
[() => reply({ terminated: { exitCode: 17, reason: 'Error' } }), 'exited with code 17'],
|
|
53
|
+
[() => reply({ running: {} }, 'replacement'), 'original Pod was replaced'],
|
|
54
|
+
[() => new Response(JSON.stringify({ error: 'pods is forbidden' }), { status: 403 }), 'Access denied'],
|
|
55
|
+
])('keeps a terminal detached when startup cannot succeed (%#)', async (response, message) => {
|
|
56
|
+
vi.stubGlobal('fetch', vi.fn().mockResolvedValueOnce(response()))
|
|
57
|
+
await mount()
|
|
58
|
+
await until(message)
|
|
59
|
+
expect(document.body.textContent).not.toContain('attached')
|
|
60
|
+
})
|