@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
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { useState, type ReactNode } from 'react'
|
|
2
|
+
import { useQuery } from '@tanstack/react-query'
|
|
3
|
+
import { LoaderCircle, RefreshCw } from 'lucide-react'
|
|
4
|
+
import type { DockTab } from '@skyhook-io/k8s-ui'
|
|
5
|
+
import { ApiError, fetchResourceWithRelationships } from '../../api/client'
|
|
6
|
+
import { getApiBase } from '../../api/config'
|
|
7
|
+
import { connectionHeaderValue, useCurrentConnectionId } from '../../api/connectionBinding'
|
|
8
|
+
import type { PodDebugTarget } from '../resources/PodDebugAction'
|
|
9
|
+
|
|
10
|
+
type Session = NonNullable<DockTab['debugSession']>
|
|
11
|
+
|
|
12
|
+
interface Startup {
|
|
13
|
+
state: 'finished' | 'running' | 'waiting' | 'blocked'
|
|
14
|
+
title?: string
|
|
15
|
+
hint?: string
|
|
16
|
+
reason?: string
|
|
17
|
+
message?: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function startup(pod: PodDebugTarget, uid: string, container: string): Startup {
|
|
21
|
+
if (pod.metadata.uid !== uid) return { state: 'finished', title: 'The original Pod was replaced' }
|
|
22
|
+
const status = pod.status.ephemeralContainerStatuses?.find(item => item.name === container)?.state
|
|
23
|
+
if (status?.terminated) {
|
|
24
|
+
const { exitCode, reason, message } = status.terminated
|
|
25
|
+
return { state: 'finished', title: `Debug container exited with code ${exitCode}`, reason, message }
|
|
26
|
+
}
|
|
27
|
+
if (pod.metadata.deletionTimestamp || ['Failed', 'Succeeded'].includes(pod.status.phase ?? '')) {
|
|
28
|
+
return { state: 'finished', title: 'The Pod is terminating or has finished' }
|
|
29
|
+
}
|
|
30
|
+
if (status?.running) return { state: 'running' }
|
|
31
|
+
const waiting = status?.waiting
|
|
32
|
+
switch (waiting?.reason) {
|
|
33
|
+
case 'InvalidImageName':
|
|
34
|
+
return { state: 'finished', title: 'The debug image name is invalid', hint: 'Start a new debug session with a valid image reference.', ...waiting }
|
|
35
|
+
case 'ErrImagePull':
|
|
36
|
+
case 'ImagePullBackOff':
|
|
37
|
+
return { state: 'blocked', title: 'Kubernetes could not pull the debug image', hint: 'Check the image and registry access. The terminal opens if Kubernetes succeeds on a retry.', ...waiting }
|
|
38
|
+
case 'ErrImageNeverPull':
|
|
39
|
+
return { state: 'blocked', title: 'The debug image is missing on the node and pulling is disabled', hint: 'Load the image on the node or start a new session with an available image.', ...waiting }
|
|
40
|
+
case 'CreateContainerConfigError':
|
|
41
|
+
case 'CreateContainerError':
|
|
42
|
+
case 'RunContainerError':
|
|
43
|
+
return { state: 'blocked', title: 'Kubernetes could not start the debug container', hint: 'Inspect the kubelet message. Start a new session if the image or its configuration must change.', ...waiting }
|
|
44
|
+
default:
|
|
45
|
+
return { state: 'waiting', title: 'Waiting for the debug container', ...waiting }
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function PodDebugSession({ namespace, podName, containerName, session, isActive = true, children, podDetailsLink }: {
|
|
50
|
+
namespace: string; podName: string; containerName: string; session: Session; isActive?: boolean; children: ReactNode; podDetailsLink?: ReactNode
|
|
51
|
+
}) {
|
|
52
|
+
const [connected, setConnected] = useState(false)
|
|
53
|
+
const currentConnection = useCurrentConnectionId()
|
|
54
|
+
const current = () => getApiBase() === session.apiBase && connectionHeaderValue() === session.connectionId
|
|
55
|
+
const query = useQuery({
|
|
56
|
+
queryKey: ['pod-debug-startup', session.apiBase, session.connectionId, session.podUID, containerName],
|
|
57
|
+
queryFn: async () => {
|
|
58
|
+
if (!current()) throw new ApiError('The cluster connection changed.', 409)
|
|
59
|
+
const { resource } = await fetchResourceWithRelationships<PodDebugTarget>('pods', namespace, podName)
|
|
60
|
+
if (!current()) throw new ApiError('The cluster connection changed.', 409)
|
|
61
|
+
return startup(resource, session.podUID, containerName)
|
|
62
|
+
},
|
|
63
|
+
enabled: !connected && isActive,
|
|
64
|
+
retry: false,
|
|
65
|
+
refetchInterval: query => query.state.data?.state === 'finished' || query.state.data?.state === 'running' ||
|
|
66
|
+
(query.state.error instanceof ApiError && [403, 404, 409].includes(query.state.error.status)) ? false : query.state.data?.state === 'blocked' ? 5000 : 2000,
|
|
67
|
+
refetchOnWindowFocus: false,
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
if (!connected && !query.error && query.data?.state === 'running' && current()) setConnected(true)
|
|
71
|
+
if (currentConnection !== session.connectionId || getApiBase() !== session.apiBase) return <div role="status" className="p-5 text-sm text-theme-text-secondary">The cluster connection changed. Reopen the Pod to inspect this debug session.</div>
|
|
72
|
+
if (connected) return <>{children}</>
|
|
73
|
+
|
|
74
|
+
const status = query.data
|
|
75
|
+
const error = query.error
|
|
76
|
+
const code = error instanceof ApiError ? error.status : undefined
|
|
77
|
+
const title = code === 403 ? 'Access denied while reading the debug container'
|
|
78
|
+
: code === 404 ? 'The original Pod is gone'
|
|
79
|
+
: code === 409 ? 'The cluster connection changed'
|
|
80
|
+
: error ? 'Could not read the debug container status' : status?.title ?? 'Waiting for the debug container'
|
|
81
|
+
return <div className="flex h-full min-h-32 flex-col justify-center gap-2 overflow-auto bg-theme-base px-5 py-4">
|
|
82
|
+
<h3 className="flex items-center gap-2 font-medium text-theme-text-primary">
|
|
83
|
+
{!error && (!status || status.state === 'waiting') && <LoaderCircle aria-hidden className="h-4 w-4 animate-spin text-theme-text-tertiary" />}
|
|
84
|
+
{title}
|
|
85
|
+
</h3>
|
|
86
|
+
<p className="break-all font-mono text-xs text-theme-text-secondary">{namespace}/{podName} · {containerName} · {session.image}</p>
|
|
87
|
+
{(error || status?.reason || status?.message) && <p className="break-words text-sm text-theme-text-primary">
|
|
88
|
+
{error?.message || [status?.reason, status?.message].filter(Boolean).join(' · ')}
|
|
89
|
+
</p>}
|
|
90
|
+
{status?.state === 'finished' && podDetailsLink}
|
|
91
|
+
{!error && status?.hint && <p className="text-xs text-theme-text-secondary">{status.hint}</p>}
|
|
92
|
+
{!error && (!status || status.state === 'waiting') && <p className="text-xs text-theme-text-secondary">The terminal opens when Kubernetes reports this container is running.</p>}
|
|
93
|
+
{error && code !== 404 && code !== 409 && <button type="button" className="btn-secondary flex w-fit items-center gap-1.5 px-3 py-1.5 text-xs"
|
|
94
|
+
disabled={query.isFetching} onClick={() => { void query.refetch() }}><RefreshCw className="h-3.5 w-3.5" />Check status</button>}
|
|
95
|
+
</div>
|
|
96
|
+
}
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
import { renderToString } from 'react-dom/server'
|
|
2
|
-
import { expect, it, vi } from 'vitest'
|
|
2
|
+
import { beforeEach, expect, it, vi } from 'vitest'
|
|
3
3
|
import type { TerminalTabProps } from '@skyhook-io/k8s-ui'
|
|
4
4
|
import { TerminalTab } from './TerminalTab'
|
|
5
|
-
|
|
6
|
-
vi.
|
|
5
|
+
vi.mock('./PodDebugSession', () => ({ PodDebugSession: ({ children }: { children: React.ReactNode }) => children }))
|
|
6
|
+
const captured = vi.hoisted(() => ({ props: null as TerminalTabProps | null, read: vi.fn((): { data?: unknown } => ({})) }))
|
|
7
|
+
vi.mock('../../api/client', () => ({ useResource: captured.read }))
|
|
8
|
+
vi.mock('@skyhook-io/k8s-ui', async original => ({ ...await original<typeof import('@skyhook-io/k8s-ui')>(), TerminalTab: (props: TerminalTabProps) => { captured.props = props; return null } }))
|
|
7
9
|
vi.mock('../../api/config', async (importOriginal) => ({ ...await importOriginal<typeof import('../../api/config')>(), apiUrl: (path: string) => `/api${path}`, getWsUrl: (path: string) => `ws://localhost/api${path}` }))
|
|
10
|
+
beforeEach(() => captured.read.mockReturnValue({}))
|
|
11
|
+
|
|
8
12
|
it.each([undefined, '/bin/custom+command'])('forwards the executable and context through the shared terminal (%s)', async shell => {
|
|
9
13
|
renderToString(<TerminalTab namespace="app" podName="worker" containerName="app" containers={['app', 'sidecar']} shell={shell} note="Primary" />)
|
|
10
14
|
const props = captured.props!
|
|
11
15
|
expect(props.command).toBe(shell); expect(props.note).toBe('Primary')
|
|
12
|
-
expect(Boolean(props.
|
|
16
|
+
expect(props.createDebugContainer).toBeUndefined(); expect(Boolean(props.renderDebugAction)).toBe(!shell)
|
|
13
17
|
const { wsUrl } = await props.createSession('app')
|
|
14
18
|
const url = new URL(wsUrl)
|
|
15
19
|
expect(url.pathname).toBe('/api/pods/app/worker/exec'); expect(url.searchParams.get('container')).toBe('app')
|
|
16
20
|
expect(url.searchParams.get('shell')).toBe(shell ?? null)
|
|
21
|
+
expect(url.searchParams.has('uid')).toBe(false)
|
|
22
|
+
const retry = await props.createSession('app', 'reviewed-pod')
|
|
23
|
+
expect(new URL(retry.wsUrl).searchParams.get('uid')).toBe('reviewed-pod')
|
|
17
24
|
})
|
|
18
25
|
|
|
19
26
|
it('reconnects on the connection the tab was opened on, not the latest', async () => {
|
|
@@ -26,3 +33,40 @@ it('reconnects on the connection the tab was opened on, not the latest', async (
|
|
|
26
33
|
expect(new URL(wsUrl).searchParams.get('connection')).toBe('n-1')
|
|
27
34
|
resetConnectionBindingForTest()
|
|
28
35
|
})
|
|
36
|
+
|
|
37
|
+
it('reconnects an existing debug session to its reviewed connection without offering another container', async () => {
|
|
38
|
+
const { observeConnectionStatus, resetConnectionBindingForTest } = await import('../../api/connectionBinding')
|
|
39
|
+
observeConnectionStatus({ connectionId: 'next-cluster' })
|
|
40
|
+
renderToString(<TerminalTab namespace="demo" podName="api" containerName="debug-1" containers={['debug-1']} debugSession={{ connectionId: 'reviewed-cluster', apiBase: '/api', podUID: 'reviewed', image: 'mirror.example/debug' }} />)
|
|
41
|
+
const { wsUrl } = await captured.props!.createSession('debug-1')
|
|
42
|
+
expect(new URL(wsUrl).searchParams.get('connection')).toBe('reviewed-cluster')
|
|
43
|
+
expect(new URL(wsUrl).searchParams.get('uid')).toBe('reviewed')
|
|
44
|
+
expect(renderToString(captured.props!.renderDebugAction!('debug-1', 'reviewed'))).toContain('different image')
|
|
45
|
+
resetConnectionBindingForTest()
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('opens and retries an ordinary terminal on the UID captured in Pod details', async () => {
|
|
49
|
+
renderToString(<TerminalTab namespace="demo" podName="api" podUID="fresh" containerName="tools" containers={['tools']} />)
|
|
50
|
+
expect(new URL((await captured.props!.createSession('tools')).wsUrl).searchParams.get('uid')).toBe('fresh')
|
|
51
|
+
expect(new URL((await captured.props!.createSession('tools', 'other')).wsUrl).searchParams.get('uid')).toBe('fresh')
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('only offers running regular containers and native sidecars of the original Pod', () => {
|
|
55
|
+
captured.read.mockReturnValue({ data: {
|
|
56
|
+
metadata: { uid: 'original' },
|
|
57
|
+
spec: {
|
|
58
|
+
containers: [{ name: 'api' }, { name: 'worker' }],
|
|
59
|
+
initContainers: [{ name: 'mesh', restartPolicy: 'Always' }, { name: 'init' }],
|
|
60
|
+
},
|
|
61
|
+
status: {
|
|
62
|
+
containerStatuses: [{ name: 'api', state: { terminated: {} } }, { name: 'worker', state: { running: {} } }],
|
|
63
|
+
initContainerStatuses: [{ name: 'mesh', state: { running: {} } }, { name: 'init', state: { running: {} } }],
|
|
64
|
+
},
|
|
65
|
+
} })
|
|
66
|
+
const render = (uid: string) => renderToString(<TerminalTab namespace="demo" podName="pod" podUID={uid} containerName="api" containers={['api', 'worker', 'mesh']} />)
|
|
67
|
+
render('original')
|
|
68
|
+
expect(captured.props?.containers).toEqual(['worker', 'mesh'])
|
|
69
|
+
expect(captured.props?.containerName).toBe('api')
|
|
70
|
+
render('replacement')
|
|
71
|
+
expect(captured.props?.containers).toEqual([])
|
|
72
|
+
})
|
|
@@ -1,50 +1,72 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import { Link } from 'react-router-dom'
|
|
3
|
+
import { relatedResourcePath } from '../../utils/navigation'
|
|
4
|
+
import { getExecContainerNames, TerminalTab as SharedTerminalTab, type DockTab } from '@skyhook-io/k8s-ui'
|
|
5
|
+
import { getApiBase, getWsUrl } from '../../api/config'
|
|
6
|
+
import { useResource } from '../../api/client'
|
|
7
|
+
import type { PodDebugTarget } from '../resources/PodDebugAction'
|
|
8
|
+
import { MissingShellDebug } from './MissingShellDebug'
|
|
9
|
+
import { PodDebugSession } from './PodDebugSession'
|
|
10
|
+
import { useCurrentConnectionId, useOpenedConnection, withConnectionParam } from '../../api/connectionBinding'
|
|
6
11
|
|
|
7
12
|
interface TerminalTabProps {
|
|
8
13
|
namespace: string
|
|
9
14
|
podName: string
|
|
15
|
+
podUID?: string
|
|
10
16
|
containerName: string
|
|
17
|
+
onContainerChange?: (name: string) => void
|
|
11
18
|
containers: string[]
|
|
12
19
|
isActive?: boolean
|
|
13
20
|
shell?: string
|
|
14
21
|
note?: string
|
|
22
|
+
debugSession?: DockTab['debugSession']
|
|
23
|
+
onLeaveTerminal?: () => void
|
|
15
24
|
}
|
|
16
25
|
|
|
17
|
-
export function TerminalTab({ namespace, podName, containerName, containers, isActive, shell, note }: TerminalTabProps) {
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
export function TerminalTab({ namespace, podName, podUID, containerName, containers, onContainerChange, isActive, shell, note, debugSession, onLeaveTerminal }: TerminalTabProps) {
|
|
27
|
+
const openedConnection = useOpenedConnection()
|
|
28
|
+
const [openedBase] = useState(getApiBase)
|
|
29
|
+
const connection = debugSession ? debugSession.connectionId : openedConnection
|
|
30
|
+
const base = debugSession?.apiBase ?? openedBase
|
|
31
|
+
const currentConnection = useCurrentConnectionId()
|
|
32
|
+
const sameConnection = currentConnection === connection && getApiBase() === base
|
|
33
|
+
const checkTargets = !!podUID && !shell && !debugSession && containers.length > 1
|
|
34
|
+
const pod = useResource<PodDebugTarget>('pods', namespace, podName, undefined, { enabled: checkTargets && sameConnection && isActive !== false })
|
|
35
|
+
const currentPod = sameConnection && !pod.error && pod.data?.metadata.uid === podUID ? pod.data : undefined
|
|
36
|
+
const pickerContainers = checkTargets ? getExecContainerNames(currentPod, { runningOnly: true }) : containers
|
|
37
|
+
const podDetailsLink = sameConnection && <Link
|
|
38
|
+
className="mb-2 inline-block text-xs text-accent underline underline-offset-2"
|
|
39
|
+
title="Close this terminal tab and open the current Pod"
|
|
40
|
+
onClick={event => { if (!event.ctrlKey && !event.metaKey && !event.shiftKey && !event.altKey && event.button === 0) onLeaveTerminal?.() }}
|
|
41
|
+
to={relatedResourcePath({ kind: 'Pod', namespace, name: podName })}
|
|
42
|
+
>Open current Pod details</Link>
|
|
43
|
+
const createSession = async (container: string, failedPodUID?: string) => {
|
|
44
|
+
const uid = debugSession?.podUID ?? podUID ?? failedPodUID
|
|
45
|
+
if (getApiBase() !== base) throw new Error('The cluster connection changed. Reopen the Pod to start a terminal.')
|
|
46
|
+
return {
|
|
47
|
+
wsUrl: withConnectionParam(getWsUrl(`/pods/${namespace}/${podName}/exec?container=${encodeURIComponent(container)}${uid ? `&uid=${encodeURIComponent(uid)}` : ''}${shell ? `&shell=${encodeURIComponent(shell)}` : ''}`), connection),
|
|
33
48
|
}
|
|
34
|
-
return response.json()
|
|
35
49
|
}
|
|
36
50
|
|
|
37
|
-
|
|
51
|
+
const terminal = (
|
|
38
52
|
<SharedTerminalTab
|
|
39
53
|
namespace={namespace}
|
|
40
54
|
podName={podName}
|
|
41
55
|
containerName={containerName}
|
|
42
|
-
containers={
|
|
56
|
+
containers={pickerContainers}
|
|
57
|
+
onContainerChange={onContainerChange}
|
|
43
58
|
isActive={isActive}
|
|
44
59
|
createSession={createSession}
|
|
45
|
-
|
|
60
|
+
podDetailsLink={podDetailsLink}
|
|
61
|
+
renderDebugAction={shell ? undefined : debugSession ? () => <p className="max-w-md text-xs text-theme-text-secondary">
|
|
62
|
+
This debug image has no usable shell. Open Pod details to choose another running container or start a debugger with a different image. {podDetailsLink}
|
|
63
|
+
</p> : (target, uid) =>
|
|
64
|
+
<MissingShellDebug key={JSON.stringify([uid,target])} namespace={namespace} name={podName} target={target} uid={uid} connection={connection} base={base} podDetailsLink={podDetailsLink} />}
|
|
46
65
|
note={note}
|
|
47
66
|
command={shell}
|
|
48
67
|
/>
|
|
49
68
|
)
|
|
69
|
+
return debugSession ? <PodDebugSession namespace={namespace} podName={podName} containerName={containerName} session={debugSession} isActive={isActive} podDetailsLink={podDetailsLink}>
|
|
70
|
+
{terminal}
|
|
71
|
+
</PodDebugSession> : terminal
|
|
50
72
|
}
|
|
@@ -4,8 +4,11 @@ import { createRoot, type Root } from 'react-dom/client'
|
|
|
4
4
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
5
5
|
import { WorkloadLogsTab } from './WorkloadLogsTab'
|
|
6
6
|
|
|
7
|
-
const state = vi.hoisted(() => ({ targets: [] as Array<{ kind: string; name: string; role?: string; snapshotOnly?: boolean }> }))
|
|
7
|
+
const state = vi.hoisted(() => ({ replicaSetSupport: true, supportCheckFailed: false, targets: [] as Array<{ kind: string; name: string; role?: string; snapshotOnly?: boolean }> }))
|
|
8
8
|
vi.mock('../../api/client', () => ({
|
|
9
|
+
useRadarFeature: () => state.supportCheckFailed
|
|
10
|
+
? { support: 'unknown', blockedReason: "Couldn't check this cluster's Radar support. Refresh to try again." }
|
|
11
|
+
: state.replicaSetSupport ? { support: 'supported' } : { support: 'unsupported', upgrade: { feature: 'Combined ReplicaSet logs' } },
|
|
9
12
|
useResource: (_kind: string, _namespace: string, name: string) => ({
|
|
10
13
|
data: { metadata: { uid: name }, spec: { replicatedJobs: [{ name: name === 'first' ? 'workers' : 'leader' }] } },
|
|
11
14
|
}),
|
|
@@ -13,6 +16,7 @@ vi.mock('../../api/client', () => ({
|
|
|
13
16
|
data: { collection: 'members', runs: [{ group: 'batch', kind: 'jobs', namespace, name: `${name}-0`, phase: 'Running', active: true }], total: 1 },
|
|
14
17
|
}),
|
|
15
18
|
}))
|
|
19
|
+
vi.mock('../../contexts/CapabilitiesContext', () => ({ useNamespacedCapabilities: () => ({ canViewLogs: true }) }))
|
|
16
20
|
vi.mock('../logs/WorkloadLogsViewer', () => ({
|
|
17
21
|
WorkloadLogsViewer: (props: { kind: string; name: string; role?: string; snapshotOnly?: boolean }) => {
|
|
18
22
|
state.targets.push(props)
|
|
@@ -25,6 +29,8 @@ let root: Root
|
|
|
25
29
|
let element: HTMLDivElement
|
|
26
30
|
beforeEach(() => {
|
|
27
31
|
state.targets = []
|
|
32
|
+
state.replicaSetSupport = true
|
|
33
|
+
state.supportCheckFailed = false
|
|
28
34
|
element = document.createElement('div')
|
|
29
35
|
document.body.appendChild(element)
|
|
30
36
|
root = createRoot(element)
|
|
@@ -64,3 +70,20 @@ describe('dock JobSet logs', () => {
|
|
|
64
70
|
expect(element.querySelector('[data-log-target="jobs/second-0"]')).not.toBeNull()
|
|
65
71
|
})
|
|
66
72
|
})
|
|
73
|
+
|
|
74
|
+
describe('dock ReplicaSet logs', () => {
|
|
75
|
+
it('checks the connected Radar before following a ReplicaSet', async () => {
|
|
76
|
+
await render('web-v2', 'ReplicaSet')
|
|
77
|
+
expect(state.targets.at(-1)).toMatchObject({ kind: 'replicasets', name: 'web-v2' })
|
|
78
|
+
state.targets = []
|
|
79
|
+
state.replicaSetSupport = false
|
|
80
|
+
await render('web-v2', 'replicasets')
|
|
81
|
+
expect(state.targets).toEqual([])
|
|
82
|
+
expect(element.textContent).toContain('newer Radar')
|
|
83
|
+
state.supportCheckFailed = true
|
|
84
|
+
await render('web-v2', 'replicasets')
|
|
85
|
+
expect(state.targets).toEqual([])
|
|
86
|
+
expect(element.textContent).toContain("Couldn't check")
|
|
87
|
+
expect(element.textContent).not.toContain('newer Radar')
|
|
88
|
+
})
|
|
89
|
+
})
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { AlertBanner, PaneLoader, RadarUpgradeNote } from '@skyhook-io/k8s-ui'
|
|
2
|
+
import { useRadarFeature } from '../../api/client'
|
|
3
|
+
import { useNamespacedCapabilities } from '../../contexts/CapabilitiesContext'
|
|
1
4
|
import { WorkloadLogsViewer } from '../logs/WorkloadLogsViewer'
|
|
2
5
|
import { ScheduledWorkloadLogsViewer } from '../logs/ScheduledWorkloadLogsViewer'
|
|
3
6
|
|
|
@@ -8,6 +11,16 @@ interface WorkloadLogsTabProps {
|
|
|
8
11
|
viewNamespaces?: string[]
|
|
9
12
|
}
|
|
10
13
|
|
|
14
|
+
function ReplicaSetDockLogs({ namespace, name }: { namespace: string; name: string }) {
|
|
15
|
+
const { support, upgrade, blockedReason } = useRadarFeature('replicaSetLogs')
|
|
16
|
+
const { canViewLogs, logsUnknown } = useNamespacedCapabilities(namespace)
|
|
17
|
+
if (upgrade) return <RadarUpgradeNote requirement={upgrade} />
|
|
18
|
+
if (blockedReason) return <AlertBanner variant="info" title={blockedReason} />
|
|
19
|
+
if (support !== 'supported') return <PaneLoader label="Checking ReplicaSet log support…" className="h-full" />
|
|
20
|
+
if (!canViewLogs && !logsUnknown) return <AlertBanner variant="warning" title="Pod logs are restricted in this namespace." />
|
|
21
|
+
return <WorkloadLogsViewer kind="replicasets" namespace={namespace} name={name} />
|
|
22
|
+
}
|
|
23
|
+
|
|
11
24
|
export function WorkloadLogsTab({
|
|
12
25
|
namespace,
|
|
13
26
|
workloadKind,
|
|
@@ -15,6 +28,9 @@ export function WorkloadLogsTab({
|
|
|
15
28
|
viewNamespaces,
|
|
16
29
|
}: WorkloadLogsTabProps) {
|
|
17
30
|
const normalizedKind = workloadKind.toLowerCase()
|
|
31
|
+
if (normalizedKind === 'replicasets' || normalizedKind === 'replicaset') {
|
|
32
|
+
return <ReplicaSetDockLogs namespace={namespace} name={workloadName} />
|
|
33
|
+
}
|
|
18
34
|
const isScheduled = normalizedKind === 'cronjob' || normalizedKind === 'cronjobs' ||
|
|
19
35
|
normalizedKind === 'cronworkflow' || normalizedKind === 'cronworkflows' ||
|
|
20
36
|
normalizedKind === 'workflowtemplate' || normalizedKind === 'workflowtemplates' ||
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot, type Root } from 'react-dom/client'
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
5
|
+
import { CommandFact } from './BatchExecutionView'
|
|
6
|
+
|
|
7
|
+
vi.mock('../../api/client', () => ({}))
|
|
8
|
+
|
|
9
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
|
|
10
|
+
|
|
11
|
+
const script = "sh -c echo '{{inputs.parameters.greeting}}, {{inputs.parameters.target}}'\nset -e\nrun-the-export --all"
|
|
12
|
+
|
|
13
|
+
let root: Root
|
|
14
|
+
let host: HTMLDivElement
|
|
15
|
+
let scrollHeight = 0
|
|
16
|
+
|
|
17
|
+
function render(command = script) {
|
|
18
|
+
host = document.createElement('div')
|
|
19
|
+
document.body.appendChild(host)
|
|
20
|
+
root = createRoot(host)
|
|
21
|
+
act(() => root.render(<CommandFact command={command} />))
|
|
22
|
+
return host.querySelector<HTMLElement>('[data-testid="definition-command"]')!
|
|
23
|
+
}
|
|
24
|
+
const button = (name: string) => [...host.querySelectorAll('button')].find((b) => b.textContent === name || b.getAttribute('aria-label') === name)
|
|
25
|
+
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
scrollHeight = 0
|
|
28
|
+
Object.defineProperty(HTMLElement.prototype, 'scrollHeight', { configurable: true, get: () => scrollHeight })
|
|
29
|
+
Object.defineProperty(HTMLElement.prototype, 'clientHeight', { configurable: true, get: () => 64 })
|
|
30
|
+
})
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
act(() => root.unmount())
|
|
33
|
+
host.remove()
|
|
34
|
+
vi.unstubAllGlobals()
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
describe('CommandFact', () => {
|
|
38
|
+
it('shows the whole command on its own line, keeping script line breaks, with no toggle when it fits', () => {
|
|
39
|
+
scrollHeight = 64
|
|
40
|
+
const code = render()
|
|
41
|
+
expect(code.textContent).toBe(script)
|
|
42
|
+
expect(code.className).toContain('whitespace-pre-wrap')
|
|
43
|
+
expect(code.className).toContain('[overflow-wrap:anywhere]')
|
|
44
|
+
expect(button('Show all')).toBeUndefined()
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('clamps a command taller than the card and expands it in place', () => {
|
|
48
|
+
scrollHeight = 200
|
|
49
|
+
const code = render()
|
|
50
|
+
expect(code.className).toContain('line-clamp-4')
|
|
51
|
+
const toggle = button('Show all')!
|
|
52
|
+
expect(toggle.getAttribute('aria-expanded')).toBe('false')
|
|
53
|
+
act(() => toggle.click())
|
|
54
|
+
expect(code.className).not.toContain('line-clamp-4')
|
|
55
|
+
expect(button('Show less')!.getAttribute('aria-expanded')).toBe('true')
|
|
56
|
+
act(() => button('Show less')!.click())
|
|
57
|
+
expect(code.className).toContain('line-clamp-4')
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('copies the whole command, not the clamped text', async () => {
|
|
61
|
+
scrollHeight = 200
|
|
62
|
+
const writeText = vi.fn().mockResolvedValue(undefined)
|
|
63
|
+
vi.stubGlobal('navigator', { clipboard: { writeText } })
|
|
64
|
+
render()
|
|
65
|
+
await act(async () => { button('Copy command')!.click() })
|
|
66
|
+
expect(writeText).toHaveBeenCalledWith(script)
|
|
67
|
+
expect(button('Command copied')).toBeDefined()
|
|
68
|
+
})
|
|
69
|
+
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useEffect, useMemo, useRef, useState, type ComponentType, type ReactNode } from 'react'
|
|
2
|
-
import { Activity, GitBranch, Terminal } from 'lucide-react'
|
|
1
|
+
import { useEffect, useLayoutEffect, useMemo, useRef, useState, type ComponentType, type ReactNode } from 'react'
|
|
2
|
+
import { Activity, Check, Copy, GitBranch, Terminal } from 'lucide-react'
|
|
3
3
|
import { clsx } from 'clsx'
|
|
4
4
|
import {
|
|
5
5
|
Collapse,
|
|
@@ -14,7 +14,9 @@ import {
|
|
|
14
14
|
podStatusClass,
|
|
15
15
|
podStatusLabel,
|
|
16
16
|
workloadPodDetail,
|
|
17
|
+
WorkflowShutdownBadge,
|
|
17
18
|
} from '@skyhook-io/k8s-ui'
|
|
19
|
+
import { copyText } from '@skyhook-io/k8s-ui/utils/clipboard'
|
|
18
20
|
import { buildWorkflowExecutionModel, flattenWorkflowExecution, type WorkflowExecutionActivity, type WorkflowExecutionModel, type WorkflowExecutionNode, type WorkflowExecutionRow, type WorkflowTemplateReference } from '@skyhook-io/k8s-ui/utils/workflow-execution'
|
|
19
21
|
import { midTruncate } from '@skyhook-io/k8s-ui/utils/format'
|
|
20
22
|
import { isJobSetV1Alpha2 } from '@skyhook-io/k8s-ui/components/resources/resource-utils-jobset-lws'
|
|
@@ -27,6 +29,7 @@ import { getScaledJobStatus } from '../resources/resource-utils-keda'
|
|
|
27
29
|
import { Tooltip } from '../ui/Tooltip'
|
|
28
30
|
import { ImageFilesystemModal } from '../resources/ImageFilesystemModal'
|
|
29
31
|
import { useIsAuthEnabled } from '../../contexts/CapabilitiesContext'
|
|
32
|
+
import { WorkflowRunStopAction } from './WorkflowRunStopAction'
|
|
30
33
|
import { executionDefinitionDiffers, executionDefinitionSummary, type ExecutionDefinitionSummary, type ExecutionUnitSummary } from './execution-definition'
|
|
31
34
|
import { batchRunHasContainerOutcome, batchRunNextStep, isFailedRunPhase, type BatchRunNextStep } from './batch-run-actions'
|
|
32
35
|
import { JobSetAdmission } from './JobSetAdmission'
|
|
@@ -254,6 +257,17 @@ function BatchExecutionContent({ leadContent, kind, apiKind, namespace, name, re
|
|
|
254
257
|
{ enabled: Boolean(fetchTarget), refetchInterval: selectedRun?.active ? 5000 : false },
|
|
255
258
|
)
|
|
256
259
|
const selectedResource = scheduled ? selectedResourceQuery.data : resource
|
|
260
|
+
// A scheduled parent's selected run is a child Workflow with no action bar
|
|
261
|
+
// of its own here; a standalone Workflow already has Stop in its bar.
|
|
262
|
+
// An older Radar's run rows carry no group; the Workflow object's own
|
|
263
|
+
// apiVersion still decides, in WorkflowStopAction.
|
|
264
|
+
const selectedRunStoppable = scheduled && selectedRun?.kind === 'workflows' && (!selectedRun.group || selectedRun.group === 'argoproj.io')
|
|
265
|
+
// Only the selected run's own, currently readable object: never the previous
|
|
266
|
+
// selection's, nor a last copy kept after a failed refetch.
|
|
267
|
+
const selectedWorkflow = selectedRunStoppable && !selectedResourceQuery.error &&
|
|
268
|
+
selectedResource?.metadata?.name === selectedRun.name && selectedResource?.metadata?.namespace === selectedRun.namespace
|
|
269
|
+
? selectedResource
|
|
270
|
+
: undefined
|
|
257
271
|
const workflowExecution = useMemo(
|
|
258
272
|
() => selectedResource && selectedRun?.kind === 'workflows' ? buildWorkflowExecutionModel(selectedResource) : null,
|
|
259
273
|
[selectedResource, selectedRun?.kind],
|
|
@@ -418,7 +432,14 @@ function BatchExecutionContent({ leadContent, kind, apiKind, namespace, name, re
|
|
|
418
432
|
{selectedResourceQuery.isFetching && <span>refreshing</span>}
|
|
419
433
|
</div>
|
|
420
434
|
</div>
|
|
421
|
-
<
|
|
435
|
+
<div className="flex shrink-0 items-center gap-2">
|
|
436
|
+
{/* Stays mounted across selections so a request in flight keeps its dialog. */}
|
|
437
|
+
{selectedRunStoppable && (
|
|
438
|
+
<WorkflowRunStopAction workflow={selectedWorkflow} namespace={selectedRun.namespace} name={selectedRun.name} />
|
|
439
|
+
)}
|
|
440
|
+
{selectedWorkflow && <WorkflowShutdownBadge data={selectedWorkflow} />}
|
|
441
|
+
<span className={clsx('badge', selectedRunHeldByKueue ? 'status-neutral' : phaseBadgeClass(selectedRun.phase))}>{selectedRunHeldByKueue ? `Held by Kueue until admitted${selectedRun.deleting ? ' · deleting' : ''}` : runStateLabel(selectedRun)}</span>
|
|
442
|
+
</div>
|
|
422
443
|
</div>
|
|
423
444
|
{memberCollection && <div className="flex flex-wrap items-center gap-3 border-b border-theme-border px-4 py-2 text-xs">
|
|
424
445
|
{!runs.some(run => workloadRunKey(run) === selectedRunKey) && <span className="text-theme-text-secondary">Selected Job is outside the current filter or shown window.</span>}
|
|
@@ -754,7 +775,7 @@ function ExecutionUnitDetails({ unit, namespace, pullSecrets, compact }: { unit:
|
|
|
754
775
|
{!compact && <div className="mb-1 flex items-center justify-between gap-3"><span className="truncate text-xs font-medium text-theme-text-primary">{unit.name}</span><span className="text-[10px] uppercase tracking-wide text-theme-text-tertiary">{unit.type}</span></div>}
|
|
755
776
|
<div className="space-y-1">
|
|
756
777
|
{unit.image && <DefinitionFact label="Image" value={unit.image} mono onClick={canBrowseImage ? () => setBrowseImage(true) : undefined} tooltip={canBrowseImage ? 'Browse image filesystem from registry' : IMAGE_BROWSE_VIA_POD} hint={!canBrowseImage} />}
|
|
757
|
-
{unit.command && <
|
|
778
|
+
{unit.command && <CommandFact key={unit.command} command={unit.command} />}
|
|
758
779
|
{!compact && unit.requests && <DefinitionFact label="Requests" value={unit.requests} />}
|
|
759
780
|
{!compact && unit.limits && <DefinitionFact label="Limits" value={unit.limits} />}
|
|
760
781
|
</div>
|
|
@@ -775,8 +796,70 @@ function ExecutionUnitDetails({ unit, namespace, pullSecrets, compact }: { unit:
|
|
|
775
796
|
|
|
776
797
|
const IMAGE_BROWSE_VIA_POD = "With sign-in on, browse an image's files from one of its Pods."
|
|
777
798
|
|
|
799
|
+
// A command (command plus args, often a whole `sh -c` script) can be far wider and
|
|
800
|
+
// taller than the card. It gets its own full-width line, keeps the script's line
|
|
801
|
+
// breaks, clamps to a few lines with an explicit toggle when it overflows, and
|
|
802
|
+
// copies whole; a hover tooltip can't hold or copy a script.
|
|
803
|
+
export function CommandFact({ command }: { command: string }) {
|
|
804
|
+
const ref = useRef<HTMLElement>(null)
|
|
805
|
+
const [expanded, setExpanded] = useState(false)
|
|
806
|
+
const [overflows, setOverflows] = useState(false)
|
|
807
|
+
const [copied, setCopied] = useState(false)
|
|
808
|
+
|
|
809
|
+
useLayoutEffect(() => {
|
|
810
|
+
const el = ref.current
|
|
811
|
+
if (!el || expanded) return
|
|
812
|
+
const measure = () => setOverflows(el.scrollHeight > el.clientHeight + 1)
|
|
813
|
+
measure()
|
|
814
|
+
if (typeof ResizeObserver === 'undefined') return
|
|
815
|
+
const observer = new ResizeObserver(measure)
|
|
816
|
+
observer.observe(el)
|
|
817
|
+
return () => observer.disconnect()
|
|
818
|
+
}, [expanded])
|
|
819
|
+
|
|
820
|
+
useEffect(() => {
|
|
821
|
+
if (!copied) return
|
|
822
|
+
const timer = setTimeout(() => setCopied(false), 1500)
|
|
823
|
+
return () => clearTimeout(timer)
|
|
824
|
+
}, [copied])
|
|
825
|
+
|
|
826
|
+
return (
|
|
827
|
+
<div className="text-sm">
|
|
828
|
+
<div className="flex items-center justify-between gap-3">
|
|
829
|
+
<span className="text-theme-text-tertiary">Command</span>
|
|
830
|
+
<button
|
|
831
|
+
type="button"
|
|
832
|
+
onClick={() => { void copyText(command).then((ok) => { if (ok) setCopied(true) }) }}
|
|
833
|
+
aria-label={copied ? 'Command copied' : 'Copy command'}
|
|
834
|
+
className="rounded p-0.5 text-theme-text-tertiary hover:bg-theme-hover hover:text-theme-text-primary"
|
|
835
|
+
>
|
|
836
|
+
{copied ? <Check className="h-3.5 w-3.5" /> : <Copy className="h-3.5 w-3.5" />}
|
|
837
|
+
</button>
|
|
838
|
+
</div>
|
|
839
|
+
{/* Padding sits on the wrapper: inside the clamped box it would expose the top of the next line. */}
|
|
840
|
+
<div className="mt-1 rounded bg-theme-base px-2 py-1.5">
|
|
841
|
+
<code
|
|
842
|
+
ref={ref}
|
|
843
|
+
data-testid="definition-command"
|
|
844
|
+
className={clsx(
|
|
845
|
+
'whitespace-pre-wrap font-mono text-xs text-theme-text-primary [overflow-wrap:anywhere]',
|
|
846
|
+
expanded ? 'block' : 'line-clamp-4',
|
|
847
|
+
)}
|
|
848
|
+
>
|
|
849
|
+
{command}
|
|
850
|
+
</code>
|
|
851
|
+
</div>
|
|
852
|
+
{(overflows || expanded) && (
|
|
853
|
+
<button type="button" aria-expanded={expanded} onClick={() => setExpanded((open) => !open)} className="mt-1 text-xs text-accent-text hover:underline">
|
|
854
|
+
{expanded ? 'Show less' : 'Show all'}
|
|
855
|
+
</button>
|
|
856
|
+
)}
|
|
857
|
+
</div>
|
|
858
|
+
)
|
|
859
|
+
}
|
|
860
|
+
|
|
778
861
|
function DefinitionFact({ label, value, mono = false, onClick, tooltip, hint = false }: { label: string; value: string; mono?: boolean; onClick?: () => void; tooltip?: string; hint?: boolean }) {
|
|
779
|
-
const valueClassName = clsx('
|
|
862
|
+
const valueClassName = clsx('min-w-0 text-theme-text-primary [overflow-wrap:anywhere]', mono && 'font-mono text-xs', onClick && 'text-accent-text hover:underline', hint && 'cursor-help underline decoration-dotted decoration-theme-text-tertiary underline-offset-2')
|
|
780
863
|
return (
|
|
781
864
|
<div className="flex items-start justify-between gap-3 text-sm">
|
|
782
865
|
<span className="shrink-0 text-theme-text-tertiary">{label}</span>
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { renderToStaticMarkup } from 'react-dom/server'
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
3
|
+
import { BatchExecutionFullscreen } from './BatchExecutionView'
|
|
4
|
+
|
|
5
|
+
const run: { group: string; kind: string; namespace: string; name: string; phase: string; active: boolean } = { group: 'argoproj.io', kind: 'workflows', namespace: 'ci', name: 'nightly-abc12', phase: 'Running', active: true }
|
|
6
|
+
const child = { apiVersion: 'argoproj.io/v1alpha1', kind: 'Workflow', metadata: { name: 'nightly-abc12', namespace: 'ci', uid: 'uid-1' }, spec: {}, status: { phase: 'Running' } }
|
|
7
|
+
const selected = vi.hoisted(() => ({ data: undefined as unknown, error: undefined as unknown }))
|
|
8
|
+
|
|
9
|
+
vi.mock('../../api/client', () => ({
|
|
10
|
+
useResource: () => ({ data: selected.data, error: selected.error }),
|
|
11
|
+
useWorkloadPods: () => ({}),
|
|
12
|
+
useJobSetResources: () => ({ data: undefined, isLoading: false }),
|
|
13
|
+
useWorkloadRuns: () => ({ data: { collection: 'runs', runs: [run], total: 1, truncated: false } }),
|
|
14
|
+
}))
|
|
15
|
+
vi.mock('./WorkflowRunStopAction', () => ({
|
|
16
|
+
WorkflowRunStopAction: ({ workflow, namespace, name }: { workflow?: { metadata: { uid: string } }; namespace: string; name: string }) =>
|
|
17
|
+
<span data-stop-action={`${namespace}/${name}/${workflow?.metadata.uid ?? 'none'}`} />,
|
|
18
|
+
}))
|
|
19
|
+
|
|
20
|
+
const key = 'workflows/ci/nightly-abc12'
|
|
21
|
+
|
|
22
|
+
describe('Stop in the run view', () => {
|
|
23
|
+
it('offers Stop for the selected child Workflow of a CronWorkflow', () => {
|
|
24
|
+
selected.data = child
|
|
25
|
+
selected.error = undefined
|
|
26
|
+
const html = renderToStaticMarkup(<BatchExecutionFullscreen kind="CronWorkflow" apiKind="cronworkflows" namespace="ci" name="nightly" resource={{ spec: {} }} selectedRunKey={key} />)
|
|
27
|
+
expect(html).toContain('data-stop-action="ci/nightly-abc12/uid-1"')
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('shows a requested shutdown beside the run state', () => {
|
|
31
|
+
selected.data = { ...child, spec: { shutdown: 'Terminate' } }
|
|
32
|
+
selected.error = undefined
|
|
33
|
+
const html = renderToStaticMarkup(<BatchExecutionFullscreen kind="CronWorkflow" apiKind="cronworkflows" namespace="ci" name="nightly" resource={{ spec: {} }} selectedRunKey={key} />)
|
|
34
|
+
expect(html).toContain('Terminating')
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('accepts a run row without a group, as an older Radar sends it', () => {
|
|
38
|
+
selected.data = child
|
|
39
|
+
selected.error = undefined
|
|
40
|
+
run.group = undefined as unknown as string
|
|
41
|
+
try {
|
|
42
|
+
const html = renderToStaticMarkup(<BatchExecutionFullscreen kind="CronWorkflow" apiKind="cronworkflows" namespace="ci" name="nightly" resource={{ spec: {} }} selectedRunKey={key} />)
|
|
43
|
+
expect(html).toContain('data-stop-action="ci/nightly-abc12/uid-1"')
|
|
44
|
+
} finally {
|
|
45
|
+
run.group = 'argoproj.io'
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('withholds the object after a failed refetch, keeping only the last copy', () => {
|
|
50
|
+
selected.data = child
|
|
51
|
+
selected.error = new Error('workflow not found')
|
|
52
|
+
const html = renderToStaticMarkup(<BatchExecutionFullscreen kind="CronWorkflow" apiKind="cronworkflows" namespace="ci" name="nightly" resource={{ spec: {} }} selectedRunKey={key} />)
|
|
53
|
+
expect(html).toContain('data-stop-action="ci/nightly-abc12/none"')
|
|
54
|
+
selected.error = undefined
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('waits for the selected run’s own object, never acting on a previous selection', () => {
|
|
58
|
+
selected.data = { ...child, metadata: { ...child.metadata, name: 'nightly-old' } }
|
|
59
|
+
selected.error = undefined
|
|
60
|
+
const html = renderToStaticMarkup(<BatchExecutionFullscreen kind="CronWorkflow" apiKind="cronworkflows" namespace="ci" name="nightly" resource={{ spec: {} }} selectedRunKey={key} />)
|
|
61
|
+
// Mounted, so a request in flight keeps its dialog, but given no object to act on.
|
|
62
|
+
expect(html).toContain('data-stop-action="ci/nightly-abc12/none"')
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('leaves a standalone Workflow to its action bar', () => {
|
|
66
|
+
const html = renderToStaticMarkup(<BatchExecutionFullscreen kind="Workflow" apiKind="workflows" namespace="ci" name="nightly-abc12" resource={child} selectedRunKey={key} />)
|
|
67
|
+
expect(html).not.toContain('data-stop-action')
|
|
68
|
+
})
|
|
69
|
+
})
|