forked from josephjacks/aci-connector-k8s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeleter.ts
41 lines (36 loc) · 1.4 KB
/
deleter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import api = require('@kubernetes/typescript-node');
import aci = require('./aci');
import azureResource = require('azure-arm-resource');
export async function ContainerDeleter(client: api.Core_v1Api, rsrcClient: azureResource.ResourceManagementClient, keepRunning: () => boolean) {
console.log('container deleter');
try {
if (!keepRunning()) {
return;
}
let groups = await aci.ListContainerGroups(rsrcClient);
let groupMembers = {};
for (let group of groups) {
groupMembers[group['name']] = group;
}
let pods = await client.listNamespacedPod("default");
for (let pod of pods.body.items) {
if (pod.spec.nodeName != "aci-connector") {
continue;
}
if (pod.metadata.deletionTimestamp != null) {
let group = groupMembers[pod.metadata.name];
if (group == null) {
client.deleteNamespacedPod(pod.metadata.name, 'default', { gracePeriodSeconds: 0 } as api.V1DeleteOptions, "false", 0, true);
} else {
console.log('deleting aci-connector');
aci.DeleteContainerGroup(group.id, rsrcClient);
}
}
}
} catch (Exception) {
console.log(Exception);
}
setTimeout(() => {
ContainerDeleter(client, rsrcClient, keepRunning);
}, 1000);
}