fix: use kubectl json output for terminal introspection
- replace fragile jsonpath quoting with full pod JSON parsing - show container and image summary in terminal failure message
This commit is contained in:
@@ -10,14 +10,21 @@ export async function GET(request: Request) {
|
|||||||
return NextResponse.json({ error: 'sandboxId is required' }, { status: 400 })
|
return NextResponse.json({ error: 'sandboxId is required' }, { status: 400 })
|
||||||
}
|
}
|
||||||
|
|
||||||
const jsonpath = `{.spec.containers[*].name}{"\n"}{.spec.containers[*].image}{"\n"}{.status.containerStatuses[*].name}{"\n"}`
|
|
||||||
const result = await dockerExecInOpenShell(
|
const result = await dockerExecInOpenShell(
|
||||||
`kubectl -n ${OPENSHELL_NAMESPACE} get pod ${sandboxId} -o jsonpath='${jsonpath}'`
|
`kubectl -n ${OPENSHELL_NAMESPACE} get pod ${sandboxId} -o json`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const pod = JSON.parse(result.stdout)
|
||||||
|
const containerNames = Array.isArray(pod?.spec?.containers) ? pod.spec.containers.map((c: any) => c.name) : []
|
||||||
|
const containerImages = Array.isArray(pod?.spec?.containers) ? pod.spec.containers.map((c: any) => c.image) : []
|
||||||
|
const statusNames = Array.isArray(pod?.status?.containerStatuses) ? pod.status.containerStatuses.map((c: any) => c.name) : []
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
ok: true,
|
ok: true,
|
||||||
sandboxId,
|
sandboxId,
|
||||||
|
containers: containerNames,
|
||||||
|
images: containerImages,
|
||||||
|
runningStatuses: statusNames,
|
||||||
raw: result.stdout.trim(),
|
raw: result.stdout.trim(),
|
||||||
stderr: result.stderr.trim(),
|
stderr: result.stderr.trim(),
|
||||||
note: 'Pod/container introspection succeeded. Use this to select the right exec target for terminal attach.'
|
note: 'Pod/container introspection succeeded. Use this to select the right exec target for terminal attach.'
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ export default function SandboxList({
|
|||||||
const inspectRes = await fetch(`/api/openshell/terminal/introspect?sandboxId=${encodeURIComponent(selectedSandbox)}`)
|
const inspectRes = await fetch(`/api/openshell/terminal/introspect?sandboxId=${encodeURIComponent(selectedSandbox)}`)
|
||||||
const inspectData = await inspectRes.json()
|
const inspectData = await inspectRes.json()
|
||||||
setTerminalMessage(inspectData.ok
|
setTerminalMessage(inspectData.ok
|
||||||
? `Terminal probe failed. Pod introspection for ${selectedSandbox}: ${inspectData.raw}`
|
? `Terminal probe failed. Pod introspection for ${selectedSandbox}: containers=${(inspectData.containers || []).join(', ')} images=${(inspectData.images || []).join(', ')}`
|
||||||
: (data.error || 'Failed to attach to OpenShell terminal.'))
|
: (data.error || 'Failed to attach to OpenShell terminal.'))
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user