Skip to content

Commit 58345aa

Browse files
committed
fix: readd error callback on informer error and connect events
Closes #2448
1 parent 2f2b63a commit 58345aa

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

src/cache.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,16 @@ export class ListWatch<T extends KubernetesObject> implements ObjectCache<T>, In
7171
this._stop();
7272
}
7373

74-
public on(verb: 'add' | 'update' | 'delete' | 'change', cb: ObjectCallback<T>): void;
75-
public on(verb: 'error' | 'connect', cb: ErrorCallback): void;
76-
public on(verb: string, cb: any): void {
74+
public on(verb: ADD | UPDATE | DELETE | CHANGE, cb: ObjectCallback<T>): void;
75+
public on(verb: ERROR | CONNECT, cb: ErrorCallback): void;
76+
public on(
77+
verb: ADD | UPDATE | DELETE | CHANGE | ERROR | CONNECT,
78+
cb: ObjectCallback<T> | ErrorCallback,
79+
): void {
7780
if (verb === CHANGE) {
78-
this.on('add', cb);
79-
this.on('update', cb);
80-
this.on('delete', cb);
81+
this.on(ADD, cb);
82+
this.on(UPDATE, cb);
83+
this.on(DELETE, cb);
8184
return;
8285
}
8386
if (this.callbackCache[verb] === undefined) {

src/informer.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,27 @@ export type ListCallback<T extends KubernetesObject> = (list: T[], ResourceVersi
99
export type ListPromise<T extends KubernetesObject> = () => Promise<KubernetesListObject<T>>;
1010

1111
// These are issued per object
12-
export const ADD: string = 'add';
13-
export const UPDATE: string = 'update';
14-
export const CHANGE: string = 'change';
15-
export const DELETE: string = 'delete';
12+
export const ADD = 'add';
13+
export type ADD = typeof ADD;
14+
export const UPDATE = 'update';
15+
export type UPDATE = typeof UPDATE;
16+
export const CHANGE = 'change';
17+
export type CHANGE = typeof CHANGE;
18+
export const DELETE = 'delete';
19+
export type DELETE = typeof DELETE;
1620

1721
// This is issued when a watch connects or reconnects
18-
export const CONNECT: string = 'connect';
22+
export const CONNECT = 'connect';
23+
export type CONNECT = typeof CONNECT;
1924
// This is issued when there is an error
20-
export const ERROR: string = 'error';
25+
export const ERROR = 'error';
26+
export type ERROR = typeof ERROR;
2127

2228
export interface Informer<T extends KubernetesObject> {
23-
on(verb: string, fn: ObjectCallback<T>): void;
24-
off(verb: string, fn: ObjectCallback<T>): void;
29+
on(verb: ADD | UPDATE | DELETE | CHANGE, cb: ObjectCallback<T>): void;
30+
on(verb: ERROR | CONNECT, cb: ErrorCallback): void;
31+
off(verb: ADD | UPDATE | DELETE | CHANGE, cb: ObjectCallback<T>): void;
32+
off(verb: ERROR | CONNECT, cb: ErrorCallback): void;
2533
start(): Promise<void>;
2634
stop(): Promise<void>;
2735
}

0 commit comments

Comments
 (0)