@controlplane/cli
Version:
Control Plane Corporation CLI
62 lines • 2.2 kB
JavaScript
"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");
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;
// Validate cron job
this.validate();
// Process labels as tags
if ((_a = this.job.spec.template.metadata) === null || _a === void 0 ? void 0 : _a.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