Skip to content

Commit 6f4d785

Browse files
committed
add script for terminating long running shell pods
1 parent f0bd443 commit 6f4d785

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

terminate-shell-pods.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {bot, log} from "./botbase";
2+
import k8s from "@kubernetes/client-node";
3+
4+
(async function () {
5+
const kc = new k8s.KubeConfig();
6+
kc.loadFromDefault();
7+
const k8sApi = kc.makeApiClient(k8s.CoreV1Api);
8+
9+
const listRequest = await k8sApi.listNamespacedPod('tool-sdzerobot');
10+
const pods = listRequest.body.items;
11+
for (const pod of pods) {
12+
const podName = pod.metadata.name;
13+
if (podName.startsWith('shell-') && isStale(pod.metadata.creationTimestamp)) {
14+
log(`[W] Terminating dangling pod ${podName}`);
15+
await k8sApi.deleteNamespacedPod(podName, 'tool-sdzerobot');
16+
}
17+
}
18+
})();
19+
20+
function isStale(date: Date): boolean {
21+
return new bot.date().subtract(2, 'hours').isAfter(date);
22+
}

0 commit comments

Comments
 (0)