From d0119c7b2d28d9b5103417bb3873968a61c88edb Mon Sep 17 00:00:00 2001 From: Siddharth VP Date: Wed, 16 Nov 2022 09:02:03 +0530 Subject: [PATCH] fix terminate-shell-pods.ts; setup cron job --- crontab | 2 ++ terminate-shell-pods.ts | 11 ++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/crontab b/crontab index f41fb6b..6268134 100644 --- a/crontab +++ b/crontab @@ -89,3 +89,5 @@ 8 16 * * * jsub -quiet -N gans-list -mem 900m ~/SDZeroBot/job most-gans/gans-lister.js 0 3 1 * * jsub -quiet -N gans-users -mem 1g ~/SDZeroBot/job most-gans/update-usernames.js + +0 4 * * * jsub -quiet -N shells -mem 400m ~/SDZeroBot/terminate-shell-pods.js diff --git a/terminate-shell-pods.ts b/terminate-shell-pods.ts index e653410..b6e5405 100644 --- a/terminate-shell-pods.ts +++ b/terminate-shell-pods.ts @@ -1,18 +1,19 @@ import {bot, log} from "./botbase"; -import k8s from "@kubernetes/client-node"; +import {KubeConfig, CoreV1Api} from "@kubernetes/client-node"; (async function () { - const kc = new k8s.KubeConfig(); + const kc = new KubeConfig(); kc.loadFromDefault(); - const k8sApi = kc.makeApiClient(k8s.CoreV1Api); + const k8sApi = kc.makeApiClient(CoreV1Api); + const namespace = 'tool-sdzerobot'; - const listRequest = await k8sApi.listNamespacedPod('tool-sdzerobot'); + const listRequest = await k8sApi.listNamespacedPod(namespace); const pods = listRequest.body.items; for (const pod of pods) { const podName = pod.metadata.name; if (podName.startsWith('shell-') && isStale(pod.metadata.creationTimestamp)) { log(`[W] Terminating dangling pod ${podName}`); - await k8sApi.deleteNamespacedPod(podName, 'tool-sdzerobot'); + await k8sApi.deleteNamespacedPod(podName, namespace); } } })();