kubernetes-fluent-client 3.10.12-nightly.5 → 3.10.12-nightly.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fetch.d.ts.map +1 -1
- package/dist/fetch.js +5 -0
- package/dist/fluent/watch.d.ts.map +1 -1
- package/dist/fluent/watch.js +25 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/package.json +1 -1
- package/src/fetch.ts +8 -0
- package/src/fluent/watch.ts +33 -7
- package/src/index.ts +1 -0
package/dist/fetch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAIA,OAAO,EAAwB,WAAW,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAExE,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI;IAC7B,IAAI,EAAE,CAAC,CAAC;IACR,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAsB,KAAK,CAAC,CAAC,EAC3B,GAAG,EAAE,GAAG,GAAG,WAAW,EACtB,IAAI,CAAC,EAAE,WAAW,GACjB,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAIA,OAAO,EAAwB,WAAW,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAExE,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI;IAC7B,IAAI,EAAE,CAAC,CAAC;IACR,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAsB,KAAK,CAAC,CAAC,EAC3B,GAAG,EAAE,GAAG,GAAG,WAAW,EACtB,IAAI,CAAC,EAAE,WAAW,GACjB,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAuC3B"}
|
package/dist/fetch.js
CHANGED
|
@@ -20,6 +20,11 @@ export async function fetch(url, init) {
|
|
|
20
20
|
try {
|
|
21
21
|
const resp = await undiciFetch(url, init);
|
|
22
22
|
const contentType = resp.headers.get("content-type") || "";
|
|
23
|
+
console.log(`FETCH_HEADERS: `, JSON.stringify([...resp.headers]) +
|
|
24
|
+
"\nFETCH_URL: " +
|
|
25
|
+
url.toString() +
|
|
26
|
+
"\nFETCH_STATUS: " +
|
|
27
|
+
resp.status);
|
|
23
28
|
// Parse the response as JSON if the content type is JSON
|
|
24
29
|
if (contentType.includes("application/json")) {
|
|
25
30
|
data = (await resp.json());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../../src/fluent/watch.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,OAAO,EAAE,YAAY,EAAwB,MAAM,aAAa,CAAC;AAGjE,OAAO,EAGL,WAAW,EACX,OAAO,EAER,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../../src/fluent/watch.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,OAAO,EAAE,YAAY,EAAwB,MAAM,aAAa,CAAC;AAGjE,OAAO,EAGL,WAAW,EACX,OAAO,EAER,MAAM,mBAAmB,CAAC;AAK3B,oBAAY,UAAU;IACpB,sCAAsC;IACtC,OAAO,YAAY;IACnB,2BAA2B;IAC3B,aAAa,kBAAkB;IAC/B,kDAAkD;IAClD,UAAU,eAAe;IACzB,0BAA0B;IAC1B,SAAS,cAAc;IACvB,8BAA8B;IAC9B,OAAO,YAAY;IACnB,sBAAsB;IACtB,KAAK,UAAU;IACf,mCAAmC;IACnC,IAAI,SAAS;IACb,wCAAwC;IACxC,oBAAoB,yBAAyB;IAC7C,qCAAqC;IACrC,iBAAiB,sBAAsB;IACvC,kCAAkC;IAClC,IAAI,SAAS;IACb,2BAA2B;IAC3B,UAAU,eAAe;IACzB,mBAAmB;IACnB,UAAU,eAAe;IACzB,qCAAqC;IACrC,wBAAwB,6BAA6B;IACrD,iCAAiC;IACjC,eAAe,oBAAoB;CACpC;AAED,4CAA4C;AAC5C,MAAM,MAAM,QAAQ,GAAG;IACrB,+HAA+H;IAC/H,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,wDAAwD;IACxD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,+FAA+F;IAC/F,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,wHAAwH;IACxH,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B,CAAC;AAKF,iDAAiD;AACjD,qBAAa,OAAO,CAAC,CAAC,SAAS,YAAY;;IAyBzC,YAAY,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC;IAc9B;;;;;;;;;;;OAWG;gBACS,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,QAAQ,GAAE,QAAa;IA6CzF;;;;OAIG;IACU,KAAK,IAAI,OAAO,CAAC,eAAe,CAAC;IAO9C,gGAAgG;IACzF,KAAK;IAQZ;;;;;;OAMG;IACH,IAAW,MAAM,IAAI,YAAY,CAEhC;CA6WF"}
|
package/dist/fluent/watch.js
CHANGED
|
@@ -6,6 +6,9 @@ import { fetch as wrappedFetch } from "../fetch.js";
|
|
|
6
6
|
import { k8sCfg, pathBuilder, getHeaders } from "./utils.js";
|
|
7
7
|
import { Readable } from "stream";
|
|
8
8
|
import { WatchPhase, FetchMethods, } from "./shared-types.js";
|
|
9
|
+
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
10
|
+
let startSleep = 5000;
|
|
11
|
+
const maxSleep = 120000;
|
|
9
12
|
export var WatchEvent;
|
|
10
13
|
(function (WatchEvent) {
|
|
11
14
|
/** Watch is connected successfully */
|
|
@@ -100,7 +103,7 @@ export class Watcher {
|
|
|
100
103
|
void this.#list();
|
|
101
104
|
}, watchCfg.relistIntervalSec * 1000 + jitter);
|
|
102
105
|
// Rebuild the watch every resync delay interval
|
|
103
|
-
this.#resyncTimer = setInterval(this.#checkResync, watchCfg.resyncDelaySec * 1000 + jitter);
|
|
106
|
+
this.#resyncTimer = setInterval(async () => await this.#checkResync(), watchCfg.resyncDelaySec * 1000 + jitter);
|
|
104
107
|
// Bind class properties
|
|
105
108
|
this.#model = model;
|
|
106
109
|
this.#filters = filters;
|
|
@@ -183,6 +186,10 @@ export class Watcher {
|
|
|
183
186
|
const list = response.data;
|
|
184
187
|
// If the request fails, emit an error event and return
|
|
185
188
|
if (!response.ok) {
|
|
189
|
+
// Backoff here
|
|
190
|
+
await sleep(startSleep);
|
|
191
|
+
startSleep = Math.min(startSleep * 2, maxSleep);
|
|
192
|
+
await this.#list(continueToken, removedItems);
|
|
186
193
|
this.#events.emit(WatchEvent.LIST_ERROR, new Error(`list failed: ${response.status} ${response.statusText}`));
|
|
187
194
|
return;
|
|
188
195
|
}
|
|
@@ -302,6 +309,11 @@ export class Watcher {
|
|
|
302
309
|
headers: await getHeaders(),
|
|
303
310
|
...opts,
|
|
304
311
|
});
|
|
312
|
+
console.log(`WATCH_FETCH: `, JSON.stringify([...response.headers]) +
|
|
313
|
+
"\nWATCH_URL: " +
|
|
314
|
+
serverUrl.toString() +
|
|
315
|
+
"\nWATCH_STATUS: " +
|
|
316
|
+
response.status);
|
|
305
317
|
const url = serverUrl instanceof URL ? serverUrl : new URL(serverUrl);
|
|
306
318
|
// If the request is successful, start listening for events
|
|
307
319
|
if (response.ok) {
|
|
@@ -313,6 +325,7 @@ export class Watcher {
|
|
|
313
325
|
throw new Error("No response body found");
|
|
314
326
|
}
|
|
315
327
|
// Reset the retry count
|
|
328
|
+
startSleep = 5000;
|
|
316
329
|
this.#resyncFailureCount = 0;
|
|
317
330
|
this.#events.emit(WatchEvent.INC_RESYNC_FAILURE_COUNT, this.#resyncFailureCount);
|
|
318
331
|
this.#stream = Readable.from(body);
|
|
@@ -332,21 +345,24 @@ export class Watcher {
|
|
|
332
345
|
void this.#errHandler(err);
|
|
333
346
|
}
|
|
334
347
|
});
|
|
335
|
-
this.#stream.on("close", this.#cleanupAndReconnect);
|
|
336
|
-
this.#stream.on("end", this.#cleanupAndReconnect);
|
|
348
|
+
this.#stream.on("close", async () => await this.#cleanupAndReconnect());
|
|
349
|
+
this.#stream.on("end", async () => await this.#cleanupAndReconnect());
|
|
337
350
|
this.#stream.on("error", this.#errHandler);
|
|
338
|
-
this.#stream.on("finish", this.#cleanupAndReconnect);
|
|
351
|
+
this.#stream.on("finish", async () => await this.#cleanupAndReconnect());
|
|
339
352
|
}
|
|
340
353
|
else {
|
|
341
354
|
throw new Error(`watch connect failed: ${response.status} ${response.statusText}`);
|
|
342
355
|
}
|
|
343
356
|
}
|
|
344
357
|
catch (e) {
|
|
358
|
+
// await sleep(startSleep);
|
|
359
|
+
// startSleep = Math.min(startSleep * 2, maxSleep);
|
|
360
|
+
console.log(`WATCH_ERROR: `, e);
|
|
345
361
|
void this.#errHandler(e);
|
|
346
362
|
}
|
|
347
363
|
};
|
|
348
364
|
/** Clear the resync timer and schedule a new one. */
|
|
349
|
-
#checkResync = () => {
|
|
365
|
+
#checkResync = async () => {
|
|
350
366
|
// Ignore if the last seen time is not set
|
|
351
367
|
if (this.#lastSeenTime === NONE) {
|
|
352
368
|
return;
|
|
@@ -369,7 +385,7 @@ export class Watcher {
|
|
|
369
385
|
else {
|
|
370
386
|
this.#pendingReconnect = true;
|
|
371
387
|
this.#events.emit(WatchEvent.RECONNECT, this.#resyncFailureCount);
|
|
372
|
-
this.#cleanupAndReconnect();
|
|
388
|
+
await this.#cleanupAndReconnect();
|
|
373
389
|
}
|
|
374
390
|
}
|
|
375
391
|
else {
|
|
@@ -405,8 +421,10 @@ export class Watcher {
|
|
|
405
421
|
this.#lastSeenTime = OVERRIDE;
|
|
406
422
|
};
|
|
407
423
|
/** Cleanup the stream and connect */
|
|
408
|
-
#cleanupAndReconnect = () => {
|
|
424
|
+
#cleanupAndReconnect = async () => {
|
|
409
425
|
this.#streamCleanup();
|
|
426
|
+
await sleep(startSleep);
|
|
427
|
+
startSleep = Math.min(startSleep * 2, maxSleep);
|
|
410
428
|
void this.#watch();
|
|
411
429
|
};
|
|
412
430
|
/** Cleanup the stream and listeners. */
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,YAAY,CAAC;AAGpB,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AAEtC,oGAAoG;AACpG,OAAO,EAAE,IAAI,EAAE,CAAC;AAGhB,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGnC,OAAO,EAAE,WAAW,IAAI,WAAW,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,YAAY,CAAC;AAGpB,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AAEtC,oGAAoG;AACpG,OAAO,EAAE,IAAI,EAAE,CAAC;AAGhB,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGnC,OAAO,EAAE,WAAW,IAAI,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAI/D,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGzD,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAGxC,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAGnE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,cAAc,YAAY,CAAC;AAG3B,OAAO,KAAK,MAAM,MAAM,gDAAgD,CAAC;AAEzE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export { fetch } from "./fetch.js";
|
|
|
10
10
|
// Export the HTTP status codes
|
|
11
11
|
export { StatusCodes as fetchStatus } from "http-status-codes";
|
|
12
12
|
// Export the Watch Config and Event types
|
|
13
|
+
// export { WatchCfg, WatchEvent, type DisposableWatcher } from "./fluent/watch.js";
|
|
13
14
|
export { WatchEvent } from "./fluent/watch.js";
|
|
14
15
|
// Export the fluent API entrypoint
|
|
15
16
|
export { K8s } from "./fluent/index.js";
|
package/package.json
CHANGED
package/src/fetch.ts
CHANGED
|
@@ -32,6 +32,14 @@ export async function fetch<T>(
|
|
|
32
32
|
try {
|
|
33
33
|
const resp = await undiciFetch(url, init);
|
|
34
34
|
const contentType = resp.headers.get("content-type") || "";
|
|
35
|
+
console.log(
|
|
36
|
+
`FETCH_HEADERS: `,
|
|
37
|
+
JSON.stringify([...resp.headers]) +
|
|
38
|
+
"\nFETCH_URL: " +
|
|
39
|
+
url.toString() +
|
|
40
|
+
"\nFETCH_STATUS: " +
|
|
41
|
+
resp.status,
|
|
42
|
+
);
|
|
35
43
|
|
|
36
44
|
// Parse the response as JSON if the content type is JSON
|
|
37
45
|
if (contentType.includes("application/json")) {
|
package/src/fluent/watch.ts
CHANGED
|
@@ -14,6 +14,10 @@ import {
|
|
|
14
14
|
Filters,
|
|
15
15
|
FetchMethods,
|
|
16
16
|
} from "./shared-types.js";
|
|
17
|
+
|
|
18
|
+
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
|
|
19
|
+
let startSleep = 5000;
|
|
20
|
+
const maxSleep = 120000;
|
|
17
21
|
export enum WatchEvent {
|
|
18
22
|
/** Watch is connected successfully */
|
|
19
23
|
CONNECT = "connect",
|
|
@@ -142,7 +146,10 @@ export class Watcher<T extends GenericClass> {
|
|
|
142
146
|
);
|
|
143
147
|
|
|
144
148
|
// Rebuild the watch every resync delay interval
|
|
145
|
-
this.#resyncTimer = setInterval(
|
|
149
|
+
this.#resyncTimer = setInterval(
|
|
150
|
+
async () => await this.#checkResync(),
|
|
151
|
+
watchCfg.resyncDelaySec * 1000 + jitter,
|
|
152
|
+
);
|
|
146
153
|
|
|
147
154
|
// Bind class properties
|
|
148
155
|
this.#model = model;
|
|
@@ -246,6 +253,10 @@ export class Watcher<T extends GenericClass> {
|
|
|
246
253
|
|
|
247
254
|
// If the request fails, emit an error event and return
|
|
248
255
|
if (!response.ok) {
|
|
256
|
+
// Backoff here
|
|
257
|
+
await sleep(startSleep);
|
|
258
|
+
startSleep = Math.min(startSleep * 2, maxSleep);
|
|
259
|
+
await this.#list(continueToken, removedItems);
|
|
249
260
|
this.#events.emit(
|
|
250
261
|
WatchEvent.LIST_ERROR,
|
|
251
262
|
new Error(`list failed: ${response.status} ${response.statusText}`),
|
|
@@ -394,6 +405,15 @@ export class Watcher<T extends GenericClass> {
|
|
|
394
405
|
...opts,
|
|
395
406
|
});
|
|
396
407
|
|
|
408
|
+
console.log(
|
|
409
|
+
`WATCH_FETCH: `,
|
|
410
|
+
JSON.stringify([...response.headers]) +
|
|
411
|
+
"\nWATCH_URL: " +
|
|
412
|
+
serverUrl.toString() +
|
|
413
|
+
"\nWATCH_STATUS: " +
|
|
414
|
+
response.status,
|
|
415
|
+
);
|
|
416
|
+
|
|
397
417
|
const url = serverUrl instanceof URL ? serverUrl : new URL(serverUrl);
|
|
398
418
|
|
|
399
419
|
// If the request is successful, start listening for events
|
|
@@ -410,6 +430,7 @@ export class Watcher<T extends GenericClass> {
|
|
|
410
430
|
}
|
|
411
431
|
|
|
412
432
|
// Reset the retry count
|
|
433
|
+
startSleep = 5000;
|
|
413
434
|
this.#resyncFailureCount = 0;
|
|
414
435
|
this.#events.emit(WatchEvent.INC_RESYNC_FAILURE_COUNT, this.#resyncFailureCount);
|
|
415
436
|
|
|
@@ -432,20 +453,23 @@ export class Watcher<T extends GenericClass> {
|
|
|
432
453
|
}
|
|
433
454
|
});
|
|
434
455
|
|
|
435
|
-
this.#stream.on("close", this.#cleanupAndReconnect);
|
|
436
|
-
this.#stream.on("end", this.#cleanupAndReconnect);
|
|
456
|
+
this.#stream.on("close", async () => await this.#cleanupAndReconnect());
|
|
457
|
+
this.#stream.on("end", async () => await this.#cleanupAndReconnect());
|
|
437
458
|
this.#stream.on("error", this.#errHandler);
|
|
438
|
-
this.#stream.on("finish", this.#cleanupAndReconnect);
|
|
459
|
+
this.#stream.on("finish", async () => await this.#cleanupAndReconnect());
|
|
439
460
|
} else {
|
|
440
461
|
throw new Error(`watch connect failed: ${response.status} ${response.statusText}`);
|
|
441
462
|
}
|
|
442
463
|
} catch (e) {
|
|
464
|
+
// await sleep(startSleep);
|
|
465
|
+
// startSleep = Math.min(startSleep * 2, maxSleep);
|
|
466
|
+
console.log(`WATCH_ERROR: `, e);
|
|
443
467
|
void this.#errHandler(e);
|
|
444
468
|
}
|
|
445
469
|
};
|
|
446
470
|
|
|
447
471
|
/** Clear the resync timer and schedule a new one. */
|
|
448
|
-
#checkResync = () => {
|
|
472
|
+
#checkResync = async () => {
|
|
449
473
|
// Ignore if the last seen time is not set
|
|
450
474
|
if (this.#lastSeenTime === NONE) {
|
|
451
475
|
return;
|
|
@@ -473,7 +497,7 @@ export class Watcher<T extends GenericClass> {
|
|
|
473
497
|
} else {
|
|
474
498
|
this.#pendingReconnect = true;
|
|
475
499
|
this.#events.emit(WatchEvent.RECONNECT, this.#resyncFailureCount);
|
|
476
|
-
this.#cleanupAndReconnect();
|
|
500
|
+
await this.#cleanupAndReconnect();
|
|
477
501
|
}
|
|
478
502
|
} else {
|
|
479
503
|
// Otherwise, call the finally function if it exists
|
|
@@ -518,8 +542,10 @@ export class Watcher<T extends GenericClass> {
|
|
|
518
542
|
};
|
|
519
543
|
|
|
520
544
|
/** Cleanup the stream and connect */
|
|
521
|
-
#cleanupAndReconnect = () => {
|
|
545
|
+
#cleanupAndReconnect = async () => {
|
|
522
546
|
this.#streamCleanup();
|
|
547
|
+
await sleep(startSleep);
|
|
548
|
+
startSleep = Math.min(startSleep * 2, maxSleep);
|
|
523
549
|
void this.#watch();
|
|
524
550
|
};
|
|
525
551
|
|
package/src/index.ts
CHANGED
|
@@ -16,6 +16,7 @@ export { fetch } from "./fetch.js";
|
|
|
16
16
|
export { StatusCodes as fetchStatus } from "http-status-codes";
|
|
17
17
|
|
|
18
18
|
// Export the Watch Config and Event types
|
|
19
|
+
// export { WatchCfg, WatchEvent, type DisposableWatcher } from "./fluent/watch.js";
|
|
19
20
|
export { WatchCfg, WatchEvent } from "./fluent/watch.js";
|
|
20
21
|
|
|
21
22
|
// Export the fluent API entrypoint
|