@controlplane/cli
Version:
Control Plane Corporation CLI
67 lines • 2.78 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.K8sHorizontalPodAutoscalerHandler = void 0;
const helper_1 = require("../../util/helper");
class K8sHorizontalPodAutoscalerHandler {
constructor(filePath, hpa) {
this.filePath = filePath;
this.hpa = hpa;
}
/*** Public Methods ***/
handle() {
// Validate Horizontal Pod Autoscaler
this.validate();
}
/*** Private Methods ***/
// Validators //
validate() {
// Validate Spec
if (!this.hpa.spec) {
this.ensurePropertyPresence('spec');
}
// Validate Behavior
if (this.hpa.spec.behavior &&
(this.hpa.spec.behavior.scaleDown.stabilizationWindowSeconds < 30 ||
this.hpa.spec.behavior.scaleDown.stabilizationWindowSeconds > 3600)) {
this.raiseCustomK8sError(`'behavior.scaleDown.stabilizationWindowSeconds' must be greater than or equal to 30 (30 seconds) and less than or equal to 3600 (one hour)`);
}
// Validate Metrics
if (this.hpa.spec.metrics && this.hpa.spec.metrics.length > 0) {
for (const [index, metric] of this.hpa.spec.metrics.entries()) {
if (!metric.containerResource) {
continue;
}
if (!metric.containerResource.container) {
this.ensurePropertyPresence(`metrics[${index}].containerResource.container`);
}
if (!metric.containerResource.name) {
this.ensurePropertyPresence(`metrics[${index}].containerResource.name`);
}
if (!metric.containerResource.target) {
this.ensurePropertyPresence(`metrics[${index}].containerResource.target`);
}
if (!metric.containerResource.target.type) {
this.ensurePropertyPresence(`metrics[${index}].containerResource.target.type`);
}
}
}
// Validate Scale Target Ref
if (this.hpa.spec.scaleTargetRef) {
if (!this.hpa.spec.scaleTargetRef.name) {
this.ensurePropertyPresence('scaleTargetRef.name');
}
if (!this.hpa.spec.scaleTargetRef.kind) {
this.ensurePropertyPresence('scaleTargetRef.kind');
}
}
}
// Validation Helpers //
ensurePropertyPresence(property) {
(0, helper_1.ensurePropertyPresence)(property, this.filePath, this.hpa);
}
raiseCustomK8sError(message) {
(0, helper_1.raiseCustomK8sError)(message, this.filePath, this.hpa);
}
}
exports.K8sHorizontalPodAutoscalerHandler = K8sHorizontalPodAutoscalerHandler;
//# sourceMappingURL=hpa.js.map