Skip to content

Commit

Permalink
fix terminate-shell-pods.ts; setup cron job
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Nov 16, 2022
1 parent 9a253e4 commit d0119c7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions crontab
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 6 additions & 5 deletions terminate-shell-pods.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
})();
Expand Down

0 comments on commit d0119c7

Please sign in to comment.