Add extensive debug logging for K8s client
All checks were successful
Build and Push Backend / build (push) Successful in 4s

- Log cluster config details
- Log HTTPS agent setup
- Log detailed error information on pod creation failure
- Track applyToHTTPSOptions execution

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

View File

@@ -21,24 +21,33 @@ export function initK8sClient() {
if (inCluster) {
k8sConfig.loadFromCluster()
console.log('📦 Loaded K8s config from cluster')
// Skip TLS verification when in cluster
// This is needed because the cluster uses self-signed certificates
const cluster = k8sConfig.getCurrentCluster()
console.log('📦 Current cluster:', cluster)
if (cluster) {
cluster.skipTLSVerify = true
console.log('🔓 K8s client configured to skip TLS verification (in-cluster mode)')
console.log('🔓 Set skipTLSVerify = true')
}
// Create custom HTTPS agent that ignores certificate errors
const httpsAgent = new https.Agent({
rejectUnauthorized: false
})
console.log('🔓 Created HTTPS agent with rejectUnauthorized: false')
// Apply custom agent to the config
k8sConfig.applyToHTTPSOptions({
httpsAgent: httpsAgent
} as any)
try {
k8sConfig.applyToHTTPSOptions({
httpsAgent: httpsAgent
} as any)
console.log('✅ Applied custom HTTPS agent to K8s config')
} catch (applyError: any) {
console.error('❌ Failed to apply HTTPS options:', applyError.message)
}
} else {
// Load from kubeconfig file
const configPath = process.env.K8S_CONFIG_PATH || process.env.KUBECONFIG || '~/.kube/config'
@@ -168,14 +177,28 @@ export async function createAgentPod(podName: string, userId: string): Promise<v
const client = getK8sClient()
const podSpec = createAgentPodSpec(podName, userId)
console.log(`🔧 Creating pod ${podName} for user ${userId}`)
console.log(`🔧 K8s config:`, {
cluster: k8sConfig?.getCurrentCluster(),
user: k8sConfig?.getCurrentUser(),
})
try {
await client.createNamespacedPod({
const result = await client.createNamespacedPod({
namespace: 'agents',
body: podSpec
})
console.log(`✅ Pod ${podName} created successfully`)
console.log(`✅ Pod UID: ${result.body.metadata?.uid}`)
} catch (error: any) {
console.error(`❌ Failed to create pod ${podName}:`, error.message)
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)
}
throw error
}
}