[TS] Renamed file extensions to typescript
This commit is contained in:
parent
4d5b347767
commit
4a6f20fa7b
31 changed files with 12 additions and 0 deletions
|
@ -1,32 +0,0 @@
|
|||
import { Router } from "express";
|
||||
import k8s from "@kubernetes/client-node";
|
||||
import { WARN } from "../util/logging.js";
|
||||
import kc from "../k8s/k8s-config.js";
|
||||
const router = Router();
|
||||
|
||||
import cairoAuthMiddleware from "./middlewares/auth-middleware.js";
|
||||
router.use(cairoAuthMiddleware);
|
||||
|
||||
const k8sApi = kc.makeApiClient(k8s.CoreV1Api);
|
||||
// Get Routes
|
||||
router.get("/available", (req, res) => {
|
||||
return res.json({ cpu: 8000, memory: 16000 });
|
||||
// TODO Workaround to detect available
|
||||
k8sApi.listNode().then((nodeRes) => {
|
||||
const nodeAllocatable = nodeRes.body.items.map((i) => i.status.allocatable);
|
||||
const nodeResources = nodeAllocatable.map(({ cpu, memory }) => ({
|
||||
cpu,
|
||||
memory,
|
||||
}));
|
||||
const { cpu: clusterCpu, memory: clusterMemory } = nodeResources[0];
|
||||
const isIdentical = ({ cpu, memory }) =>
|
||||
clusterMemory === memory && clusterCpu === cpu;
|
||||
if (!nodeResources.every(isIdentical))
|
||||
WARN("ROUTES", "Warning, node resources were non-consistent");
|
||||
const availableCpu = parseInt(clusterCpu) * 1000;
|
||||
const availableMemory = parseInt(clusterMemory) / 1024;
|
||||
res.json({ cpu: availableCpu, memory: availableMemory });
|
||||
});
|
||||
});
|
||||
|
||||
export default router;
|
Loading…
Add table
Add a link
Reference in a new issue