File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments