Fix: Pass HTTPS agent as request option directly
All checks were successful
Build and Push Backend / build (push) Successful in 11s
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:
@@ -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<void> {
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user