Link K8S deps properly

This commit is contained in:
Elijah Dunemask 2022-10-08 17:47:46 +00:00
parent 0ac77cdb15
commit f0260fc819
64 changed files with 4282 additions and 3069 deletions

View file

@ -27,6 +27,8 @@ class JobManager {
pushLog(jobId, log) {
const job = this.getJobById(jobId);
if (!job) return;
if (log instanceof Array) job.log.push(...log);
else job.log.push(log);
}

View file

@ -1,11 +1,5 @@
const baseCommand = "node";
const suiteEntry = "tests/assets/suite/runner.js";
const pipelineMapping = [
{
id: 0,
pipeline: [{ name: "primary" }, { name: "secondary", delay: 5000 }],
},
];
const buildCommon = (jobRequest) => {
const { isTriage, ignore, region, testNames } = jobRequest;
@ -25,7 +19,6 @@ const buildManual = (jobReq) => {
throw Error("Currently only 1 test can be selected!");
command.push(`test=${testNames[0]}`);
return { ...jobReq, command };
};
@ -51,7 +44,6 @@ const buildPipeline = (jobReq, socketId) => {
};
export default function jobBuilder(jobRequest, id) {
console.log(jobRequest);
const jobReq = buildCommon(jobRequest, id);
const { pipeline, testNames, tags } = jobReq;
if (pipeline) return buildPipeline(jobReq, id);

View file

@ -5,22 +5,13 @@
"name": "qltr-job-test-suite-1"
},
"spec": {
"ttlSecondsAfterFinished": 2,
"template": {
"spec": {
"containers": [
{
"resources": {
"requests": {
"memory": "64MI",
"cpu": "250m"
},
"limits": {
"memory": "128MI",
"cpu": "500m"
}
},
"name": "qltr-job-test-suite-1",
"image": "node",
"image": "node:latest",
"imagePullPolicy": "Always",
"command": ["node", "--version"]
}

View file

@ -1,16 +1,24 @@
import cp from "node:child_process";
import k8s from "@kubernetes/client-node";
import { INFO, ERR } from "../../util/logging.js";
import { jobBuilder, createFile, deleteFile } from "./k8s-common.js";
const applyFile = async (filePath) => {
const command = `kubectl apply -f ${filePath}`;
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);
job.spec.template.spec.containers[0].image = "node:latest";
job.spec.template.spec.containers[0].command = ["node", "--version"];
// job.spec.template.spec.containers[0].image = "reed";
// job.spec.template.spec.containers[0].command = "python3 -m pytest -v --tb=no -p no:warnings".split(" ");
const kc = new k8s.KubeConfig();
kc.loadFromCluster();
const batchV1Api = kc.makeApiClient(k8s.BatchV1Api);
const batchV1beta1Api = kc.makeApiClient(k8s.BatchV1beta1Api);
const jobName = job.metadata.name;
batchV1Api
.createNamespacedJob("dunestorm-dunemask", job)
.then((res) => INFO("K8S", `Job ${jobName} created!`))
.catch((err) => ERR("K8S", err));
/*const filePath = createFile(job);
applyFile(filePath);
deleteFile(filePath);
deleteFile(filePath);*/
}