kubernetes-fluent-client 3.1.2 → 3.1.3
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/.husky/pre-commit +1 -0
- package/.lintstagedrc.json +5 -0
- package/dist/fluent/watch.d.ts.map +1 -1
- package/dist/fluent/watch.js +4 -3
- package/package.json +8 -5
- package/src/fluent/watch.ts +6 -4
- package/dist/fetch.test.d.ts +0 -2
- package/dist/fetch.test.d.ts.map +0 -1
- package/dist/fetch.test.js +0 -97
- package/dist/fileSystem.test.d.ts +0 -2
- package/dist/fileSystem.test.d.ts.map +0 -1
- package/dist/fileSystem.test.js +0 -75
- package/dist/fluent/http2-watch.spec.d.ts +0 -2
- package/dist/fluent/http2-watch.spec.d.ts.map +0 -1
- package/dist/fluent/http2-watch.spec.js +0 -284
- package/dist/fluent/index.test.d.ts +0 -2
- package/dist/fluent/index.test.d.ts.map +0 -1
- package/dist/fluent/index.test.js +0 -193
- package/dist/fluent/utils.test.d.ts +0 -2
- package/dist/fluent/utils.test.d.ts.map +0 -1
- package/dist/fluent/utils.test.js +0 -215
- package/dist/fluent/watch.spec.d.ts +0 -2
- package/dist/fluent/watch.spec.d.ts.map +0 -1
- package/dist/fluent/watch.spec.js +0 -261
- package/dist/generate.test.d.ts +0 -2
- package/dist/generate.test.d.ts.map +0 -1
- package/dist/generate.test.js +0 -320
- package/dist/helpers.test.d.ts +0 -2
- package/dist/helpers.test.d.ts.map +0 -1
- package/dist/helpers.test.js +0 -37
- package/dist/kinds.test.d.ts +0 -2
- package/dist/kinds.test.d.ts.map +0 -1
- package/dist/kinds.test.js +0 -155
- package/dist/postProcessing.test.d.ts +0 -2
- package/dist/postProcessing.test.d.ts.map +0 -1
- package/dist/postProcessing.test.js +0 -550
- package/e2e/cli.e2e.test.ts +0 -127
- package/e2e/crds/policyreports.default.expected/policyreport-v1alpha1.ts +0 -332
- package/e2e/crds/policyreports.default.expected/policyreport-v1alpha2.ts +0 -360
- package/e2e/crds/policyreports.default.expected/policyreport-v1beta1.ts +0 -360
- package/e2e/crds/policyreports.no.post.expected/policyreport-v1alpha1.ts +0 -331
- package/e2e/crds/policyreports.no.post.expected/policyreport-v1alpha2.ts +0 -360
- package/e2e/crds/policyreports.no.post.expected/policyreport-v1beta1.ts +0 -360
- package/e2e/crds/test.yaml/policyreports.test.yaml +0 -1008
- package/e2e/crds/test.yaml/uds-podmonitors.test.yaml +0 -1245
- package/e2e/crds/uds-podmonitors.default.expected/podmonitor-v1.ts +0 -1333
- package/e2e/crds/uds-podmonitors.no.post.expected/podmonitor-v1.ts +0 -1360
- package/src/fetch.test.ts +0 -115
- package/src/fileSystem.test.ts +0 -67
- package/src/fluent/http2-watch.spec.ts +0 -335
- package/src/fluent/index.test.ts +0 -268
- package/src/fluent/utils.test.ts +0 -276
- package/src/fluent/watch.spec.ts +0 -299
- package/src/generate.test.ts +0 -399
- package/src/helpers.test.ts +0 -42
- package/src/kinds.test.ts +0 -166
- package/src/postProcessing.test.ts +0 -742
|
@@ -0,0 +1 @@
|
|
|
1
|
+
npx lint-staged --verbose
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../../src/fluent/watch.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAKtC,OAAO,EAAE,YAAY,EAAwB,MAAM,UAAU,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,WAAW,EAAqC,MAAM,SAAS,CAAC;AAIlF,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,yBAAy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CAqfF"}
|
package/dist/fluent/watch.js
CHANGED
|
@@ -433,8 +433,7 @@ class Watcher {
|
|
|
433
433
|
// Handle client connection errors
|
|
434
434
|
client.on("error", err => {
|
|
435
435
|
this.#events.emit(WatchEvent.NETWORK_ERROR, err);
|
|
436
|
-
this.#
|
|
437
|
-
this.#scheduleReconnect();
|
|
436
|
+
this.#cleanupAndReconnect(client, err);
|
|
438
437
|
});
|
|
439
438
|
// Set up headers for the HTTP/2 request
|
|
440
439
|
const headers = await this.#generateRequestHeaders(url);
|
|
@@ -477,6 +476,9 @@ class Watcher {
|
|
|
477
476
|
this.#pendingReconnect = true;
|
|
478
477
|
this.#events.emit(WatchEvent.RECONNECT, this.#resyncFailureCount);
|
|
479
478
|
this.#streamCleanup();
|
|
479
|
+
if (this.#useHTTP2) {
|
|
480
|
+
this.#cleanupAndReconnect();
|
|
481
|
+
}
|
|
480
482
|
if (!this.#useHTTP2) {
|
|
481
483
|
void this.#watch();
|
|
482
484
|
}
|
|
@@ -585,7 +587,6 @@ class Watcher {
|
|
|
585
587
|
#cleanupAndReconnect(client, error) {
|
|
586
588
|
this.#streamCleanup(client);
|
|
587
589
|
if (error) {
|
|
588
|
-
this.#events.emit(WatchEvent.NETWORK_ERROR, error);
|
|
589
590
|
void this.#errHandler(error);
|
|
590
591
|
}
|
|
591
592
|
this.#scheduleReconnect();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kubernetes-fluent-client",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.3",
|
|
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",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"test": "jest src --coverage",
|
|
13
13
|
"test:e2e": "jest e2e",
|
|
14
14
|
"format:check": "eslint src && prettier . --check",
|
|
15
|
-
"format:fix": "eslint --fix src && prettier . --write"
|
|
15
|
+
"format:fix": "eslint --fix src && prettier . --write",
|
|
16
|
+
"prepare": "if [ \"$NODE_ENV\" != 'production' ]; then husky; fi"
|
|
16
17
|
},
|
|
17
18
|
"engines": {
|
|
18
19
|
"node": ">=18.0.0"
|
|
@@ -53,10 +54,12 @@
|
|
|
53
54
|
"@types/readable-stream": "4.0.15",
|
|
54
55
|
"@types/urijs": "^1.19.25",
|
|
55
56
|
"@types/yargs": "17.0.33",
|
|
56
|
-
"@typescript-eslint/eslint-plugin": "8.
|
|
57
|
-
"@typescript-eslint/parser": "8.
|
|
58
|
-
"eslint-plugin-jsdoc": "50.4.
|
|
57
|
+
"@typescript-eslint/eslint-plugin": "8.10.0",
|
|
58
|
+
"@typescript-eslint/parser": "8.10.0",
|
|
59
|
+
"eslint-plugin-jsdoc": "50.4.3",
|
|
60
|
+
"husky": "^8.0.0",
|
|
59
61
|
"jest": "29.7.0",
|
|
62
|
+
"lint-staged": "^15.2.10",
|
|
60
63
|
"nock": "13.5.5",
|
|
61
64
|
"prettier": "3.3.3",
|
|
62
65
|
"semantic-release": "24.1.2",
|
package/src/fluent/watch.ts
CHANGED
|
@@ -525,8 +525,7 @@ export class Watcher<T extends GenericClass> {
|
|
|
525
525
|
// Handle client connection errors
|
|
526
526
|
client.on("error", err => {
|
|
527
527
|
this.#events.emit(WatchEvent.NETWORK_ERROR, err);
|
|
528
|
-
this.#
|
|
529
|
-
this.#scheduleReconnect();
|
|
528
|
+
this.#cleanupAndReconnect(client, err);
|
|
530
529
|
});
|
|
531
530
|
|
|
532
531
|
// Set up headers for the HTTP/2 request
|
|
@@ -579,6 +578,10 @@ export class Watcher<T extends GenericClass> {
|
|
|
579
578
|
this.#events.emit(WatchEvent.RECONNECT, this.#resyncFailureCount);
|
|
580
579
|
this.#streamCleanup();
|
|
581
580
|
|
|
581
|
+
if (this.#useHTTP2) {
|
|
582
|
+
this.#cleanupAndReconnect();
|
|
583
|
+
}
|
|
584
|
+
|
|
582
585
|
if (!this.#useHTTP2) {
|
|
583
586
|
void this.#watch();
|
|
584
587
|
}
|
|
@@ -699,11 +702,10 @@ export class Watcher<T extends GenericClass> {
|
|
|
699
702
|
* @param client - the client session
|
|
700
703
|
* @param error - the error that occurred
|
|
701
704
|
*/
|
|
702
|
-
#cleanupAndReconnect(client
|
|
705
|
+
#cleanupAndReconnect(client?: http2.ClientHttp2Session, error?: Error) {
|
|
703
706
|
this.#streamCleanup(client);
|
|
704
707
|
|
|
705
708
|
if (error) {
|
|
706
|
-
this.#events.emit(WatchEvent.NETWORK_ERROR, error);
|
|
707
709
|
void this.#errHandler(error);
|
|
708
710
|
}
|
|
709
711
|
|
package/dist/fetch.test.d.ts
DELETED
package/dist/fetch.test.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.test.d.ts","sourceRoot":"","sources":["../src/fetch.test.ts"],"names":[],"mappings":""}
|
package/dist/fetch.test.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
// SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
|
|
4
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
-
};
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
const globals_1 = require("@jest/globals");
|
|
9
|
-
const http_status_codes_1 = require("http-status-codes");
|
|
10
|
-
const nock_1 = __importDefault(require("nock"));
|
|
11
|
-
const fetch_1 = require("./fetch");
|
|
12
|
-
(0, globals_1.beforeEach)(() => {
|
|
13
|
-
(0, nock_1.default)("https://jsonplaceholder.typicode.com")
|
|
14
|
-
.get("/todos/1")
|
|
15
|
-
.reply(200, {
|
|
16
|
-
userId: 1,
|
|
17
|
-
id: 1,
|
|
18
|
-
title: "Example title",
|
|
19
|
-
completed: false,
|
|
20
|
-
})
|
|
21
|
-
.post("/todos", {
|
|
22
|
-
title: "test todo",
|
|
23
|
-
userId: 1,
|
|
24
|
-
completed: false,
|
|
25
|
-
})
|
|
26
|
-
.reply(200, (uri, requestBody) => requestBody)
|
|
27
|
-
.get("/todos/empty-null")
|
|
28
|
-
.reply(200, undefined)
|
|
29
|
-
.get("/todos/empty-string")
|
|
30
|
-
.reply(200, "")
|
|
31
|
-
.get("/todos/empty-object")
|
|
32
|
-
.reply(200, {})
|
|
33
|
-
.get("/todos/invalid")
|
|
34
|
-
.replyWithError("Something bad happened");
|
|
35
|
-
});
|
|
36
|
-
(0, globals_1.test)("fetch: should return without type data", async () => {
|
|
37
|
-
const url = "https://jsonplaceholder.typicode.com/todos/1";
|
|
38
|
-
const { data, ok } = await (0, fetch_1.fetch)(url);
|
|
39
|
-
(0, globals_1.expect)(ok).toBe(true);
|
|
40
|
-
(0, globals_1.expect)(data["title"]).toBe("Example title");
|
|
41
|
-
});
|
|
42
|
-
(0, globals_1.test)("fetch: should return parsed JSON response as a specific type", async () => {
|
|
43
|
-
const url = "https://jsonplaceholder.typicode.com/todos/1";
|
|
44
|
-
const { data, ok } = await (0, fetch_1.fetch)(url);
|
|
45
|
-
(0, globals_1.expect)(ok).toBe(true);
|
|
46
|
-
(0, globals_1.expect)(data.id).toBe(1);
|
|
47
|
-
(0, globals_1.expect)(typeof data.title).toBe("string");
|
|
48
|
-
(0, globals_1.expect)(typeof data.completed).toBe("boolean");
|
|
49
|
-
});
|
|
50
|
-
(0, globals_1.test)("fetch: should handle additional request options", async () => {
|
|
51
|
-
const url = "https://jsonplaceholder.typicode.com/todos";
|
|
52
|
-
const requestOptions = {
|
|
53
|
-
method: "POST",
|
|
54
|
-
body: JSON.stringify({
|
|
55
|
-
title: "test todo",
|
|
56
|
-
userId: 1,
|
|
57
|
-
completed: false,
|
|
58
|
-
}),
|
|
59
|
-
headers: {
|
|
60
|
-
"Content-type": "application/json; charset=UTF-8",
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
64
|
-
const { data, ok } = await (0, fetch_1.fetch)(url, requestOptions);
|
|
65
|
-
(0, globals_1.expect)(ok).toBe(true);
|
|
66
|
-
(0, globals_1.expect)(data["title"]).toBe("test todo");
|
|
67
|
-
(0, globals_1.expect)(data["userId"]).toBe(1);
|
|
68
|
-
(0, globals_1.expect)(data["completed"]).toBe(false);
|
|
69
|
-
});
|
|
70
|
-
(0, globals_1.test)("fetch: should handle empty (null) responses", async () => {
|
|
71
|
-
const url = "https://jsonplaceholder.typicode.com/todos/empty-null";
|
|
72
|
-
const resp = await (0, fetch_1.fetch)(url);
|
|
73
|
-
(0, globals_1.expect)(resp.data).toBe("");
|
|
74
|
-
(0, globals_1.expect)(resp.ok).toBe(true);
|
|
75
|
-
(0, globals_1.expect)(resp.status).toBe(http_status_codes_1.StatusCodes.OK);
|
|
76
|
-
});
|
|
77
|
-
(0, globals_1.test)("fetch: should handle empty (string) responses", async () => {
|
|
78
|
-
const url = "https://jsonplaceholder.typicode.com/todos/empty-string";
|
|
79
|
-
const resp = await (0, fetch_1.fetch)(url);
|
|
80
|
-
(0, globals_1.expect)(resp.data).toBe("");
|
|
81
|
-
(0, globals_1.expect)(resp.ok).toBe(true);
|
|
82
|
-
(0, globals_1.expect)(resp.status).toBe(http_status_codes_1.StatusCodes.OK);
|
|
83
|
-
});
|
|
84
|
-
(0, globals_1.test)("fetch: should handle empty (object) responses", async () => {
|
|
85
|
-
const url = "https://jsonplaceholder.typicode.com/todos/empty-object";
|
|
86
|
-
const resp = await (0, fetch_1.fetch)(url);
|
|
87
|
-
(0, globals_1.expect)(resp.data).toEqual({});
|
|
88
|
-
(0, globals_1.expect)(resp.ok).toBe(true);
|
|
89
|
-
(0, globals_1.expect)(resp.status).toBe(http_status_codes_1.StatusCodes.OK);
|
|
90
|
-
});
|
|
91
|
-
(0, globals_1.test)("fetch: should handle failed requests without throwing an error", async () => {
|
|
92
|
-
const url = "https://jsonplaceholder.typicode.com/todos/invalid";
|
|
93
|
-
const resp = await (0, fetch_1.fetch)(url);
|
|
94
|
-
(0, globals_1.expect)(resp.data).toBe(undefined);
|
|
95
|
-
(0, globals_1.expect)(resp.ok).toBe(false);
|
|
96
|
-
(0, globals_1.expect)(resp.status).toBe(http_status_codes_1.StatusCodes.BAD_REQUEST);
|
|
97
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fileSystem.test.d.ts","sourceRoot":"","sources":["../src/fileSystem.test.ts"],"names":[],"mappings":""}
|
package/dist/fileSystem.test.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
// SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
|
|
4
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
-
if (k2 === undefined) k2 = k;
|
|
6
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
-
}
|
|
10
|
-
Object.defineProperty(o, k2, desc);
|
|
11
|
-
}) : (function(o, m, k, k2) {
|
|
12
|
-
if (k2 === undefined) k2 = k;
|
|
13
|
-
o[k2] = m[k];
|
|
14
|
-
}));
|
|
15
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
-
}) : function(o, v) {
|
|
18
|
-
o["default"] = v;
|
|
19
|
-
});
|
|
20
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
21
|
-
if (mod && mod.__esModule) return mod;
|
|
22
|
-
var result = {};
|
|
23
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
24
|
-
__setModuleDefault(result, mod);
|
|
25
|
-
return result;
|
|
26
|
-
};
|
|
27
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
const fs = __importStar(require("fs"));
|
|
29
|
-
const fileSystem_1 = require("./fileSystem");
|
|
30
|
-
const globals_1 = require("@jest/globals");
|
|
31
|
-
// Mock the fs module
|
|
32
|
-
globals_1.jest.mock("fs");
|
|
33
|
-
(0, globals_1.describe)("NodeFileSystem", () => {
|
|
34
|
-
let nodeFileSystem;
|
|
35
|
-
(0, globals_1.beforeEach)(() => {
|
|
36
|
-
nodeFileSystem = new fileSystem_1.NodeFileSystem();
|
|
37
|
-
globals_1.jest.clearAllMocks(); // Clear all mocks before each test
|
|
38
|
-
});
|
|
39
|
-
(0, globals_1.describe)("readFile", () => {
|
|
40
|
-
(0, globals_1.test)("should call fs.readFileSync with correct arguments", () => {
|
|
41
|
-
const mockFilePath = "test-file.txt";
|
|
42
|
-
const mockFileContent = "This is a test file";
|
|
43
|
-
// Mock the fs.readFileSync method to return the mock file content
|
|
44
|
-
fs.readFileSync.mockReturnValue(mockFileContent);
|
|
45
|
-
const result = nodeFileSystem.readFile(mockFilePath);
|
|
46
|
-
// Assert that fs.readFileSync was called with the correct file path and encoding
|
|
47
|
-
(0, globals_1.expect)(fs.readFileSync).toHaveBeenCalledWith(mockFilePath, "utf8");
|
|
48
|
-
// Assert that the returned content matches the mock file content
|
|
49
|
-
(0, globals_1.expect)(result).toBe(mockFileContent);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
(0, globals_1.describe)("writeFile", () => {
|
|
53
|
-
(0, globals_1.test)("should call fs.writeFileSync with correct arguments", () => {
|
|
54
|
-
const mockFilePath = "test-file.txt";
|
|
55
|
-
const mockFileContent = "This is a test file";
|
|
56
|
-
// Call the writeFile method
|
|
57
|
-
nodeFileSystem.writeFile(mockFilePath, mockFileContent);
|
|
58
|
-
// Assert that fs.writeFileSync was called with the correct arguments
|
|
59
|
-
(0, globals_1.expect)(fs.writeFileSync).toHaveBeenCalledWith(mockFilePath, mockFileContent, "utf8");
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
(0, globals_1.describe)("readdirSync", () => {
|
|
63
|
-
(0, globals_1.test)("should call fs.readdirSync with correct arguments and return file list", () => {
|
|
64
|
-
const mockDirectoryPath = "test-directory";
|
|
65
|
-
const mockFileList = ["file1.txt", "file2.txt"];
|
|
66
|
-
// Mock the fs.readdirSync method to return the mock file list
|
|
67
|
-
fs.readdirSync.mockReturnValue(mockFileList);
|
|
68
|
-
const result = nodeFileSystem.readdirSync(mockDirectoryPath);
|
|
69
|
-
// Assert that fs.readdirSync was called with the correct directory path
|
|
70
|
-
(0, globals_1.expect)(fs.readdirSync).toHaveBeenCalledWith(mockDirectoryPath);
|
|
71
|
-
// Assert that the returned file list matches the mock file list
|
|
72
|
-
(0, globals_1.expect)(result).toEqual(mockFileList);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http2-watch.spec.d.ts","sourceRoot":"","sources":["../../src/fluent/http2-watch.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
|
-
const globals_1 = require("@jest/globals");
|
|
8
|
-
const http2_1 = __importDefault(require("http2"));
|
|
9
|
-
const __1 = require("..");
|
|
10
|
-
const types_1 = require("./types");
|
|
11
|
-
const _1 = require(".");
|
|
12
|
-
globals_1.jest.mock("http2");
|
|
13
|
-
(0, globals_1.describe)("Watcher HTTP2", () => {
|
|
14
|
-
let watcher;
|
|
15
|
-
let mockClient;
|
|
16
|
-
let mockReq;
|
|
17
|
-
const evtMock = globals_1.jest.fn();
|
|
18
|
-
const errMock = globals_1.jest.fn();
|
|
19
|
-
const setupAndStartWatcher = (eventType, handler) => {
|
|
20
|
-
watcher.events.on(eventType, handler);
|
|
21
|
-
watcher.start().catch(errMock);
|
|
22
|
-
};
|
|
23
|
-
(0, globals_1.beforeEach)(() => {
|
|
24
|
-
globals_1.jest.clearAllMocks();
|
|
25
|
-
// http2.client
|
|
26
|
-
mockClient = {
|
|
27
|
-
request: globals_1.jest.fn(),
|
|
28
|
-
close: globals_1.jest.fn(),
|
|
29
|
-
on: globals_1.jest.fn(),
|
|
30
|
-
destroy: globals_1.jest.fn(),
|
|
31
|
-
};
|
|
32
|
-
// http2.request stream
|
|
33
|
-
mockReq = {
|
|
34
|
-
on: globals_1.jest.fn(),
|
|
35
|
-
end: globals_1.jest.fn(),
|
|
36
|
-
setEncoding: globals_1.jest.fn(),
|
|
37
|
-
};
|
|
38
|
-
// http2.connect function to return the mocked client session
|
|
39
|
-
http2_1.default.connect.mockReturnValue(mockClient);
|
|
40
|
-
});
|
|
41
|
-
(0, globals_1.afterEach)(() => {
|
|
42
|
-
watcher.close();
|
|
43
|
-
});
|
|
44
|
-
(0, globals_1.it)("should watch named resources", done => {
|
|
45
|
-
const pod = createMockPod("pod-1", "1");
|
|
46
|
-
const response = { type: "ADDED", object: pod };
|
|
47
|
-
watcher = (0, _1.K8s)(__1.kind.Pod).Watch(evtMock, {
|
|
48
|
-
useHTTP2: true,
|
|
49
|
-
});
|
|
50
|
-
mockReq.on.mockImplementation((event, callback) => {
|
|
51
|
-
switch (event) {
|
|
52
|
-
case "response":
|
|
53
|
-
callback({ ":status": 200 }, 0);
|
|
54
|
-
break;
|
|
55
|
-
case "data":
|
|
56
|
-
setTimeout(() => {
|
|
57
|
-
callback(Buffer.from(JSON.stringify(response)));
|
|
58
|
-
}, 10);
|
|
59
|
-
break;
|
|
60
|
-
case "end":
|
|
61
|
-
setTimeout(() => {
|
|
62
|
-
callback();
|
|
63
|
-
done();
|
|
64
|
-
}, 20);
|
|
65
|
-
break;
|
|
66
|
-
case "error":
|
|
67
|
-
errMock(new Error("HTTP2 connection error"));
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
return mockReq;
|
|
71
|
-
});
|
|
72
|
-
mockClient.request.mockReturnValue(mockReq);
|
|
73
|
-
setupAndStartWatcher(__1.WatchEvent.CONNECT, () => {
|
|
74
|
-
setupAndStartWatcher(__1.WatchEvent.DATA, (receivedPod, phase) => {
|
|
75
|
-
(0, globals_1.expect)(receivedPod.metadata?.name).toBe("pod-1");
|
|
76
|
-
(0, globals_1.expect)(receivedPod.metadata?.resourceVersion).toBe("1");
|
|
77
|
-
(0, globals_1.expect)(phase).toBe(types_1.WatchPhase.Added);
|
|
78
|
-
done();
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
(0, globals_1.it)("should handle resource version is too old", done => {
|
|
83
|
-
const errorResponse = {
|
|
84
|
-
type: "ERROR",
|
|
85
|
-
object: {
|
|
86
|
-
kind: "Status",
|
|
87
|
-
apiVersion: "v1",
|
|
88
|
-
metadata: {},
|
|
89
|
-
status: "Failure",
|
|
90
|
-
message: "too old resource version: 123 (391079)",
|
|
91
|
-
reason: "Gone",
|
|
92
|
-
code: 410,
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
watcher = (0, _1.K8s)(__1.kind.Pod).Watch(evtMock, {
|
|
96
|
-
useHTTP2: true,
|
|
97
|
-
});
|
|
98
|
-
mockReq.on.mockImplementation((event, callback) => {
|
|
99
|
-
switch (event) {
|
|
100
|
-
case "response":
|
|
101
|
-
callback({ ":status": 200 }, 0);
|
|
102
|
-
break;
|
|
103
|
-
case "data":
|
|
104
|
-
setTimeout(() => {
|
|
105
|
-
callback(Buffer.from(JSON.stringify(errorResponse)));
|
|
106
|
-
}, 10);
|
|
107
|
-
break;
|
|
108
|
-
case "end":
|
|
109
|
-
setTimeout(() => {
|
|
110
|
-
callback();
|
|
111
|
-
done();
|
|
112
|
-
}, 20);
|
|
113
|
-
break;
|
|
114
|
-
case "error":
|
|
115
|
-
errMock(new Error("HTTP2 connection error"));
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
return mockReq;
|
|
119
|
-
});
|
|
120
|
-
mockClient.request.mockReturnValue(mockReq);
|
|
121
|
-
setupAndStartWatcher(__1.WatchEvent.OLD_RESOURCE_VERSION, res => {
|
|
122
|
-
(0, globals_1.expect)(res).toEqual("123");
|
|
123
|
-
done();
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
(0, globals_1.it)("should call the event handler for each event", done => {
|
|
127
|
-
const pod = createMockPod("pod-0", "1");
|
|
128
|
-
const response = { type: "ADDED", object: pod };
|
|
129
|
-
watcher = (0, _1.K8s)(__1.kind.Pod).Watch((evt, phase) => {
|
|
130
|
-
(0, globals_1.expect)(evt.metadata?.name).toEqual("pod-0");
|
|
131
|
-
(0, globals_1.expect)(phase).toEqual(types_1.WatchPhase.Added);
|
|
132
|
-
}, { useHTTP2: true });
|
|
133
|
-
mockReq.on.mockImplementation((event, callback) => {
|
|
134
|
-
switch (event) {
|
|
135
|
-
case "response":
|
|
136
|
-
callback({ ":status": 200 }, 0);
|
|
137
|
-
break;
|
|
138
|
-
case "data":
|
|
139
|
-
setTimeout(() => {
|
|
140
|
-
callback(Buffer.from(JSON.stringify(response)));
|
|
141
|
-
}, 10);
|
|
142
|
-
break;
|
|
143
|
-
case "end":
|
|
144
|
-
setTimeout(() => {
|
|
145
|
-
callback();
|
|
146
|
-
}, 20);
|
|
147
|
-
break;
|
|
148
|
-
case "error":
|
|
149
|
-
errMock(new Error("HTTP2 connection error"));
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
return mockReq;
|
|
153
|
-
});
|
|
154
|
-
mockClient.request.mockReturnValue(mockReq);
|
|
155
|
-
watcher.start().catch(errMock);
|
|
156
|
-
done();
|
|
157
|
-
});
|
|
158
|
-
(0, globals_1.it)("should return the cache id", () => {
|
|
159
|
-
watcher = (0, _1.K8s)(__1.kind.Pod).Watch(evtMock, {
|
|
160
|
-
resyncDelaySec: 1,
|
|
161
|
-
useHTTP2: true,
|
|
162
|
-
});
|
|
163
|
-
(0, globals_1.expect)(watcher.getCacheID()).toEqual("d69b75a611");
|
|
164
|
-
});
|
|
165
|
-
(0, globals_1.it)("should handle the CONNECT event", done => {
|
|
166
|
-
watcher = (0, _1.K8s)(__1.kind.Pod).Watch(evtMock, {
|
|
167
|
-
resyncDelaySec: 1,
|
|
168
|
-
useHTTP2: true,
|
|
169
|
-
});
|
|
170
|
-
setupAndStartWatcher(__1.WatchEvent.CONNECT, () => { });
|
|
171
|
-
done();
|
|
172
|
-
});
|
|
173
|
-
(0, globals_1.it)("should handle the DATA event", done => {
|
|
174
|
-
watcher = (0, _1.K8s)(__1.kind.Pod).Watch(evtMock, {
|
|
175
|
-
resyncDelaySec: 1,
|
|
176
|
-
useHTTP2: true,
|
|
177
|
-
});
|
|
178
|
-
setupAndStartWatcher(__1.WatchEvent.DATA, (pod, phase) => {
|
|
179
|
-
(0, globals_1.expect)(pod.metadata?.name).toEqual("pod-0");
|
|
180
|
-
(0, globals_1.expect)(phase).toEqual(types_1.WatchPhase.Added);
|
|
181
|
-
});
|
|
182
|
-
done();
|
|
183
|
-
});
|
|
184
|
-
(0, globals_1.it)("should handle the NETWORK_ERROR event", done => {
|
|
185
|
-
const errorMessage = "Something bad happened";
|
|
186
|
-
watcher = (0, _1.K8s)(__1.kind.Pod).Watch(evtMock, {
|
|
187
|
-
useHTTP2: true,
|
|
188
|
-
resyncDelaySec: 1,
|
|
189
|
-
});
|
|
190
|
-
mockReq.on.mockImplementation((event, callback) => {
|
|
191
|
-
if (event === "response") {
|
|
192
|
-
callback({ ":status": 200 }, 0);
|
|
193
|
-
}
|
|
194
|
-
else if (event === "error") {
|
|
195
|
-
callback(new Error(errorMessage));
|
|
196
|
-
}
|
|
197
|
-
return mockReq;
|
|
198
|
-
});
|
|
199
|
-
mockClient.request.mockReturnValue(mockReq);
|
|
200
|
-
setupAndStartWatcher(__1.WatchEvent.NETWORK_ERROR, error => {
|
|
201
|
-
(0, globals_1.expect)(error.message).toEqual(errorMessage);
|
|
202
|
-
});
|
|
203
|
-
watcher.start().catch(errMock);
|
|
204
|
-
done();
|
|
205
|
-
});
|
|
206
|
-
(0, globals_1.it)("should handle the RECONNECT event on an error", done => {
|
|
207
|
-
const errorMessage = "Something bad happened";
|
|
208
|
-
watcher = (0, _1.K8s)(__1.kind.Pod).Watch(evtMock, {
|
|
209
|
-
useHTTP2: true,
|
|
210
|
-
resyncDelaySec: 0.01,
|
|
211
|
-
});
|
|
212
|
-
let reconnectCount = 0;
|
|
213
|
-
mockReq.on.mockImplementation((event, callback) => {
|
|
214
|
-
if (event === "response") {
|
|
215
|
-
callback({ ":status": 200 }, 0);
|
|
216
|
-
}
|
|
217
|
-
else if (event === "error") {
|
|
218
|
-
reconnectCount += 1;
|
|
219
|
-
callback(new Error(errorMessage));
|
|
220
|
-
}
|
|
221
|
-
return mockReq;
|
|
222
|
-
});
|
|
223
|
-
mockClient.request.mockReturnValue(mockReq);
|
|
224
|
-
setupAndStartWatcher(__1.WatchEvent.RECONNECT, count => {
|
|
225
|
-
(0, globals_1.expect)(count).toEqual(reconnectCount);
|
|
226
|
-
});
|
|
227
|
-
watcher.start().catch(errMock);
|
|
228
|
-
done();
|
|
229
|
-
});
|
|
230
|
-
(0, globals_1.it)("should perform a resync after the resync interval", done => {
|
|
231
|
-
watcher = (0, _1.K8s)(__1.kind.Pod).Watch(evtMock, {
|
|
232
|
-
useHTTP2: true,
|
|
233
|
-
resyncDelaySec: 1,
|
|
234
|
-
});
|
|
235
|
-
watcher.start().catch(errMock);
|
|
236
|
-
done();
|
|
237
|
-
});
|
|
238
|
-
(0, globals_1.it)("should handle the GIVE_UP event", done => {
|
|
239
|
-
watcher = (0, _1.K8s)(__1.kind.Pod).Watch(evtMock, {
|
|
240
|
-
useHTTP2: true,
|
|
241
|
-
lastSeenLimitSeconds: 0.01,
|
|
242
|
-
resyncDelaySec: 0.01,
|
|
243
|
-
resyncFailureMax: 1,
|
|
244
|
-
});
|
|
245
|
-
setupAndStartWatcher(__1.WatchEvent.GIVE_UP, () => {
|
|
246
|
-
(0, globals_1.expect)(errMock).toBeCalled();
|
|
247
|
-
});
|
|
248
|
-
watcher.start().catch(errMock);
|
|
249
|
-
done();
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
/**
|
|
253
|
-
* Creates a mock pod object
|
|
254
|
-
*
|
|
255
|
-
* @param name The name of the pod
|
|
256
|
-
* @param resourceVersion The resource version of the pod
|
|
257
|
-
* @returns A mock pod object
|
|
258
|
-
*/
|
|
259
|
-
function createMockPod(name, resourceVersion) {
|
|
260
|
-
return {
|
|
261
|
-
kind: "Pod",
|
|
262
|
-
apiVersion: "v1",
|
|
263
|
-
metadata: {
|
|
264
|
-
name,
|
|
265
|
-
resourceVersion,
|
|
266
|
-
uid: "abc-123-xyz",
|
|
267
|
-
},
|
|
268
|
-
spec: {
|
|
269
|
-
containers: [
|
|
270
|
-
{
|
|
271
|
-
name: "nginx",
|
|
272
|
-
image: "nginx:1.14.2",
|
|
273
|
-
ports: [
|
|
274
|
-
{
|
|
275
|
-
containerPort: 80,
|
|
276
|
-
protocol: "TCP",
|
|
277
|
-
},
|
|
278
|
-
],
|
|
279
|
-
},
|
|
280
|
-
],
|
|
281
|
-
},
|
|
282
|
-
status: {},
|
|
283
|
-
};
|
|
284
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../src/fluent/index.test.ts"],"names":[],"mappings":""}
|