-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.ts
71 lines (63 loc) · 2.21 KB
/
main.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import logger from './logger';
import kubeClient from './client/kube';
import icingaClient from './client/icinga';
import IcingaWrapper from './icinga';
import config from './config';
import Node from './kube/node';
import Service from './kube/service';
import Ingress from './kube/ingress';
import Volume from './kube/volume';
import * as JSONStream from 'json-stream';
const icinga = new IcingaWrapper(logger, icingaClient);
const kubeNode = new Node(logger, icinga, config.kubernetes.nodes);
const kubeIngress = new Ingress(logger, kubeNode, icinga, config.kubernetes.ingresses);
const kubeService = new Service(logger, kubeNode, icinga, config.kubernetes.services);
const kubeVolume = new Volume(logger, kubeNode, icinga, config.kubernetes.volumes);
/**
* Main
*/
async function main() {
if (config.cleanup) {
await icinga.deleteServicesByFilter('service.vars._kubernetes == true').catch((err) => {
logger.error('failed to cleanup icinga services', {error: err});
});
await icinga.deleteHostsByFilter('host.vars._kubernetes == true').catch((err) => {
logger.error('failed to cleanup icinga hosts', {error: err});
});
}
if (config.kubernetes.nodes.discover) {
kubeNode.kubeListener(function() {
let json = new JSONStream();
let stream = kubeClient.apis.v1.watch.nodes.getStream();
stream.pipe(json);
return json;
});
}
if (config.kubernetes.ingresses.discover) {
kubeIngress.kubeListener(() => {
let json = new JSONStream();
let stream = kubeClient.apis.extensions.v1beta1.watch.ingresses.getStream();
stream.pipe(json);
return json;
});
}
if (config.kubernetes.volumes.discover) {
kubeVolume.kubeListener(() => {
let json = new JSONStream();
let stream = kubeClient.apis.v1.watch.persistentvolumes.getStream();
stream.pipe(json);
return json;
});
}
if (config.kubernetes.services.ClusterIP.discover
|| config.kubernetes.services.NodePort.discover
|| config.kubernetes.services.LoadBalancer.discover) {
kubeService.kubeListener(() => {
let json = new JSONStream();
let stream = kubeClient.apis.v1.watch.services.getStream();
stream.pipe(json);
return json;
});
}
}
main();