From 034805e1eab5020c4f139a30474754adade984fc Mon Sep 17 00:00:00 2001 From: Harald Schilly Date: Wed, 15 Jun 2022 09:42:53 +0200 Subject: [PATCH] example/ts/informer: avoid staleness by adding a timeout -- see #596 --- .../informer/informer-with-label-selector.ts | 18 ++++++++++++------ examples/typescript/informer/informer.ts | 15 ++++++++++++++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/examples/typescript/informer/informer-with-label-selector.ts b/examples/typescript/informer/informer-with-label-selector.ts index cbcf7f4366..160da4ee59 100644 --- a/examples/typescript/informer/informer-with-label-selector.ts +++ b/examples/typescript/informer/informer-with-label-selector.ts @@ -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) => { diff --git a/examples/typescript/informer/informer.ts b/examples/typescript/informer/informer.ts index b7a1a48f31..50a63a3b53 100644 --- a/examples/typescript/informer/informer.ts +++ b/examples/typescript/informer/informer.ts @@ -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);