UNPKG

@topgroup/diginext

Version:

A BUILD SERVER & CLI to deploy apps to any Kubernetes clusters.

34 lines (33 loc) 1.6 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DeploymentScaler = void 0; const k8s_1 = __importDefault(require("../../../modules/k8s")); const plugins_1 = require("../../../plugins"); const deploy_checker_1 = require("./deploy-checker"); class DeploymentScaler { constructor(context, namespace, onUpdate) { this.context = context; this.namespace = namespace; this.onUpdate = onUpdate; } async scaleDeployment(deploymentName, targetReplicas, timeout = 300 // 5 minutes ) { var _a, _b; try { (_a = this.onUpdate) === null || _a === void 0 ? void 0 : _a.call(this, `Scaling "${deploymentName}" to ${targetReplicas} replicas`); await k8s_1.default.scaleDeploy(deploymentName, targetReplicas, this.namespace, { context: this.context }); const checker = new deploy_checker_1.DeploymentReadinessChecker(this.context, this.namespace, deploymentName, "", // No specific version for scaling existing deployment this.onUpdate); return await (0, plugins_1.waitUntil)(() => checker.isDeploymentReady(targetReplicas), 5, // 5 second intervals timeout); } catch (error) { (_b = this.onUpdate) === null || _b === void 0 ? void 0 : _b.call(this, `Failed to scale deployment: ${error.message}`); return false; } } } exports.DeploymentScaler = DeploymentScaler;