2022-08-21 00:10:36 +00:00
|
|
|
import cp from "node:child_process";
|
|
|
|
import { jobBuilder, createFile, deleteFile } from "./k8s-common.js";
|
|
|
|
|
|
|
|
const applyFile = async (filePath) => {
|
2022-08-21 00:11:11 +00:00
|
|
|
const command = `kubectl apply -f ${filePath}`;
|
2022-08-21 00:10:36 +00:00
|
|
|
return new Promise((res, rej) =>
|
|
|
|
cp.exec(command, (err, stdout, stderr) => (err && rej(err)) || res(stdout))
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default async function createJob(jobRequest) {
|
|
|
|
const job = jobBuilder(jobRequest);
|
|
|
|
const filePath = createFile(job);
|
|
|
|
applyFile(filePath);
|
|
|
|
deleteFile(filePath);
|
|
|
|
}
|