-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add script for terminating long running shell pods
- Loading branch information
1 parent
f0bd443
commit 6f4d785
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |