UNPKG

@vfarcic/dot-ai

Version:

Universal Kubernetes application deployment agent with CLI and MCP interfaces

102 lines (101 loc) 3.97 kB
"use strict"; /** * Deploy Operation - Handles Kubernetes manifest deployment with readiness checking */ Object.defineProperty(exports, "__esModule", { value: true }); exports.DeployOperation = void 0; const promises_1 = require("fs/promises"); const path_1 = require("path"); const error_handling_1 = require("./error-handling"); const kubernetes_utils_1 = require("./kubernetes-utils"); class DeployOperation { kubectlConfig; constructor(kubeconfig) { this.kubectlConfig = { kubeconfig: kubeconfig || process.env.KUBECONFIG }; } /** * Deploy Kubernetes manifests from generated solution */ async deploy(options) { return error_handling_1.ErrorHandler.withErrorHandling(async () => { const manifestPath = this.getManifestPath(options); // Verify manifest file exists await this.verifyManifestExists(manifestPath); // Update kubeconfig if provided in options const kubectlConfig = { ...this.kubectlConfig, kubeconfig: options.kubeconfig || this.kubectlConfig.kubeconfig }; // Apply manifests with kubectl const kubectlOutput = await this.applyManifests(manifestPath, options.timeout || 30, kubectlConfig); return { success: true, solutionId: options.solutionId, manifestPath, readinessTimeout: false, message: 'Deployment completed successfully', kubectlOutput }; }, { operation: 'deploy', component: 'deploy-operation' }); } /** * Get the manifest file path for the solution */ getManifestPath(options) { const sessionDir = options.sessionDir || process.env.DOT_AI_SESSION_DIR; if (!sessionDir) { throw new Error('Session directory not configured. Set DOT_AI_SESSION_DIR environment variable or provide sessionDir parameter.'); } return (0, path_1.join)(sessionDir, `${options.solutionId}.yaml`); } /** * Verify that the manifest file exists */ async verifyManifestExists(manifestPath) { try { await (0, promises_1.access)(manifestPath); } catch (error) { throw new Error(`Manifest file not found: ${manifestPath}`); } } /** * Apply manifests using kubectl with readiness checking */ async applyManifests(manifestPath, timeout, kubectlConfig) { // First, apply the manifests const applyResult = await (0, kubernetes_utils_1.executeKubectl)(['apply', '-f', `"${manifestPath}"`], kubectlConfig); // Try to wait for deployments to be ready (ignore failures for other resource types) let waitOutput = ''; try { const waitResult = await (0, kubernetes_utils_1.executeKubectl)([ 'wait', '--for=condition=available', 'deployments', '--all', `--timeout=${timeout}s`, '--all-namespaces' ], { ...kubectlConfig, timeout: (timeout + 10) * 1000 // Add 10 seconds buffer for kubectl command itself }); waitOutput = `\n\nWait output:\n${waitResult}`; } catch (waitError) { // If no deployments found or wait fails, that's OK for ConfigMaps, Services, etc. if (waitError.message && waitError.message.includes('no matching resources found')) { waitOutput = '\n\nWait output: No deployments found to wait for (likely ConfigMaps, Services, etc.)'; } else { waitOutput = `\n\nWait output: Warning - ${waitError.message}`; } } return `Apply output:\n${applyResult}${waitOutput}`; } } exports.DeployOperation = DeployOperation;