Skip to content

Commit

Permalink
fix: allowWatchBookmarks should be configurable (#235)
Browse files Browse the repository at this point in the history
Make allowWatchBookmarks configurable

---------

Signed-off-by: Case Wylie <cmwylie19@defenseunicorns.com>
  • Loading branch information
cmwylie19 authored May 1, 2024
1 parent 02bd539 commit d71ae9a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/fluent/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export enum WatchEvent {

/** Configuration for the watch function. */
export type WatchCfg = {
/** Whether to allow watch bookmarks. */
allowWatchBookmarks?: boolean;
/** The resource version to start the watch at, this will be updated on each event. */
resourceVersion?: string;
/** The maximum number of times to retry the watch, the retry count is reset on success. Unlimited retries if not specified. */
Expand Down Expand Up @@ -175,6 +177,7 @@ export class Watcher<T extends GenericClass> {
#buildURL = async () => {
// Build the path and query params for the resource, excluding the name
const { opts, serverUrl } = await k8sCfg("GET");

const url = pathBuilder(serverUrl, this.#model, this.#filters, true);

// Enable the watch query param
Expand All @@ -191,7 +194,10 @@ export class Watcher<T extends GenericClass> {
}

// Enable watch bookmarks
url.searchParams.set("allowWatchBookmarks", "true");
url.searchParams.set(
"allowWatchBookmarks",
this.#watchCfg.allowWatchBookmarks ? `${this.#watchCfg.allowWatchBookmarks}` : "true",
);

// Add the abort signal to the request options
opts.signal = this.#abortController.signal;
Expand Down Expand Up @@ -340,6 +346,7 @@ export class Watcher<T extends GenericClass> {
this.#events.emit(WatchEvent.RECONNECT, err, this.#retryCount);

if (this.#pendingReconnect) {
// wait for the connection to be re-established
this.#events.emit(WatchEvent.RECONNECT_PENDING);
} else {
this.#pendingReconnect = true;
Expand Down

0 comments on commit d71ae9a

Please sign in to comment.