UNPKG

@controlplane/cli

Version:

Control Plane Corporation CLI

67 lines 2.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.K8sJobHandler = void 0; const helper_1 = require("../../util/helper"); const pod_template_1 = require("../processors/pod-template"); const constants_1 = require("../../config/constants"); class K8sJobHandler { constructor(filePath, job, mapper) { this.filePath = filePath; this.job = job; this.mapper = mapper; this.workload = { kind: 'workload', name: job.metadata.name, spec: { type: 'cron', containers: [], defaultOptions: { capacityAI: false, }, job: { schedule: '* * * * *', concurrencyPolicy: 'Forbid', historyLimit: 5, restartPolicy: 'Never', }, }, }; } /*** Public Methods ***/ handle() { var _a, _b, _c; // Validate cron job this.validate(); // Jobs always convert to workloads of type 'cron' if ((0, helper_1.getCplnAnnotation)(constants_1.K8S_CPLN_ANNOTATION_WORKLOAD_TYPE, this.job, (_b = (_a = this.job.spec) === null || _a === void 0 ? void 0 : _a.template) === null || _b === void 0 ? void 0 : _b.metadata)) { this.mapper.warnings.push(`Annotation '${constants_1.K8S_CPLN_ANNOTATION_WORKLOAD_TYPE}' on Job '${this.job.metadata.name}' was ignored because Jobs always convert to workloads of type 'cron'.`); } // Process labels as tags if ((_c = this.job.spec.template.metadata) === null || _c === void 0 ? void 0 : _c.labels) { this.workload.tags = this.job.spec.template.metadata.labels; } if (!this.workload.tags || Object.keys(this.workload.tags).length == 0) { this.workload.tags = this.job.metadata.labels; } // Handle suspend if (this.job.spec.suspend) { this.workload.spec.defaultOptions.suspend = true; } // Process template property const templateProcessor = new pod_template_1.K8sPodTemplateProcessor(this.filePath, 'spec.template', this.job, this.workload, this.job.spec.template, this.mapper); templateProcessor.process(); return this.workload; } /*** Private Methods ***/ // Validators // validate() { } // Validation Helpers // ensurePropertyPresence(property) { (0, helper_1.ensurePropertyPresence)(property, this.filePath, this.job); } raiseCustomK8sError(message) { (0, helper_1.raiseCustomK8sError)(message, this.filePath, this.job); } } exports.K8sJobHandler = K8sJobHandler; //# sourceMappingURL=job.js.map