kubernetes-fluent-client 3.3.0 → 3.3.2

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.
@@ -43,8 +43,6 @@ export type WatchCfg = {
43
43
  relistIntervalSec?: number;
44
44
  /** Max amount of seconds to go without receiving an event before reconciliation starts. Defaults to 300 (5 minutes). */
45
45
  lastSeenLimitSeconds?: number;
46
- /** Watch Mechansism */
47
- useLegacyWatch?: boolean;
48
46
  };
49
47
  /** A wrapper around the Kubernetes watch API. */
50
48
  export declare class Watcher<T extends GenericClass> {
@@ -1 +1 @@
1
- {"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../../src/fluent/watch.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,OAAoB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,KAAK,EAAS,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,YAAY,EAAwB,MAAM,UAAU,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,WAAW,EAAc,MAAM,SAAS,CAAC;AAK3D,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;AAC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const crypto_1 = require("crypto");
11
11
  const events_1 = require("events");
12
- const byline_1 = __importDefault(require("byline"));
13
12
  const https_1 = __importDefault(require("https"));
14
- const node_fetch_1 = __importDefault(require("node-fetch"));
15
13
  const undici_1 = require("undici");
16
14
  const fetch_1 = require("../fetch");
17
15
  const types_1 = require("./types");
@@ -59,7 +57,6 @@ class Watcher {
59
57
  #callback;
60
58
  #watchCfg;
61
59
  #latestRelistWindow = "";
62
- #useLegacyWatch = false;
63
60
  // Track the last time data was received
64
61
  #lastSeenTime = NONE;
65
62
  #lastSeenLimit;
@@ -69,7 +66,6 @@ class Watcher {
69
66
  #resyncFailureCount = 0;
70
67
  // Create a stream to read the response body
71
68
  #stream;
72
- #legacyStream;
73
69
  // Create an EventEmitter to emit events
74
70
  #events = new events_1.EventEmitter();
75
71
  // Create a timer to relist the watch
@@ -103,8 +99,6 @@ class Watcher {
103
99
  watchCfg.relistIntervalSec ??= 600;
104
100
  // Set the resync interval to 10 minutes if not specified
105
101
  watchCfg.lastSeenLimitSeconds ??= 600;
106
- // Set the watch mechanism
107
- this.#useLegacyWatch = watchCfg.useLegacyWatch || false;
108
102
  // Set the last seen limit to the resync interval
109
103
  this.#lastSeenLimit = watchCfg.lastSeenLimitSeconds * 1000;
110
104
  // Set the latest relist interval to now
@@ -134,24 +128,14 @@ class Watcher {
134
128
  */
135
129
  async start() {
136
130
  this.#events.emit(WatchEvent.INIT_CACHE_MISS, this.#latestRelistWindow);
137
- if (this.#useLegacyWatch) {
138
- await this.#legacyWatch();
139
- }
140
- else {
141
- await this.#watch();
142
- }
131
+ await this.#watch();
143
132
  return this.#abortController;
144
133
  }
145
134
  /** Close the watch. Also available on the AbortController returned by {@link Watcher.start}. */
146
135
  close() {
147
136
  clearInterval(this.$relistTimer);
148
137
  clearInterval(this.#resyncTimer);
149
- if (this.#useLegacyWatch) {
150
- this.#legacyStreamCleanup();
151
- }
152
- else {
153
- this.#streamCleanup();
154
- }
138
+ this.#streamCleanup();
155
139
  this.#abortController.abort();
156
140
  }
157
141
  /**
@@ -344,49 +328,6 @@ class Watcher {
344
328
  this.#events.emit(WatchEvent.DATA_ERROR, err);
345
329
  }
346
330
  };
347
- /** node-fetch watch */
348
- #legacyWatch = async () => {
349
- try {
350
- // Start with a list operation
351
- await this.#list();
352
- // Build the URL and request options
353
- const { opts, url } = await this.#buildURL(true, this.#resourceVersion);
354
- // Create a stream to read the response body
355
- this.#legacyStream = byline_1.default.createStream();
356
- // Bind the stream events
357
- this.#legacyStream.on("error", this.#errHandler);
358
- this.#legacyStream.on("close", this.#legacyStreamCleanup);
359
- this.#legacyStream.on("finish", this.#legacyStreamCleanup);
360
- // Make the actual request
361
- const response = await (0, node_fetch_1.default)(url, { ...opts });
362
- // If the request is successful, start listening for events
363
- if (response.ok) {
364
- // Reset the pending reconnect flag
365
- this.#pendingReconnect = false;
366
- this.#events.emit(WatchEvent.CONNECT, url.pathname);
367
- const { body } = response;
368
- // Reset the retry count
369
- this.#resyncFailureCount = 0;
370
- this.#events.emit(WatchEvent.INC_RESYNC_FAILURE_COUNT, this.#resyncFailureCount);
371
- // Listen for events and call the callback function
372
- this.#legacyStream.on("data", async (line) => {
373
- await this.#processLine(line, this.#process);
374
- });
375
- // Bind the body events
376
- body.on("error", this.#errHandler);
377
- body.on("close", this.#legacyStreamCleanup);
378
- body.on("finish", this.#legacyStreamCleanup);
379
- // Pipe the response body to the stream
380
- body.pipe(this.#legacyStream);
381
- }
382
- else {
383
- throw new Error(`watch connect failed: ${response.status} ${response.statusText}`);
384
- }
385
- }
386
- catch (e) {
387
- void this.#errHandler(e);
388
- }
389
- };
390
331
  static getHTTPSAgent = (opts) => {
391
332
  // In cluster there will be agent - testing or dev no
392
333
  const agentOptions = opts.agent instanceof https_1.default.Agent
@@ -494,13 +435,7 @@ class Watcher {
494
435
  else {
495
436
  this.#pendingReconnect = true;
496
437
  this.#events.emit(WatchEvent.RECONNECT, this.#resyncFailureCount);
497
- if (this.#useLegacyWatch) {
498
- this.#legacyStreamCleanup();
499
- void this.#legacyWatch();
500
- }
501
- else {
502
- this.#cleanupAndReconnect();
503
- }
438
+ this.#cleanupAndReconnect();
504
439
  }
505
440
  }
506
441
  else {
@@ -520,12 +455,7 @@ class Watcher {
520
455
  case "AbortError":
521
456
  clearInterval(this.$relistTimer);
522
457
  clearInterval(this.#resyncTimer);
523
- if (this.#useLegacyWatch) {
524
- this.#legacyStreamCleanup();
525
- }
526
- else {
527
- this.#streamCleanup();
528
- }
458
+ this.#streamCleanup();
529
459
  this.#events.emit(WatchEvent.ABORT, err);
530
460
  return;
531
461
  case "TooOld":
@@ -552,12 +482,6 @@ class Watcher {
552
482
  this.#stream.destroy();
553
483
  }
554
484
  };
555
- #legacyStreamCleanup = () => {
556
- if (this.#legacyStream) {
557
- this.#legacyStream.removeAllListeners();
558
- this.#legacyStream.destroy();
559
- }
560
- };
561
485
  }
562
486
  exports.Watcher = Watcher;
563
487
  _a = Watcher;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kubernetes-fluent-client",
3
- "version": "3.3.0",
3
+ "version": "3.3.2",
4
4
  "description": "A @kubernetes/client-node fluent API wrapper that leverages K8s Server Side Apply.",
5
5
  "bin": "./dist/cli.js",
6
6
  "main": "dist/index.js",
@@ -38,13 +38,12 @@
38
38
  "homepage": "https://github.com/defenseunicorns/kubernetes-fluent-client#readme",
39
39
  "dependencies": {
40
40
  "@kubernetes/client-node": "1.0.0-rc7",
41
- "byline": "5.0.0",
42
41
  "fast-json-patch": "3.1.1",
43
42
  "http-status-codes": "2.3.0",
44
43
  "node-fetch": "2.7.0",
45
44
  "quicktype-core": "23.0.170",
46
45
  "type-fest": "4.26.1",
47
- "undici": "6.20.1",
46
+ "undici": "6.21.0",
48
47
  "yargs": "17.7.2"
49
48
  },
50
49
  "devDependencies": {
@@ -57,14 +56,14 @@
57
56
  "@types/readable-stream": "4.0.18",
58
57
  "@types/urijs": "^1.19.25",
59
58
  "@types/yargs": "17.0.33",
60
- "@typescript-eslint/eslint-plugin": "8.13.0",
61
- "@typescript-eslint/parser": "8.13.0",
62
- "eslint-plugin-jsdoc": "50.4.3",
59
+ "@typescript-eslint/eslint-plugin": "8.14.0",
60
+ "@typescript-eslint/parser": "8.14.0",
61
+ "eslint-plugin-jsdoc": "50.5.0",
63
62
  "globals": "^15.12.0",
64
63
  "husky": "^9.1.6",
65
64
  "jest": "29.7.0",
66
65
  "lint-staged": "^15.2.10",
67
- "nock": "13.5.5",
66
+ "nock": "13.5.6",
68
67
  "prettier": "3.3.3",
69
68
  "semantic-release": "24.2.0",
70
69
  "ts-jest": "29.2.5",
@@ -3,9 +3,8 @@
3
3
 
4
4
  import { createHash } from "crypto";
5
5
  import { EventEmitter } from "events";
6
- import byline from "byline";
7
6
  import https from "https";
8
- import legacyFetch, { RequestInit } from "node-fetch";
7
+ import { RequestInit } from "node-fetch";
9
8
  import { Agent, fetch } from "undici";
10
9
  import { fetch as wrappedFetch } from "../fetch";
11
10
  import { GenericClass, KubernetesListObject } from "../types";
@@ -55,8 +54,6 @@ export type WatchCfg = {
55
54
  relistIntervalSec?: number;
56
55
  /** Max amount of seconds to go without receiving an event before reconciliation starts. Defaults to 300 (5 minutes). */
57
56
  lastSeenLimitSeconds?: number;
58
- /** Watch Mechansism */
59
- useLegacyWatch?: boolean;
60
57
  };
61
58
 
62
59
  const NONE = 50;
@@ -70,7 +67,7 @@ export class Watcher<T extends GenericClass> {
70
67
  #callback: WatchAction<T>;
71
68
  #watchCfg: WatchCfg;
72
69
  #latestRelistWindow: string = "";
73
- #useLegacyWatch = false;
70
+
74
71
  // Track the last time data was received
75
72
  #lastSeenTime = NONE;
76
73
  #lastSeenLimit: number;
@@ -83,7 +80,6 @@ export class Watcher<T extends GenericClass> {
83
80
 
84
81
  // Create a stream to read the response body
85
82
  #stream?: Readable;
86
- #legacyStream?: byline.LineStream;
87
83
 
88
84
  // Create an EventEmitter to emit events
89
85
  #events = new EventEmitter();
@@ -127,9 +123,6 @@ export class Watcher<T extends GenericClass> {
127
123
  // Set the resync interval to 10 minutes if not specified
128
124
  watchCfg.lastSeenLimitSeconds ??= 600;
129
125
 
130
- // Set the watch mechanism
131
- this.#useLegacyWatch = watchCfg.useLegacyWatch || false;
132
-
133
126
  // Set the last seen limit to the resync interval
134
127
  this.#lastSeenLimit = watchCfg.lastSeenLimitSeconds * 1000;
135
128
 
@@ -169,11 +162,8 @@ export class Watcher<T extends GenericClass> {
169
162
  */
170
163
  public async start(): Promise<AbortController> {
171
164
  this.#events.emit(WatchEvent.INIT_CACHE_MISS, this.#latestRelistWindow);
172
- if (this.#useLegacyWatch) {
173
- await this.#legacyWatch();
174
- } else {
175
- await this.#watch();
176
- }
165
+ await this.#watch();
166
+
177
167
  return this.#abortController;
178
168
  }
179
169
 
@@ -181,11 +171,8 @@ export class Watcher<T extends GenericClass> {
181
171
  public close() {
182
172
  clearInterval(this.$relistTimer);
183
173
  clearInterval(this.#resyncTimer);
184
- if (this.#useLegacyWatch) {
185
- this.#legacyStreamCleanup();
186
- } else {
187
- this.#streamCleanup();
188
- }
174
+
175
+ this.#streamCleanup();
189
176
  this.#abortController.abort();
190
177
  }
191
178
 
@@ -417,58 +404,6 @@ export class Watcher<T extends GenericClass> {
417
404
  this.#events.emit(WatchEvent.DATA_ERROR, err);
418
405
  }
419
406
  };
420
- /** node-fetch watch */
421
- #legacyWatch = async () => {
422
- try {
423
- // Start with a list operation
424
- await this.#list();
425
-
426
- // Build the URL and request options
427
- const { opts, url } = await this.#buildURL(true, this.#resourceVersion);
428
-
429
- // Create a stream to read the response body
430
- this.#legacyStream = byline.createStream();
431
-
432
- // Bind the stream events
433
- this.#legacyStream.on("error", this.#errHandler);
434
- this.#legacyStream.on("close", this.#legacyStreamCleanup);
435
- this.#legacyStream.on("finish", this.#legacyStreamCleanup);
436
-
437
- // Make the actual request
438
- const response = await legacyFetch(url, { ...opts });
439
-
440
- // If the request is successful, start listening for events
441
- if (response.ok) {
442
- // Reset the pending reconnect flag
443
- this.#pendingReconnect = false;
444
-
445
- this.#events.emit(WatchEvent.CONNECT, url.pathname);
446
-
447
- const { body } = response;
448
-
449
- // Reset the retry count
450
- this.#resyncFailureCount = 0;
451
- this.#events.emit(WatchEvent.INC_RESYNC_FAILURE_COUNT, this.#resyncFailureCount);
452
-
453
- // Listen for events and call the callback function
454
- this.#legacyStream.on("data", async line => {
455
- await this.#processLine(line, this.#process);
456
- });
457
-
458
- // Bind the body events
459
- body.on("error", this.#errHandler);
460
- body.on("close", this.#legacyStreamCleanup);
461
- body.on("finish", this.#legacyStreamCleanup);
462
-
463
- // Pipe the response body to the stream
464
- body.pipe(this.#legacyStream);
465
- } else {
466
- throw new Error(`watch connect failed: ${response.status} ${response.statusText}`);
467
- }
468
- } catch (e) {
469
- void this.#errHandler(e);
470
- }
471
- };
472
407
 
473
408
  static getHTTPSAgent = (opts: RequestInit) => {
474
409
  // In cluster there will be agent - testing or dev no
@@ -595,12 +530,7 @@ export class Watcher<T extends GenericClass> {
595
530
  } else {
596
531
  this.#pendingReconnect = true;
597
532
  this.#events.emit(WatchEvent.RECONNECT, this.#resyncFailureCount);
598
- if (this.#useLegacyWatch) {
599
- this.#legacyStreamCleanup();
600
- void this.#legacyWatch();
601
- } else {
602
- this.#cleanupAndReconnect();
603
- }
533
+ this.#cleanupAndReconnect();
604
534
  }
605
535
  } else {
606
536
  // Otherwise, call the finally function if it exists
@@ -623,11 +553,9 @@ export class Watcher<T extends GenericClass> {
623
553
  case "AbortError":
624
554
  clearInterval(this.$relistTimer);
625
555
  clearInterval(this.#resyncTimer);
626
- if (this.#useLegacyWatch) {
627
- this.#legacyStreamCleanup();
628
- } else {
629
- this.#streamCleanup();
630
- }
556
+
557
+ this.#streamCleanup();
558
+
631
559
  this.#events.emit(WatchEvent.ABORT, err);
632
560
  return;
633
561
 
@@ -659,11 +587,4 @@ export class Watcher<T extends GenericClass> {
659
587
  this.#stream.destroy();
660
588
  }
661
589
  };
662
-
663
- #legacyStreamCleanup = () => {
664
- if (this.#legacyStream) {
665
- this.#legacyStream.removeAllListeners();
666
- this.#legacyStream.destroy();
667
- }
668
- };
669
590
  }