Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import * as k8s from '@kubernetes/client-node';
const kc = new k8s.KubeConfig();
kc.loadFromDefault();
const watch = new k8s.Watch(kc);
const req = watch.watch('/api/v1/namespaces',
// optional query parameters can go here.
{},
// callback is called for each received object.
(type, obj) => {
if (type === 'ADDED') {
// tslint:disable-next-line:no-console
console.log('new object:');
} else if (type === 'MODIFIED') {
// tslint:disable-next-line:no-console
console.log('changed object:');
} else if (type === 'DELETED') {
// tslint:disable-next-line:no-console
console.log('deleted object:');
} else {
// tslint:disable-next-line:no-console
connect() {
if (!this.connected) {
this.connected = true;
let kc = new k8s.KubeConfig();
let configFile = process.env['HOME'] + '/.kube/config';
try {
kc.loadFromFile(configFile);
} catch (e) {
console.log('error reading ' + configFile + ': ' + e.message);
throw e;
}
//let resourceVersion = 0
let watch = new k8s.Watch(kc);
// optional query parameters can go here.
// TODO filter on labels once we add them to Activities
const queryParameters = {};
// callback is called for each received object.
const callback = (type: any, obj: any) => {
if (type === 'ADDED') {
this.notify(CallbackKind.ADD, obj);
}
else if (type === 'MODIFIED') {
this.notify(CallbackKind.UPDATE, obj);
}
else if (type === 'DELETED') {
this.notify(CallbackKind.DELETE, obj);
}
async watch(path, queryParams, callbackFn, doneFn, name) {
const watch = new k8s.Watch(this.kubeConfig);
const promise = new Promise((resolve, reject) => {
let req;
const resolveFn = x => {
if (req) {
req.abort();
}
resolve(x);
};
req = watch.watch(
path,
queryParams,
callbackFn(resolveFn, reject),
doneFn(resolveFn, reject),
const k8s = require('@kubernetes/client-node');
const kc = new k8s.KubeConfig();
kc.loadFromDefault();
const k8sApi = kc.makeApiClient(k8s.CoreV1Api);
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++) {
function kubeWatcher() {
logger.info(`Starting kube-watcher, listening for pods labelled "${SELECTOR_LABEL}" on any namespace.`);
return new k8s.Watch(kubeConfig).watch(watchUrl, selector, eventHandler, errorHandler);
}
constructor() {
super();
this._watcher = new k8s.Watch(kc);
this._req = null;
this._watchedJobs = new Map;
}
useFactory: (kc: KubeConfig) => new Watch(kc),
inject: [KubeConfig],