forked from opendatahub-io/odh-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnectKube.js
More file actions
51 lines (40 loc) · 1.32 KB
/
connectKube.js
File metadata and controls
51 lines (40 loc) · 1.32 KB
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
'use strict'
function getData(){
const path = require('path')
const fs = require("fs")
const data = require(path.join(__dirname, 'frontend/public/odhDataRes.json'));
const k8s = require('@kubernetes/client-node');
const kc = new k8s.KubeConfig();
//kc.loadFromFile('/home/parsoni/.kube/config');
kc.loadFromDefault();
const watch = new k8s.Watch(kc);
watch.watch('/apis/route.openshift.io/v1/namespaces/opendatahub/routes',
{
allowWatchBookmarks: false,
},
(type, apiObj, watchObj) => {
data.forEach((x) => {
if(x.imgName == apiObj['metadata'].name){
x.link = 'http://' + apiObj['spec'].host;
}
}
)
//console.log(data)
fs.writeFile(path.join(__dirname, 'frontend/build/odhDataRes.json'), JSON.stringify(data), err => {
// Checking for errors
if (err) throw err;
});
},
// done callback is called if the watch terminates normally
(err) => {
// tslint:disable-next-line:no-console
console.log(err);
})
.then((req) => {
// watch returns a request object which you can use to abort the watch.
setTimeout(() => { req.abort(); }, 3 * 1000);
});
}
module.exports = {
getData
}