From ca1591921851b7e418280fda7fa0a37fb3c0840e Mon Sep 17 00:00:00 2001 From: Jari Kolehmainen Date: Wed, 17 Nov 2021 10:23:05 +0200 Subject: [PATCH] Add timeout option to KubeApi.watch (#4365) Signed-off-by: Jari Kolehmainen --- src/common/k8s-api/kube-api.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/common/k8s-api/kube-api.ts b/src/common/k8s-api/kube-api.ts index 840187f047..e4ec4a95e9 100644 --- a/src/common/k8s-api/kube-api.ts +++ b/src/common/k8s-api/kube-api.ts @@ -208,6 +208,7 @@ export type KubeApiWatchOptions = { abortController?: AbortController watchId?: string; retry?: boolean; + timeout?: number; }; export type KubeApiPatchType = "merge" | "json" | "strategic"; @@ -527,7 +528,7 @@ export class KubeApi { watch(opts: KubeApiWatchOptions = { namespace: "", retry: false }): () => void { let errorReceived = false; let timedRetry: NodeJS.Timeout; - const { abortController: { abort, signal } = new AbortController(), namespace, callback = noop, retry } = opts; + const { abortController: { abort, signal } = new AbortController(), namespace, callback = noop, retry, timeout } = opts; const { watchId = `${this.kind.toLowerCase()}-${this.watchId++}` } = opts; signal.addEventListener("abort", () => { @@ -535,8 +536,9 @@ export class KubeApi { clearTimeout(timedRetry); }); + const requestParams = timeout ? { query: { timeoutSeconds: timeout }}: {}; const watchUrl = this.getWatchUrl(namespace); - const responsePromise = this.request.getResponse(watchUrl, null, { signal, timeout: 600_000 }); + const responsePromise = this.request.getResponse(watchUrl, requestParams, { signal, timeout: 600_000 }); logger.info(`[KUBE-API] watch (${watchId}) ${retry === true ? "retried" : "started"} ${watchUrl}`);