diff --git a/src/common/k8s-api/kube-api.ts b/src/common/k8s-api/kube-api.ts index 54b0e5726f..5426f63343 100644 --- a/src/common/k8s-api/kube-api.ts +++ b/src/common/k8s-api/kube-api.ts @@ -195,6 +195,9 @@ export type KubeApiWatchOptions = { abortController?: AbortController watchId?: string; retry?: boolean; + + // Request options that are applied for the initial watch request and also subsequent retry requests + getRequestOptions?: () => RequestInit; }; export class KubeApi { @@ -486,7 +489,12 @@ 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, + getRequestOptions } = opts; const { watchId = `${this.kind.toLowerCase()}-${this.watchId++}` } = opts; signal.addEventListener("abort", () => { @@ -495,7 +503,11 @@ export class KubeApi { }); const watchUrl = this.getWatchUrl(namespace); - const responsePromise = this.request.getResponse(watchUrl, null, { signal, timeout: 600_000 }); + const responsePromise = this.request.getResponse( + watchUrl, + null, + merge({ signal, timeout: 600_000 }, getRequestOptions?.()) + ); logger.info(`[KUBE-API] watch (${watchId}) ${retry === true ? "retried" : "started"} ${watchUrl}`);