Fix: Pass HTTPS agent as request option directly
All checks were successful
Build and Push Backend / build (push) Successful in 11s

applyToHTTPSOptions doesn't work reliably. Instead, pass the
httpsAgent as the last parameter to createNamespacedPod.

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Hector Ros
2026-01-20 18:17:30 +01:00
parent 9eb9def85c
commit 65b18d13b5

View File

@@ -68,6 +68,23 @@ export function getK8sClient(): k8s.CoreV1Api {
return k8sClient 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 * Create pod spec for agent
*/ */
@@ -174,27 +191,24 @@ export function createAgentPodSpec(podName: string, userId: string): k8s.V1Pod {
* Create agent pod in Kubernetes * Create agent pod in Kubernetes
*/ */
export async function createAgentPod(podName: string, userId: string): Promise<void> { export async function createAgentPod(podName: string, userId: string): Promise<void> {
const client = getK8sClient() const { client, options } = getK8sClientWithOptions()
const podSpec = createAgentPodSpec(podName, userId) const podSpec = createAgentPodSpec(podName, userId)
console.log(`🔧 Creating pod ${podName} for user ${userId}`) console.log(`🔧 Creating pod ${podName} for user ${userId}`)
console.log(`🔧 K8s config:`, { console.log(`🔧 Using custom HTTPS agent with rejectUnauthorized: false`)
cluster: k8sConfig?.getCurrentCluster(),
user: k8sConfig?.getCurrentUser(),
})
try { try {
const result = await client.createNamespacedPod({ const result = await client.createNamespacedPod({
namespace: 'agents', namespace: 'agents',
body: podSpec body: podSpec
}) }, undefined, undefined, undefined, undefined, options)
console.log(`✅ Pod ${podName} created successfully`) console.log(`✅ Pod ${podName} created successfully`)
console.log(`✅ Pod UID: ${result.body.metadata?.uid}`) console.log(`✅ Pod UID: ${result.body.metadata?.uid}`)
} catch (error: any) { } catch (error: any) {
console.error(`❌ Failed to create pod ${podName}`) console.error(`❌ Failed to create pod ${podName}`)
console.error(`❌ Error message:`, error.message) console.error(`❌ Error message:`, error.message)
console.error(`❌ Error code:`, error.code) console.error(`❌ Error code:`, error.code)
console.error(`❌ Error stack:`, error.stack)
if (error.response) { if (error.response) {
console.error(`❌ Response status:`, error.response.statusCode) console.error(`❌ Response status:`, error.response.statusCode)
console.error(`❌ Response body:`, error.response.body) console.error(`❌ Response body:`, error.response.body)