Skip to content

Commit

Permalink
add script for terminating long running shell pods
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Oct 10, 2022
1 parent f0bd443 commit 6f4d785
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions terminate-shell-pods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {bot, log} from "./botbase";
import k8s from "@kubernetes/client-node";

(async function () {
const kc = new k8s.KubeConfig();
kc.loadFromDefault();
const k8sApi = kc.makeApiClient(k8s.CoreV1Api);

const listRequest = await k8sApi.listNamespacedPod('tool-sdzerobot');
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');
}
}
})();

function isStale(date: Date): boolean {
return new bot.date().subtract(2, 'hours').isAfter(date);
}

0 comments on commit 6f4d785

Please sign in to comment.