Skip to content

Commit

Permalink
example/ts/informer: avoid staleness by adding a timeout -- see kuber…
Browse files Browse the repository at this point in the history
  • Loading branch information
haraldschilly committed Jun 15, 2022
1 parent b4ccd6e commit 034805e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
18 changes: 12 additions & 6 deletions examples/typescript/informer/informer-with-label-selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ const k8sApi = kc.makeApiClient(k8s.CoreV1Api);

const APP_LABEL_SELECTOR = 'app=foo';

// timeout based on discussions in https://github.com/kubernetes-client/javascript/issues/596
const listFn = () => k8sApi.listNamespacedPod(
'default',
undefined,
undefined,
undefined,
undefined,
APP_LABEL_SELECTOR,
'default', // namespace: string
undefined, // pretty?: string
undefined, // allowWatchBookmarks?: boolean
undefined, // _continue?: string
undefined, // fieldSelector?: string
APP_LABEL_SELECTOR, // labelSelector?: string
undefined, // limit?: number
undefined, // resourceVersion?: string
undefined, // resourceVersionMatch?: string
300 // timeoutSeconds?: number
// keep watch field false (default)
);

const createPod = async (name, app) => {
Expand Down
15 changes: 14 additions & 1 deletion examples/typescript/informer/informer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,20 @@ kc.loadFromDefault();

const k8sApi = kc.makeApiClient(k8s.CoreV1Api);

const listFn = () => k8sApi.listNamespacedPod('default');
// timeout based on discussions in https://github.com/kubernetes-client/javascript/issues/596
const listFn = () => k8sApi.listNamespacedPod(
'default', // namespace: string
undefined, // pretty?: string
undefined, // allowWatchBookmarks?: boolean
undefined, // _continue?: string
undefined, // fieldSelector?: string
undefined, // labelSelector?: string
undefined, // limit?: number
undefined, // resourceVersion?: string
undefined, // resourceVersionMatch?: string
300 // timeoutSeconds?: number
// keep watch field false (default)
);

const informer = k8s.makeInformer(kc, '/api/v1/namespaces/default/pods', listFn);

Expand Down

0 comments on commit 034805e

Please sign in to comment.