kubernetes-fluent-client 1.10.0 → 2.0.1
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/README.md +5 -3
- package/dist/fluent/index.d.ts +1 -1
- package/dist/fluent/index.d.ts.map +1 -1
- package/dist/fluent/index.js +2 -2
- package/dist/fluent/types.d.ts +11 -9
- package/dist/fluent/types.d.ts.map +1 -1
- package/dist/fluent/types.js +2 -0
- package/dist/fluent/watch.d.ts +78 -35
- package/dist/fluent/watch.d.ts.map +1 -1
- package/dist/fluent/watch.js +289 -107
- package/dist/fluent/watch.spec.d.ts +2 -0
- package/dist/fluent/watch.spec.d.ts.map +1 -0
- package/dist/fluent/watch.spec.js +235 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/package.json +5 -5
- package/src/fluent/index.ts +4 -4
- package/src/fluent/types.ts +13 -11
- package/src/fluent/watch.spec.ts +281 -0
- package/src/fluent/watch.ts +319 -150
- package/src/index.ts +3 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const globals_1 = require("@jest/globals");
|
|
8
|
+
const nock_1 = __importDefault(require("nock"));
|
|
9
|
+
const readable_stream_1 = require("readable-stream");
|
|
10
|
+
const _1 = require(".");
|
|
11
|
+
const __1 = require("..");
|
|
12
|
+
const types_1 = require("./types");
|
|
13
|
+
(0, globals_1.describe)("Watcher", () => {
|
|
14
|
+
const evtMock = globals_1.jest.fn();
|
|
15
|
+
const errMock = globals_1.jest.fn();
|
|
16
|
+
const setupAndStartWatcher = (eventType, handler) => {
|
|
17
|
+
watcher.events.on(eventType, handler);
|
|
18
|
+
watcher.start().catch(errMock);
|
|
19
|
+
};
|
|
20
|
+
let watcher;
|
|
21
|
+
(0, globals_1.beforeEach)(() => {
|
|
22
|
+
globals_1.jest.resetAllMocks();
|
|
23
|
+
watcher = (0, _1.K8s)(__1.kind.Pod).Watch(evtMock, {
|
|
24
|
+
retryDelaySec: 1,
|
|
25
|
+
});
|
|
26
|
+
(0, nock_1.default)("http://jest-test:8080")
|
|
27
|
+
.get("/api/v1/pods")
|
|
28
|
+
.query({ watch: "true", allowWatchBookmarks: "true" })
|
|
29
|
+
.reply(200, () => {
|
|
30
|
+
const stream = new readable_stream_1.PassThrough();
|
|
31
|
+
const resources = [
|
|
32
|
+
{ type: "ADDED", object: createMockPod(`pod-0`, `1`) },
|
|
33
|
+
{ type: "BOOKMARK", object: { metadata: { resourceVersion: "1" } } },
|
|
34
|
+
{ type: "MODIFIED", object: createMockPod(`pod-0`, `2`) },
|
|
35
|
+
];
|
|
36
|
+
resources.forEach(resource => {
|
|
37
|
+
stream.write(JSON.stringify(resource) + "\n");
|
|
38
|
+
});
|
|
39
|
+
stream.end();
|
|
40
|
+
return stream;
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
(0, globals_1.afterEach)(() => {
|
|
44
|
+
watcher.close();
|
|
45
|
+
});
|
|
46
|
+
(0, globals_1.it)("should watch named resources", done => {
|
|
47
|
+
nock_1.default.cleanAll();
|
|
48
|
+
(0, nock_1.default)("http://jest-test:8080")
|
|
49
|
+
.get("/api/v1/namespaces/tester/pods")
|
|
50
|
+
.query({ watch: "true", allowWatchBookmarks: "true", fieldSelector: "metadata.name=demo" })
|
|
51
|
+
.reply(200);
|
|
52
|
+
watcher = (0, _1.K8s)(__1.kind.Pod, { name: "demo" }).InNamespace("tester").Watch(evtMock);
|
|
53
|
+
setupAndStartWatcher(__1.WatchEvent.CONNECT, () => {
|
|
54
|
+
done();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
(0, globals_1.it)("should start the watch at the specified resource version", done => {
|
|
58
|
+
nock_1.default.cleanAll();
|
|
59
|
+
(0, nock_1.default)("http://jest-test:8080")
|
|
60
|
+
.get("/api/v1/pods")
|
|
61
|
+
.query({
|
|
62
|
+
watch: "true",
|
|
63
|
+
allowWatchBookmarks: "true",
|
|
64
|
+
resourceVersion: "25",
|
|
65
|
+
})
|
|
66
|
+
.reply(200);
|
|
67
|
+
watcher = (0, _1.K8s)(__1.kind.Pod).Watch(evtMock, {
|
|
68
|
+
resourceVersion: "25",
|
|
69
|
+
});
|
|
70
|
+
setupAndStartWatcher(__1.WatchEvent.CONNECT, () => {
|
|
71
|
+
done();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
(0, globals_1.it)("should handle resource version is too old", done => {
|
|
75
|
+
nock_1.default.cleanAll();
|
|
76
|
+
(0, nock_1.default)("http://jest-test:8080")
|
|
77
|
+
.get("/api/v1/pods")
|
|
78
|
+
.query({ watch: "true", allowWatchBookmarks: "true", resourceVersion: "45" })
|
|
79
|
+
.reply(200, () => {
|
|
80
|
+
const stream = new readable_stream_1.PassThrough();
|
|
81
|
+
stream.write(JSON.stringify({
|
|
82
|
+
type: "ERROR",
|
|
83
|
+
object: {
|
|
84
|
+
kind: "Status",
|
|
85
|
+
apiVersion: "v1",
|
|
86
|
+
metadata: {},
|
|
87
|
+
status: "Failure",
|
|
88
|
+
message: "too old resource version: 123 (391079)",
|
|
89
|
+
reason: "Gone",
|
|
90
|
+
code: 410,
|
|
91
|
+
},
|
|
92
|
+
}) + "\n");
|
|
93
|
+
stream.end();
|
|
94
|
+
return stream;
|
|
95
|
+
});
|
|
96
|
+
watcher = (0, _1.K8s)(__1.kind.Pod).Watch(evtMock, {
|
|
97
|
+
resourceVersion: "45",
|
|
98
|
+
});
|
|
99
|
+
setupAndStartWatcher(__1.WatchEvent.OLD_RESOURCE_VERSION, res => {
|
|
100
|
+
(0, globals_1.expect)(res).toEqual("45");
|
|
101
|
+
done();
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
(0, globals_1.it)("should call the event handler for each event", done => {
|
|
105
|
+
watcher = (0, _1.K8s)(__1.kind.Pod).Watch((evt, phase) => {
|
|
106
|
+
(0, globals_1.expect)(evt.metadata?.name).toEqual(`pod-0`);
|
|
107
|
+
(0, globals_1.expect)(phase).toEqual(types_1.WatchPhase.Added);
|
|
108
|
+
done();
|
|
109
|
+
});
|
|
110
|
+
watcher.start().catch(errMock);
|
|
111
|
+
});
|
|
112
|
+
(0, globals_1.it)("should return the cache id", () => {
|
|
113
|
+
(0, globals_1.expect)(watcher.getCacheID()).toEqual("d69b75a611");
|
|
114
|
+
});
|
|
115
|
+
(0, globals_1.it)("should use an updated resourceVersion", done => {
|
|
116
|
+
nock_1.default.cleanAll();
|
|
117
|
+
(0, nock_1.default)("http://jest-test:8080")
|
|
118
|
+
.get("/api/v1/pods")
|
|
119
|
+
.query({
|
|
120
|
+
watch: "true",
|
|
121
|
+
allowWatchBookmarks: "true",
|
|
122
|
+
resourceVersion: "35",
|
|
123
|
+
})
|
|
124
|
+
.reply(200);
|
|
125
|
+
// Update the resource version, could be combined with getCacheID to store the value
|
|
126
|
+
watcher.resourceVersion = "35";
|
|
127
|
+
setupAndStartWatcher(__1.WatchEvent.CONNECT, () => {
|
|
128
|
+
done();
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
(0, globals_1.it)("should handle the CONNECT event", done => {
|
|
132
|
+
setupAndStartWatcher(__1.WatchEvent.CONNECT, () => {
|
|
133
|
+
done();
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
(0, globals_1.it)("should handle the DATA event", done => {
|
|
137
|
+
setupAndStartWatcher(__1.WatchEvent.DATA, (pod, phase) => {
|
|
138
|
+
(0, globals_1.expect)(pod.metadata?.name).toEqual(`pod-0`);
|
|
139
|
+
(0, globals_1.expect)(phase).toEqual(types_1.WatchPhase.Added);
|
|
140
|
+
done();
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
(0, globals_1.it)("should handle the BOOKMARK event", done => {
|
|
144
|
+
setupAndStartWatcher(__1.WatchEvent.BOOKMARK, bookmark => {
|
|
145
|
+
(0, globals_1.expect)(bookmark.metadata?.resourceVersion).toEqual("1");
|
|
146
|
+
done();
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
(0, globals_1.it)("should handle the NETWORK_ERROR event", done => {
|
|
150
|
+
nock_1.default.cleanAll();
|
|
151
|
+
(0, nock_1.default)("http://jest-test:8080")
|
|
152
|
+
.get("/api/v1/pods")
|
|
153
|
+
.query({ watch: "true", allowWatchBookmarks: "true" })
|
|
154
|
+
.replyWithError("Something bad happened");
|
|
155
|
+
setupAndStartWatcher(__1.WatchEvent.NETWORK_ERROR, error => {
|
|
156
|
+
(0, globals_1.expect)(error.message).toEqual("request to http://jest-test:8080/api/v1/pods?watch=true&allowWatchBookmarks=true failed, reason: Something bad happened");
|
|
157
|
+
done();
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
(0, globals_1.it)("should handle the RESOURCE_VERSION event", done => {
|
|
161
|
+
setupAndStartWatcher(__1.WatchEvent.RESOURCE_VERSION, resourceVersion => {
|
|
162
|
+
(0, globals_1.expect)(watcher.resourceVersion).toEqual("2");
|
|
163
|
+
(0, globals_1.expect)(resourceVersion).toEqual("2");
|
|
164
|
+
done();
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
(0, globals_1.it)("should handle the RECONNECT event", done => {
|
|
168
|
+
nock_1.default.cleanAll();
|
|
169
|
+
(0, nock_1.default)("http://jest-test:8080")
|
|
170
|
+
.get("/api/v1/pods")
|
|
171
|
+
.query({ watch: "true", allowWatchBookmarks: "true" })
|
|
172
|
+
.replyWithError("Something bad happened");
|
|
173
|
+
setupAndStartWatcher(__1.WatchEvent.RECONNECT, error => {
|
|
174
|
+
(0, globals_1.expect)(error.message).toEqual("request to http://jest-test:8080/api/v1/pods?watch=true&allowWatchBookmarks=true failed, reason: Something bad happened");
|
|
175
|
+
done();
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
(0, globals_1.it)("should perform a resync after the resync interval", done => {
|
|
179
|
+
watcher = (0, _1.K8s)(__1.kind.Pod).Watch(evtMock, {
|
|
180
|
+
resyncIntervalSec: 1,
|
|
181
|
+
});
|
|
182
|
+
setupAndStartWatcher(__1.WatchEvent.RESYNC, err => {
|
|
183
|
+
(0, globals_1.expect)(err.name).toEqual("Resync");
|
|
184
|
+
(0, globals_1.expect)(err.message).toEqual("Resync triggered by resyncIntervalSec");
|
|
185
|
+
done();
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
(0, globals_1.it)("should handle the GIVE_UP event", done => {
|
|
189
|
+
nock_1.default.cleanAll();
|
|
190
|
+
(0, nock_1.default)("http://jest-test:8080");
|
|
191
|
+
watcher = (0, _1.K8s)(__1.kind.Pod).Watch(evtMock, {
|
|
192
|
+
retryMax: 1,
|
|
193
|
+
retryDelaySec: 1,
|
|
194
|
+
});
|
|
195
|
+
setupAndStartWatcher(__1.WatchEvent.GIVE_UP, error => {
|
|
196
|
+
(0, globals_1.expect)(error.message).toContain("request to http://jest-test:8080/api/v1/pods?watch=true&allowWatchBookmarks=true failed");
|
|
197
|
+
done();
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
/**
|
|
202
|
+
* Creates a mock pod object
|
|
203
|
+
*
|
|
204
|
+
* @param name The name of the pod
|
|
205
|
+
* @param resourceVersion The resource version of the pod
|
|
206
|
+
* @returns A mock pod object
|
|
207
|
+
*/
|
|
208
|
+
function createMockPod(name, resourceVersion) {
|
|
209
|
+
return {
|
|
210
|
+
kind: "Pod",
|
|
211
|
+
apiVersion: "v1",
|
|
212
|
+
metadata: {
|
|
213
|
+
name: name,
|
|
214
|
+
resourceVersion: resourceVersion,
|
|
215
|
+
// ... other metadata fields
|
|
216
|
+
},
|
|
217
|
+
spec: {
|
|
218
|
+
containers: [
|
|
219
|
+
{
|
|
220
|
+
name: "nginx",
|
|
221
|
+
image: "nginx:1.14.2",
|
|
222
|
+
ports: [
|
|
223
|
+
{
|
|
224
|
+
containerPort: 80,
|
|
225
|
+
protocol: "TCP",
|
|
226
|
+
},
|
|
227
|
+
],
|
|
228
|
+
},
|
|
229
|
+
],
|
|
230
|
+
},
|
|
231
|
+
status: {
|
|
232
|
+
// ... pod status
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import * as kind from "./upstream";
|
|
|
4
4
|
export { kind };
|
|
5
5
|
export { fetch } from "./fetch";
|
|
6
6
|
export { StatusCodes as fetchStatus } from "http-status-codes";
|
|
7
|
+
export { WatchCfg, WatchEvent } from "./fluent/watch";
|
|
7
8
|
export { K8s } from "./fluent";
|
|
8
9
|
export { RegisterKind, modelToGroupVersionKind } from "./kinds";
|
|
9
10
|
export { GenericKind } from "./types";
|
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,SAAS,CAAC;AAGjB,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AAEnC,oGAAoG;AACpG,OAAO,EAAE,IAAI,EAAE,CAAC;AAGhB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAGhC,OAAO,EAAE,WAAW,IAAI,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAG/D,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAG/B,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAGhE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,cAAc,SAAS,CAAC;AAGxB,OAAO,KAAK,MAAM,MAAM,6CAA6C,CAAC;AAEtE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,SAAS,CAAC;AAGjB,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AAEnC,oGAAoG;AACpG,OAAO,EAAE,IAAI,EAAE,CAAC;AAGhB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAGhC,OAAO,EAAE,WAAW,IAAI,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAG/D,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGtD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAG/B,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAGhE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,cAAc,SAAS,CAAC;AAGxB,OAAO,KAAK,MAAM,MAAM,6CAA6C,CAAC;AAEtE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -28,7 +28,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
28
28
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
29
29
|
};
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.waitForCluster = exports.fromEnv = exports.models = exports.GenericKind = exports.modelToGroupVersionKind = exports.RegisterKind = exports.K8s = exports.fetchStatus = exports.fetch = exports.kind = void 0;
|
|
31
|
+
exports.waitForCluster = exports.fromEnv = exports.models = exports.GenericKind = exports.modelToGroupVersionKind = exports.RegisterKind = exports.K8s = exports.WatchEvent = exports.fetchStatus = exports.fetch = exports.kind = void 0;
|
|
32
32
|
require("./patch");
|
|
33
33
|
// Export kinds as a single object
|
|
34
34
|
const kind = __importStar(require("./upstream"));
|
|
@@ -39,6 +39,9 @@ Object.defineProperty(exports, "fetch", { enumerable: true, get: function () { r
|
|
|
39
39
|
// Export the HTTP status codes
|
|
40
40
|
var http_status_codes_1 = require("http-status-codes");
|
|
41
41
|
Object.defineProperty(exports, "fetchStatus", { enumerable: true, get: function () { return http_status_codes_1.StatusCodes; } });
|
|
42
|
+
// Export the Watch Config and Event types
|
|
43
|
+
var watch_1 = require("./fluent/watch");
|
|
44
|
+
Object.defineProperty(exports, "WatchEvent", { enumerable: true, get: function () { return watch_1.WatchEvent; } });
|
|
42
45
|
// Export the fluent API entrypoint
|
|
43
46
|
var fluent_1 = require("./fluent");
|
|
44
47
|
Object.defineProperty(exports, "K8s", { enumerable: true, get: function () { return fluent_1.K8s; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kubernetes-fluent-client",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
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",
|
|
@@ -35,13 +35,13 @@
|
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://github.com/defenseunicorns/kubernetes-fluent-client#readme",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@kubernetes/client-node": "1.0.0-
|
|
38
|
+
"@kubernetes/client-node": "1.0.0-rc4",
|
|
39
39
|
"byline": "5.0.0",
|
|
40
40
|
"fast-json-patch": "3.1.1",
|
|
41
41
|
"http-status-codes": "2.3.0",
|
|
42
42
|
"node-fetch": "2.7.0",
|
|
43
43
|
"quicktype-core": "23.0.80",
|
|
44
|
-
"type-fest": "4.
|
|
44
|
+
"type-fest": "4.9.0",
|
|
45
45
|
"yargs": "17.7.2"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"@types/byline": "4.2.36",
|
|
52
52
|
"@types/readable-stream": "4.0.10",
|
|
53
53
|
"@types/yargs": "17.0.32",
|
|
54
|
-
"@typescript-eslint/eslint-plugin": "6.
|
|
55
|
-
"@typescript-eslint/parser": "6.
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "6.16.0",
|
|
55
|
+
"@typescript-eslint/parser": "6.16.0",
|
|
56
56
|
"eslint-plugin-jsdoc": "46.9.1",
|
|
57
57
|
"jest": "29.7.0",
|
|
58
58
|
"nock": "13.4.0",
|
package/src/fluent/index.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { GenericClass } from "../types";
|
|
|
12
12
|
import { ApplyCfg } from "./apply";
|
|
13
13
|
import { Filters, K8sInit, Paths, WatchAction } from "./types";
|
|
14
14
|
import { k8sCfg, k8sExec } from "./utils";
|
|
15
|
-
import {
|
|
15
|
+
import { WatchCfg, Watcher } from "./watch";
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Kubernetes fluent API inspired by Kubectl. Pass in a model, then call filters and actions on it.
|
|
@@ -24,7 +24,7 @@ import { ExecWatch, WatchCfg } from "./watch";
|
|
|
24
24
|
export function K8s<T extends GenericClass, K extends KubernetesObject = InstanceType<T>>(
|
|
25
25
|
model: T,
|
|
26
26
|
filters: Filters = {},
|
|
27
|
-
): K8sInit<K> {
|
|
27
|
+
): K8sInit<T, K> {
|
|
28
28
|
const withFilters = { WithField, WithLabel, Get, Delete, Watch };
|
|
29
29
|
const matchedKind = filters.kindOverride || modelToGroupVersionKind(model.name);
|
|
30
30
|
|
|
@@ -166,8 +166,8 @@ export function K8s<T extends GenericClass, K extends KubernetesObject = Instanc
|
|
|
166
166
|
* @inheritdoc
|
|
167
167
|
* @see {@link K8sInit.Watch}
|
|
168
168
|
*/
|
|
169
|
-
|
|
170
|
-
return
|
|
169
|
+
function Watch(callback: WatchAction<T>, watchCfg?: WatchCfg) {
|
|
170
|
+
return new Watcher(model, filters, callback, watchCfg);
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
/**
|
package/src/fluent/types.ts
CHANGED
|
@@ -6,8 +6,8 @@ import { Operation } from "fast-json-patch";
|
|
|
6
6
|
import type { PartialDeep } from "type-fest";
|
|
7
7
|
|
|
8
8
|
import { GenericClass, GroupVersionKind } from "../types";
|
|
9
|
-
import { WatchCfg, WatchController } from "./watch";
|
|
10
9
|
import { ApplyCfg } from "./apply";
|
|
10
|
+
import { WatchCfg, Watcher } from "./watch";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* The Phase matched when using the K8s Watch API.
|
|
@@ -16,6 +16,8 @@ export enum WatchPhase {
|
|
|
16
16
|
Added = "ADDED",
|
|
17
17
|
Modified = "MODIFIED",
|
|
18
18
|
Deleted = "DELETED",
|
|
19
|
+
Bookmark = "BOOKMARK",
|
|
20
|
+
Error = "ERROR",
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
export type FetchMethods = "GET" | "APPLY" | "POST" | "PUT" | "DELETE" | "PATCH" | "WATCH";
|
|
@@ -41,7 +43,7 @@ export type GetFunction<K extends KubernetesObject> = {
|
|
|
41
43
|
(name: string): Promise<K>;
|
|
42
44
|
};
|
|
43
45
|
|
|
44
|
-
export type K8sFilteredActions<K extends KubernetesObject> = {
|
|
46
|
+
export type K8sFilteredActions<T extends GenericClass, K extends KubernetesObject> = {
|
|
45
47
|
/**
|
|
46
48
|
* Get the resource or resources matching the filters.
|
|
47
49
|
* If no filters are specified, all resources will be returned.
|
|
@@ -63,10 +65,7 @@ export type K8sFilteredActions<K extends KubernetesObject> = {
|
|
|
63
65
|
* @param watchCfg - (optional) watch configuration
|
|
64
66
|
* @returns a watch controller
|
|
65
67
|
*/
|
|
66
|
-
Watch: (
|
|
67
|
-
callback: (payload: K, phase: WatchPhase) => void,
|
|
68
|
-
watchCfg?: WatchCfg,
|
|
69
|
-
) => Promise<WatchController>;
|
|
68
|
+
Watch: (callback: WatchAction<T>, watchCfg?: WatchCfg) => Watcher<T>;
|
|
70
69
|
};
|
|
71
70
|
|
|
72
71
|
export type K8sUnfilteredActions<K extends KubernetesObject> = {
|
|
@@ -117,7 +116,10 @@ export type K8sUnfilteredActions<K extends KubernetesObject> = {
|
|
|
117
116
|
Raw: (url: string) => Promise<K>;
|
|
118
117
|
};
|
|
119
118
|
|
|
120
|
-
export type K8sWithFilters<K extends KubernetesObject> = K8sFilteredActions<
|
|
119
|
+
export type K8sWithFilters<T extends GenericClass, K extends KubernetesObject> = K8sFilteredActions<
|
|
120
|
+
T,
|
|
121
|
+
K
|
|
122
|
+
> & {
|
|
121
123
|
/**
|
|
122
124
|
* Filter the query by the given field.
|
|
123
125
|
* Note multiple calls to this method will result in an AND condition. e.g.
|
|
@@ -137,7 +139,7 @@ export type K8sWithFilters<K extends KubernetesObject> = K8sFilteredActions<K> &
|
|
|
137
139
|
* @param value - the field value
|
|
138
140
|
* @returns the fluent API
|
|
139
141
|
*/
|
|
140
|
-
WithField: <P extends Paths<K>>(key: P, value: string) => K8sWithFilters<K>;
|
|
142
|
+
WithField: <P extends Paths<K>>(key: P, value: string) => K8sWithFilters<T, K>;
|
|
141
143
|
|
|
142
144
|
/**
|
|
143
145
|
* Filter the query by the given label. If no value is specified, the label simply must exist.
|
|
@@ -157,10 +159,10 @@ export type K8sWithFilters<K extends KubernetesObject> = K8sFilteredActions<K> &
|
|
|
157
159
|
* @param value - the label value
|
|
158
160
|
* @returns the fluent API
|
|
159
161
|
*/
|
|
160
|
-
WithLabel: (key: string, value?: string) => K8sWithFilters<K>;
|
|
162
|
+
WithLabel: (key: string, value?: string) => K8sWithFilters<T, K>;
|
|
161
163
|
};
|
|
162
164
|
|
|
163
|
-
export type K8sInit<K extends KubernetesObject> = K8sWithFilters<K> &
|
|
165
|
+
export type K8sInit<T extends GenericClass, K extends KubernetesObject> = K8sWithFilters<T, K> &
|
|
164
166
|
K8sUnfilteredActions<K> & {
|
|
165
167
|
/**
|
|
166
168
|
* Set the namespace filter.
|
|
@@ -168,7 +170,7 @@ export type K8sInit<K extends KubernetesObject> = K8sWithFilters<K> &
|
|
|
168
170
|
* @param namespace - the namespace to filter on
|
|
169
171
|
* @returns the fluent API
|
|
170
172
|
*/
|
|
171
|
-
InNamespace: (namespace: string) => K8sWithFilters<K>;
|
|
173
|
+
InNamespace: (namespace: string) => K8sWithFilters<T, K>;
|
|
172
174
|
};
|
|
173
175
|
|
|
174
176
|
export type WatchAction<T extends GenericClass, K extends KubernetesObject = InstanceType<T>> = (
|