diff --git a/src/lib/k8s.ts b/src/lib/k8s.ts index 63e2355..b2fc549 100644 --- a/src/lib/k8s.ts +++ b/src/lib/k8s.ts @@ -68,6 +68,23 @@ export function getK8sClient(): k8s.CoreV1Api { return k8sClient } +/** + * Get Kubernetes client with custom request options + * This ensures the HTTPS agent is used for each request + */ +export function getK8sClientWithOptions(): { client: k8s.CoreV1Api, options: any } { + const client = getK8sClient() + + // Create request options with custom HTTPS agent + const options = { + httpsAgent: new https.Agent({ + rejectUnauthorized: false + }) + } + + return { client, options } +} + /** * Create pod spec for agent */ @@ -174,27 +191,24 @@ export function createAgentPodSpec(podName: string, userId: string): k8s.V1Pod { * Create agent pod in Kubernetes */ export async function createAgentPod(podName: string, userId: string): Promise { - const client = getK8sClient() + const { client, options } = getK8sClientWithOptions() const podSpec = createAgentPodSpec(podName, userId) console.log(`🔧 Creating pod ${podName} for user ${userId}`) - console.log(`🔧 K8s config:`, { - cluster: k8sConfig?.getCurrentCluster(), - user: k8sConfig?.getCurrentUser(), - }) + console.log(`🔧 Using custom HTTPS agent with rejectUnauthorized: false`) try { const result = await client.createNamespacedPod({ namespace: 'agents', body: podSpec - }) + }, undefined, undefined, undefined, undefined, options) + console.log(`✅ Pod ${podName} created successfully`) console.log(`✅ Pod UID: ${result.body.metadata?.uid}`) } catch (error: any) { console.error(`❌ Failed to create pod ${podName}`) console.error(`❌ Error message:`, error.message) console.error(`❌ Error code:`, error.code) - console.error(`❌ Error stack:`, error.stack) if (error.response) { console.error(`❌ Response status:`, error.response.statusCode) console.error(`❌ Response body:`, error.response.body)