Skip to content

Commit edc9de5

Browse files
committed
feat: added labelSelector to cache and informer
1 parent f0ee657 commit edc9de5

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/cache.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ObjectSerializer } from './api';
12
import {
23
ADD,
34
CHANGE,
@@ -15,6 +16,7 @@ import { RequestResult, Watch } from './watch';
1516

1617
export interface ObjectCache<T> {
1718
get(name: string, namespace?: string): T | undefined;
19+
1820
list(namespace?: string): ReadonlyArray<T>;
1921
}
2022

@@ -31,6 +33,7 @@ export class ListWatch<T extends KubernetesObject> implements ObjectCache<T>, In
3133
private readonly watch: Watch,
3234
private readonly listFn: ListPromise<T>,
3335
autoStart: boolean = true,
36+
private readonly labelSelector?: string,
3437
) {
3538
this.callbackCache[ADD] = [];
3639
this.callbackCache[UPDATE] = [];
@@ -142,9 +145,18 @@ export class ListWatch<T extends KubernetesObject> implements ObjectCache<T>, In
142145
}
143146
});
144147
this.addOrUpdateItems(list.items);
148+
const queryParams = {
149+
resourceVersion: list.metadata!.resourceVersion,
150+
} as {
151+
resourceVersion: string | undefined,
152+
labelSelector: string | undefined,
153+
};
154+
if (this.labelSelector !== undefined) {
155+
queryParams.labelSelector = ObjectSerializer.serialize(this.labelSelector, 'string');
156+
}
145157
this.request = await this.watch.watch(
146158
this.path,
147-
{ resourceVersion: list.metadata!.resourceVersion },
159+
queryParams,
148160
this.watchHandler.bind(this),
149161
this.doneHandler.bind(this),
150162
);

src/informer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export function makeInformer<T>(
3535
kubeconfig: KubeConfig,
3636
path: string,
3737
listPromiseFn: ListPromise<T>,
38+
labelSelector?: string,
3839
): Informer<T> {
3940
const watch = new Watch(kubeconfig);
40-
return new ListWatch<T>(path, watch, listPromiseFn, false);
41+
return new ListWatch<T>(path, watch, listPromiseFn, false, labelSelector);
4142
}

0 commit comments

Comments
 (0)