forked from kubernetes-client/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache-example.js
More file actions
33 lines (28 loc) · 788 Bytes
/
cache-example.js
File metadata and controls
33 lines (28 loc) · 788 Bytes
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
const k8s = require('@kubernetes/client-node');
const kc = new k8s.KubeConfig();
kc.loadFromDefault();
const k8sApi = kc.makeApiClient(k8s.Core_v1Api);
const path = '/api/v1/namespaces/default/pods';
const watch = new k8s.Watch(kc);
const listFn = (fn) => {
k8sApi.listNamespacedPod('default')
.then((res) => {
fn(res.body.items);
})
.catch((err) => {
console.log(err);
});
}
const cache = new k8s.ListWatch(path, watch, listFn);
const looper = () => {
const list = cache.list('default');
if (list) {
let names = [];
for (let i = 0; i < list.length; i++) {
names.push(list[i].metadata.name);
}
console.log(names.join(','));
}
setTimeout(looper, 2000);
}
looper();