From 68642588101c28465e06c0af5b5d2da2f8b30dd3 Mon Sep 17 00:00:00 2001 From: Hector Ros Date: Tue, 20 Jan 2026 19:56:04 +0100 Subject: [PATCH] Fix getPodIP: handle different K8s API response structures - Add debug logging to getPodIP - Handle both response.body and direct response - Apply same fix to getPodStatus for consistency - Fixes 500 error when accessing agent terminal --- src/lib/k8s.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/lib/k8s.ts b/src/lib/k8s.ts index 0b0fb3c..e25648d 100644 --- a/src/lib/k8s.ts +++ b/src/lib/k8s.ts @@ -253,7 +253,10 @@ export async function getPodStatus(podName: string): Promise { name: podName, namespace: 'agents' }) - return response.body.status?.phase || null + + // Handle different response structures + const pod = response.body || response + return pod?.status?.phase || null } catch (error: any) { if (error.statusCode === 404 || error.response?.statusCode === 404) { return null @@ -269,12 +272,23 @@ export async function getPodIP(podName: string): Promise { const client = getK8sClient() try { + console.log(`🔍 Getting IP for pod: ${podName}`) const response = await client.readNamespacedPod({ name: podName, namespace: 'agents' }) - return response.body.status?.podIP || null + + console.log(`🔍 Response type: ${typeof response}`) + console.log(`🔍 Has body: ${'body' in response}`) + + // Handle different response structures + const pod = response.body || response + const podIP = pod?.status?.podIP + + console.log(`🔍 Pod IP: ${podIP}`) + return podIP || null } catch (error: any) { + console.error(`❌ Error getting pod IP for ${podName}:`, error.message) if (error.statusCode === 404 || error.response?.statusCode === 404) { return null }