kubernetes-fluent-client 3.5.6 → 3.6.0
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/cli.js +9 -16
- package/dist/fetch.js +5 -8
- package/dist/fluent/index.d.ts +2 -1
- package/dist/fluent/index.d.ts.map +1 -1
- package/dist/fluent/index.js +27 -29
- package/dist/fluent/shared-types.d.ts +49 -0
- package/dist/fluent/shared-types.d.ts.map +1 -0
- package/dist/fluent/shared-types.js +23 -0
- package/dist/fluent/types.d.ts +2 -37
- package/dist/fluent/types.d.ts.map +1 -1
- package/dist/fluent/types.js +1 -14
- package/dist/fluent/utils.d.ts +1 -1
- package/dist/fluent/utils.d.ts.map +1 -1
- package/dist/fluent/utils.js +25 -35
- package/dist/fluent/watch.d.ts +1 -8
- package/dist/fluent/watch.d.ts.map +1 -1
- package/dist/fluent/watch.js +23 -43
- package/dist/generate.js +22 -65
- package/dist/helpers.js +5 -10
- package/dist/index.js +13 -60
- package/dist/kinds.js +2 -7
- package/dist/normalization.d.ts +97 -0
- package/dist/normalization.d.ts.map +1 -0
- package/dist/normalization.js +152 -0
- package/dist/patch.js +1 -2
- package/dist/postProcessing.d.ts +6 -127
- package/dist/postProcessing.d.ts.map +1 -1
- package/dist/postProcessing.js +24 -279
- package/dist/types.d.ts +3 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -5
- package/dist/upstream.js +2 -53
- package/package.json +11 -8
- package/src/cli.ts +1 -3
- package/src/fluent/index.ts +12 -11
- package/src/fluent/shared-types.ts +55 -0
- package/src/fluent/types.ts +3 -54
- package/src/fluent/utils.ts +2 -2
- package/src/fluent/watch.ts +2 -21
- package/src/normalization.ts +181 -0
- package/src/postProcessing.ts +11 -239
- package/src/types.ts +3 -4
- package/dist/fileSystem.d.ts +0 -11
- package/dist/fileSystem.d.ts.map +0 -1
- package/dist/fileSystem.js +0 -52
- package/src/fileSystem.ts +0 -25
package/dist/cli.js
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
3
|
// SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const package_json_1 = require("../package.json");
|
|
13
|
-
const postProcessing_1 = require("./postProcessing");
|
|
14
|
-
const fileSystem_1 = require("./fileSystem"); // Import your new file system
|
|
15
|
-
void (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
16
|
-
.version("version", "Display version number", `kubernetes-fluent-client v${package_json_1.version}`)
|
|
4
|
+
import { hideBin } from "yargs/helpers";
|
|
5
|
+
import yargs from "yargs/yargs";
|
|
6
|
+
import { generate } from "./generate";
|
|
7
|
+
import { version } from "../package.json";
|
|
8
|
+
import { postProcessing } from "./postProcessing";
|
|
9
|
+
void yargs(hideBin(process.argv))
|
|
10
|
+
.version("version", "Display version number", `kubernetes-fluent-client v${version}`)
|
|
17
11
|
.alias("version", "V")
|
|
18
12
|
.command("crd [source] [directory]", "generate usable types from a K8s CRD", yargs => {
|
|
19
13
|
return yargs
|
|
@@ -49,16 +43,15 @@ void (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
|
49
43
|
// Pass the `post` flag to opts
|
|
50
44
|
opts.noPost = argv.noPost;
|
|
51
45
|
// Use NodeFileSystem as the file system for post-processing
|
|
52
|
-
const fileSystem = new fileSystem_1.NodeFileSystem(); // Create an instance of NodeFileSystem
|
|
53
46
|
if (!opts.noPost) {
|
|
54
47
|
console.log("\n✅ Post-processing has been enabled.\n");
|
|
55
48
|
}
|
|
56
49
|
try {
|
|
57
50
|
// Capture the results returned by generate
|
|
58
|
-
const allResults = await
|
|
51
|
+
const allResults = await generate(opts);
|
|
59
52
|
// If noPost is false, run post-processing
|
|
60
53
|
if (!opts.noPost) {
|
|
61
|
-
await
|
|
54
|
+
await postProcessing(allResults, opts); // Pass the file system to postProcessing
|
|
62
55
|
}
|
|
63
56
|
}
|
|
64
57
|
catch (e) {
|
package/dist/fetch.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
2
|
// SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const http_status_codes_1 = require("http-status-codes");
|
|
7
|
-
const undici_1 = require("undici");
|
|
3
|
+
import { StatusCodes } from "http-status-codes";
|
|
4
|
+
import { fetch as undiciFetch } from "undici";
|
|
8
5
|
/**
|
|
9
6
|
* Perform an async HTTP call and return the parsed JSON response, optionally
|
|
10
7
|
* as a specific type.
|
|
@@ -18,10 +15,10 @@ const undici_1 = require("undici");
|
|
|
18
15
|
* @param init Additional options for the request
|
|
19
16
|
* @returns The parsed JSON response
|
|
20
17
|
*/
|
|
21
|
-
async function fetch(url, init) {
|
|
18
|
+
export async function fetch(url, init) {
|
|
22
19
|
let data = undefined;
|
|
23
20
|
try {
|
|
24
|
-
const resp = await (
|
|
21
|
+
const resp = await undiciFetch(url, init);
|
|
25
22
|
const contentType = resp.headers.get("content-type") || "";
|
|
26
23
|
// Parse the response as JSON if the content type is JSON
|
|
27
24
|
if (contentType.includes("application/json")) {
|
|
@@ -39,7 +36,7 @@ async function fetch(url, init) {
|
|
|
39
36
|
};
|
|
40
37
|
}
|
|
41
38
|
catch (e) {
|
|
42
|
-
const status = parseInt(e?.code) ||
|
|
39
|
+
const status = parseInt(e?.code) || StatusCodes.BAD_REQUEST;
|
|
43
40
|
const statusText = e?.message || "Unknown error";
|
|
44
41
|
return {
|
|
45
42
|
data,
|
package/dist/fluent/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { KubernetesObject } from "@kubernetes/client-node";
|
|
2
2
|
import { GenericClass } from "../types";
|
|
3
|
-
import {
|
|
3
|
+
import { K8sInit } from "./types";
|
|
4
|
+
import { Filters } from "./shared-types";
|
|
4
5
|
/**
|
|
5
6
|
* Kubernetes fluent API inspired by Kubectl. Pass in a model, then call filters and actions on it.
|
|
6
7
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fluent/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAwB,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAOjF,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fluent/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAwB,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAOjF,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,OAAO,EAAS,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,OAAO,EAAuC,MAAM,gBAAgB,CAAC;AAK9E;;;;;;GAMG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,YAAY,EAAE,CAAC,SAAS,gBAAgB,GAAG,YAAY,CAAC,CAAC,CAAC,EACtF,KAAK,EAAE,CAAC,EACR,OAAO,GAAE,OAAY,GACpB,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAyRf"}
|
package/dist/fluent/index.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
2
|
// SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const upstream_1 = require("../upstream");
|
|
3
|
+
import { StatusCodes } from "http-status-codes";
|
|
4
|
+
import { fetch } from "../fetch";
|
|
5
|
+
import { modelToGroupVersionKind } from "../kinds";
|
|
6
|
+
import { FetchMethods } from "./shared-types";
|
|
7
|
+
import { k8sCfg, k8sExec } from "./utils";
|
|
8
|
+
import { Watcher } from "./watch";
|
|
9
|
+
import { hasLogs } from "../helpers";
|
|
10
|
+
import { Pod } from "../upstream";
|
|
13
11
|
/**
|
|
14
12
|
* Kubernetes fluent API inspired by Kubectl. Pass in a model, then call filters and actions on it.
|
|
15
13
|
*
|
|
@@ -17,9 +15,9 @@ const upstream_1 = require("../upstream");
|
|
|
17
15
|
* @param filters - (optional) filter overrides, can also be chained
|
|
18
16
|
* @returns a fluent API for the model
|
|
19
17
|
*/
|
|
20
|
-
function K8s(model, filters = {}) {
|
|
18
|
+
export function K8s(model, filters = {}) {
|
|
21
19
|
const withFilters = { WithField, WithLabel, Get, Delete, Evict, Watch, Logs };
|
|
22
|
-
const matchedKind = filters.kindOverride ||
|
|
20
|
+
const matchedKind = filters.kindOverride || modelToGroupVersionKind(model.name);
|
|
23
21
|
/**
|
|
24
22
|
* @inheritdoc
|
|
25
23
|
* @see {@link K8sInit.InNamespace}
|
|
@@ -90,11 +88,11 @@ function K8s(model, filters = {}) {
|
|
|
90
88
|
if (!namespace) {
|
|
91
89
|
throw new Error("Namespace must be defined");
|
|
92
90
|
}
|
|
93
|
-
if (!
|
|
91
|
+
if (!hasLogs(kind)) {
|
|
94
92
|
throw new Error("Kind must be Pod or have a selector");
|
|
95
93
|
}
|
|
96
94
|
try {
|
|
97
|
-
const object = await
|
|
95
|
+
const object = await k8sExec(model, filters, FetchMethods.GET);
|
|
98
96
|
if (kind !== "Pod") {
|
|
99
97
|
if (kind === "Service") {
|
|
100
98
|
const svc = object;
|
|
@@ -107,7 +105,7 @@ function K8s(model, filters = {}) {
|
|
|
107
105
|
const rs = object;
|
|
108
106
|
labels = rs.spec.selector.matchLabels ?? {};
|
|
109
107
|
}
|
|
110
|
-
const list = await K8s(
|
|
108
|
+
const list = await K8s(Pod, { namespace: filters.namespace, labels }).Get();
|
|
111
109
|
list.items.forEach(item => {
|
|
112
110
|
return podList.push(item);
|
|
113
111
|
});
|
|
@@ -120,7 +118,7 @@ function K8s(model, filters = {}) {
|
|
|
120
118
|
throw new Error(`Failed to get logs in KFC Logs function`);
|
|
121
119
|
}
|
|
122
120
|
const podModel = { ...model, name: "V1Pod" };
|
|
123
|
-
const logPromises = podList.map(po =>
|
|
121
|
+
const logPromises = podList.map(po => k8sExec(podModel, { ...filters, name: po.metadata.name }, FetchMethods.LOG));
|
|
124
122
|
const responses = await Promise.all(logPromises);
|
|
125
123
|
const combinedString = responses.reduce((accumulator, currentString, i) => {
|
|
126
124
|
const prefixedLines = currentString
|
|
@@ -144,7 +142,7 @@ function K8s(model, filters = {}) {
|
|
|
144
142
|
}
|
|
145
143
|
filters.name = name;
|
|
146
144
|
}
|
|
147
|
-
return
|
|
145
|
+
return k8sExec(model, filters, FetchMethods.GET);
|
|
148
146
|
}
|
|
149
147
|
/**
|
|
150
148
|
* @inheritdoc
|
|
@@ -159,11 +157,11 @@ function K8s(model, filters = {}) {
|
|
|
159
157
|
}
|
|
160
158
|
try {
|
|
161
159
|
// Try to delete the resource
|
|
162
|
-
await
|
|
160
|
+
await k8sExec(model, filters, FetchMethods.DELETE);
|
|
163
161
|
}
|
|
164
162
|
catch (e) {
|
|
165
163
|
// If the resource doesn't exist, ignore the error
|
|
166
|
-
if (e.status ===
|
|
164
|
+
if (e.status === StatusCodes.NOT_FOUND) {
|
|
167
165
|
return;
|
|
168
166
|
}
|
|
169
167
|
throw e;
|
|
@@ -175,7 +173,7 @@ function K8s(model, filters = {}) {
|
|
|
175
173
|
*/
|
|
176
174
|
async function Apply(resource, applyCfg = { force: false }) {
|
|
177
175
|
syncFilters(resource);
|
|
178
|
-
return
|
|
176
|
+
return k8sExec(model, filters, FetchMethods.APPLY, resource, applyCfg);
|
|
179
177
|
}
|
|
180
178
|
/**
|
|
181
179
|
* @inheritdoc
|
|
@@ -183,7 +181,7 @@ function K8s(model, filters = {}) {
|
|
|
183
181
|
*/
|
|
184
182
|
async function Create(resource) {
|
|
185
183
|
syncFilters(resource);
|
|
186
|
-
return
|
|
184
|
+
return k8sExec(model, filters, FetchMethods.POST, resource);
|
|
187
185
|
}
|
|
188
186
|
/**
|
|
189
187
|
* @inheritdoc
|
|
@@ -206,11 +204,11 @@ function K8s(model, filters = {}) {
|
|
|
206
204
|
},
|
|
207
205
|
};
|
|
208
206
|
// Try to evict the resource
|
|
209
|
-
await
|
|
207
|
+
await k8sExec(model, filters, FetchMethods.POST, evictionPayload);
|
|
210
208
|
}
|
|
211
209
|
catch (e) {
|
|
212
210
|
// If the resource doesn't exist, ignore the error
|
|
213
|
-
if (e.status ===
|
|
211
|
+
if (e.status === StatusCodes.NOT_FOUND) {
|
|
214
212
|
return;
|
|
215
213
|
}
|
|
216
214
|
throw e;
|
|
@@ -225,7 +223,7 @@ function K8s(model, filters = {}) {
|
|
|
225
223
|
if (payload.length < 1) {
|
|
226
224
|
throw new Error("No operations specified");
|
|
227
225
|
}
|
|
228
|
-
return
|
|
226
|
+
return k8sExec(model, filters, FetchMethods.PATCH, payload);
|
|
229
227
|
}
|
|
230
228
|
/**
|
|
231
229
|
* @inheritdoc
|
|
@@ -233,23 +231,23 @@ function K8s(model, filters = {}) {
|
|
|
233
231
|
*/
|
|
234
232
|
async function PatchStatus(resource) {
|
|
235
233
|
syncFilters(resource);
|
|
236
|
-
return
|
|
234
|
+
return k8sExec(model, filters, FetchMethods.PATCH_STATUS, resource);
|
|
237
235
|
}
|
|
238
236
|
/**
|
|
239
237
|
* @inheritdoc
|
|
240
238
|
* @see {@link K8sInit.Watch}
|
|
241
239
|
*/
|
|
242
240
|
function Watch(callback, watchCfg) {
|
|
243
|
-
return new
|
|
241
|
+
return new Watcher(model, filters, callback, watchCfg);
|
|
244
242
|
}
|
|
245
243
|
/**
|
|
246
244
|
* @inheritdoc
|
|
247
245
|
* @see {@link K8sInit.Raw}
|
|
248
246
|
*/
|
|
249
|
-
async function Raw(url, method =
|
|
250
|
-
const thing = await
|
|
247
|
+
async function Raw(url, method = FetchMethods.GET) {
|
|
248
|
+
const thing = await k8sCfg(method);
|
|
251
249
|
const { opts, serverUrl } = thing;
|
|
252
|
-
const resp = await
|
|
250
|
+
const resp = await fetch(`${serverUrl}${url}`, opts);
|
|
253
251
|
if (resp.ok) {
|
|
254
252
|
return resp.data;
|
|
255
253
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { GenericClass, GroupVersionKind } from "../types";
|
|
2
|
+
import { RequestInit } from "undici";
|
|
3
|
+
import { KubernetesObject } from "@kubernetes/client-node";
|
|
4
|
+
/**
|
|
5
|
+
* Fetch options and server URL
|
|
6
|
+
*/
|
|
7
|
+
export type K8sConfigPromise = Promise<{
|
|
8
|
+
opts: RequestInit;
|
|
9
|
+
serverUrl: string | URL;
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* The Phase matched when using the K8s Watch API.
|
|
13
|
+
*/
|
|
14
|
+
export declare enum WatchPhase {
|
|
15
|
+
Added = "ADDED",
|
|
16
|
+
Modified = "MODIFIED",
|
|
17
|
+
Deleted = "DELETED",
|
|
18
|
+
Bookmark = "BOOKMARK",
|
|
19
|
+
Error = "ERROR"
|
|
20
|
+
}
|
|
21
|
+
export type WatchAction<T extends GenericClass, K extends KubernetesObject = InstanceType<T>> = (update: K, phase: WatchPhase) => Promise<void> | void;
|
|
22
|
+
export interface Filters {
|
|
23
|
+
kindOverride?: GroupVersionKind;
|
|
24
|
+
fields?: Record<string, string>;
|
|
25
|
+
labels?: Record<string, string>;
|
|
26
|
+
name?: string;
|
|
27
|
+
namespace?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Configuration for the apply function.
|
|
31
|
+
*/
|
|
32
|
+
export type ApplyCfg = {
|
|
33
|
+
/**
|
|
34
|
+
* Force the apply to be a create.
|
|
35
|
+
*/
|
|
36
|
+
force?: boolean;
|
|
37
|
+
};
|
|
38
|
+
export declare enum FetchMethods {
|
|
39
|
+
APPLY = "APPLY",
|
|
40
|
+
DELETE = "DELETE",
|
|
41
|
+
GET = "GET",
|
|
42
|
+
LOG = "LOG",
|
|
43
|
+
PATCH = "PATCH",
|
|
44
|
+
PATCH_STATUS = "PATCH_STATUS",
|
|
45
|
+
POST = "POST",
|
|
46
|
+
PUT = "PUT",
|
|
47
|
+
WATCH = "WATCH"
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=shared-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-types.d.ts","sourceRoot":"","sources":["../../src/fluent/shared-types.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,SAAS,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,CAAC,CAAC;AAEvF;;GAEG;AACH,oBAAY,UAAU;IACpB,KAAK,UAAU;IACf,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,KAAK,UAAU;CAChB;AAED,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,YAAY,EAAE,CAAC,SAAS,gBAAgB,GAAG,YAAY,CAAC,CAAC,CAAC,IAAI,CAC9F,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,UAAU,KACd,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAE1B,MAAM,WAAW,OAAO;IACtB,YAAY,CAAC,EAAE,gBAAgB,CAAC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,oBAAY,YAAY;IACtB,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,KAAK,UAAU;IACf,YAAY,iBAAiB;IAC7B,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,KAAK,UAAU;CAChB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Phase matched when using the K8s Watch API.
|
|
3
|
+
*/
|
|
4
|
+
export var WatchPhase;
|
|
5
|
+
(function (WatchPhase) {
|
|
6
|
+
WatchPhase["Added"] = "ADDED";
|
|
7
|
+
WatchPhase["Modified"] = "MODIFIED";
|
|
8
|
+
WatchPhase["Deleted"] = "DELETED";
|
|
9
|
+
WatchPhase["Bookmark"] = "BOOKMARK";
|
|
10
|
+
WatchPhase["Error"] = "ERROR";
|
|
11
|
+
})(WatchPhase || (WatchPhase = {}));
|
|
12
|
+
export var FetchMethods;
|
|
13
|
+
(function (FetchMethods) {
|
|
14
|
+
FetchMethods["APPLY"] = "APPLY";
|
|
15
|
+
FetchMethods["DELETE"] = "DELETE";
|
|
16
|
+
FetchMethods["GET"] = "GET";
|
|
17
|
+
FetchMethods["LOG"] = "LOG";
|
|
18
|
+
FetchMethods["PATCH"] = "PATCH";
|
|
19
|
+
FetchMethods["PATCH_STATUS"] = "PATCH_STATUS";
|
|
20
|
+
FetchMethods["POST"] = "POST";
|
|
21
|
+
FetchMethods["PUT"] = "PUT";
|
|
22
|
+
FetchMethods["WATCH"] = "WATCH";
|
|
23
|
+
})(FetchMethods || (FetchMethods = {}));
|
package/dist/fluent/types.d.ts
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
import { KubernetesListObject, KubernetesObject } from "@kubernetes/client-node";
|
|
2
2
|
import { Operation } from "fast-json-patch";
|
|
3
3
|
import type { PartialDeep } from "type-fest";
|
|
4
|
-
import {
|
|
5
|
-
import { GenericClass, GroupVersionKind } from "../types";
|
|
4
|
+
import { GenericClass } from "../types";
|
|
6
5
|
import { WatchCfg, Watcher } from "./watch";
|
|
7
6
|
import https from "https";
|
|
8
7
|
import { SecureClientSessionOptions } from "http2";
|
|
8
|
+
import { WatchAction, FetchMethods, ApplyCfg } from "./shared-types";
|
|
9
9
|
export type WatcherType<T extends GenericClass> = Watcher<T>;
|
|
10
|
-
/**
|
|
11
|
-
* Fetch options and server URL
|
|
12
|
-
*/
|
|
13
|
-
export type K8sConfigPromise = Promise<{
|
|
14
|
-
opts: RequestInit;
|
|
15
|
-
serverUrl: string | URL;
|
|
16
|
-
}>;
|
|
17
10
|
/**
|
|
18
11
|
* Agent options for the the http2Watch
|
|
19
12
|
*/
|
|
@@ -26,24 +19,6 @@ export interface Options {
|
|
|
26
19
|
options?: AgentOptions;
|
|
27
20
|
};
|
|
28
21
|
}
|
|
29
|
-
/**
|
|
30
|
-
* The Phase matched when using the K8s Watch API.
|
|
31
|
-
*/
|
|
32
|
-
export declare enum WatchPhase {
|
|
33
|
-
Added = "ADDED",
|
|
34
|
-
Modified = "MODIFIED",
|
|
35
|
-
Deleted = "DELETED",
|
|
36
|
-
Bookmark = "BOOKMARK",
|
|
37
|
-
Error = "ERROR"
|
|
38
|
-
}
|
|
39
|
-
export type FetchMethods = "APPLY" | "DELETE" | "GET" | "LOG" | "PATCH" | "PATCH_STATUS" | "POST" | "PUT" | "WATCH";
|
|
40
|
-
export interface Filters {
|
|
41
|
-
kindOverride?: GroupVersionKind;
|
|
42
|
-
fields?: Record<string, string>;
|
|
43
|
-
labels?: Record<string, string>;
|
|
44
|
-
name?: string;
|
|
45
|
-
namespace?: string;
|
|
46
|
-
}
|
|
47
22
|
/**
|
|
48
23
|
* Get the resource or resources matching the filters.
|
|
49
24
|
* If no filters are specified, all resources will be returned.
|
|
@@ -189,15 +164,6 @@ export type K8sWithFilters<T extends GenericClass, K extends KubernetesObject> =
|
|
|
189
164
|
*/
|
|
190
165
|
WithLabel: (key: string, value?: string) => K8sWithFilters<T, K>;
|
|
191
166
|
};
|
|
192
|
-
/**
|
|
193
|
-
* Configuration for the apply function.
|
|
194
|
-
*/
|
|
195
|
-
export type ApplyCfg = {
|
|
196
|
-
/**
|
|
197
|
-
* Force the apply to be a create.
|
|
198
|
-
*/
|
|
199
|
-
force?: boolean;
|
|
200
|
-
};
|
|
201
167
|
export type K8sInit<T extends GenericClass, K extends KubernetesObject> = K8sWithFilters<T, K> & K8sUnfilteredActions<K> & {
|
|
202
168
|
/**
|
|
203
169
|
* Set the namespace filter.
|
|
@@ -207,7 +173,6 @@ export type K8sInit<T extends GenericClass, K extends KubernetesObject> = K8sWit
|
|
|
207
173
|
*/
|
|
208
174
|
InNamespace: (namespace: string) => K8sWithFilters<T, K>;
|
|
209
175
|
};
|
|
210
|
-
export type WatchAction<T extends GenericClass, K extends KubernetesObject = InstanceType<T>> = (update: K, phase: WatchPhase) => Promise<void> | void;
|
|
211
176
|
type Join<K, P> = K extends string | number ? P extends string | number ? `${K}${"" extends P ? "" : "."}${P}` : never : never;
|
|
212
177
|
export type Paths<T, D extends number = 10> = [D] extends [never] ? never : T extends object ? {
|
|
213
178
|
[K in keyof T]-?: K extends string | number ? `${K}` | Join<K, Paths<T[K]>> : never;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/fluent/types.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAA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AE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK;CACpF,CAAC,MAAM,CAAC,CAAC,GACV,EAAE,CAAC"}
|
package/dist/fluent/types.js
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
2
|
// SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
|
|
4
|
-
|
|
5
|
-
exports.WatchPhase = void 0;
|
|
6
|
-
/**
|
|
7
|
-
* The Phase matched when using the K8s Watch API.
|
|
8
|
-
*/
|
|
9
|
-
var WatchPhase;
|
|
10
|
-
(function (WatchPhase) {
|
|
11
|
-
WatchPhase["Added"] = "ADDED";
|
|
12
|
-
WatchPhase["Modified"] = "MODIFIED";
|
|
13
|
-
WatchPhase["Deleted"] = "DELETED";
|
|
14
|
-
WatchPhase["Bookmark"] = "BOOKMARK";
|
|
15
|
-
WatchPhase["Error"] = "ERROR";
|
|
16
|
-
})(WatchPhase || (exports.WatchPhase = WatchPhase = {}));
|
|
3
|
+
export {};
|
package/dist/fluent/utils.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { RequestInit } from "node-fetch";
|
|
|
2
2
|
import { URL } from "url";
|
|
3
3
|
import { Dispatcher } from "undici";
|
|
4
4
|
import { GenericClass } from "../types";
|
|
5
|
-
import { ApplyCfg,
|
|
5
|
+
import { ApplyCfg, Filters, K8sConfigPromise, FetchMethods } from "./shared-types";
|
|
6
6
|
/**
|
|
7
7
|
* Get the headers for a request
|
|
8
8
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/fluent/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC1B,OAAO,EAAS,UAAU,EAAE,MAAM,QAAQ,CAA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,QAA2B,cA+DtC"}
|
package/dist/fluent/utils.js
CHANGED
|
@@ -1,23 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
2
|
// SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
exports.k8sCfg = k8sCfg;
|
|
13
|
-
exports.k8sExec = k8sExec;
|
|
14
|
-
const client_node_1 = require("@kubernetes/client-node");
|
|
15
|
-
const url_1 = require("url");
|
|
16
|
-
const undici_1 = require("undici");
|
|
17
|
-
const https_1 = require("https");
|
|
18
|
-
const fetch_1 = require("../fetch");
|
|
19
|
-
const kinds_1 = require("../kinds");
|
|
20
|
-
const fs_1 = __importDefault(require("fs"));
|
|
3
|
+
import { KubeConfig, PatchStrategy } from "@kubernetes/client-node";
|
|
4
|
+
import { URL } from "url";
|
|
5
|
+
import { Agent } from "undici";
|
|
6
|
+
import { Agent as httpsAgent } from "https";
|
|
7
|
+
import { fetch } from "../fetch";
|
|
8
|
+
import { modelToGroupVersionKind } from "../kinds";
|
|
9
|
+
import { FetchMethods } from "./shared-types";
|
|
10
|
+
import fs from "fs";
|
|
21
11
|
const SSA_CONTENT_TYPE = "application/apply-patch+yaml";
|
|
22
12
|
const K8S_SA_TOKEN_PATH = "/var/run/secrets/kubernetes.io/serviceaccount/token";
|
|
23
13
|
/**
|
|
@@ -26,7 +16,7 @@ const K8S_SA_TOKEN_PATH = "/var/run/secrets/kubernetes.io/serviceaccount/token";
|
|
|
26
16
|
* @param token - the token from @kubernetes/client-node
|
|
27
17
|
* @returns the headers for undici
|
|
28
18
|
*/
|
|
29
|
-
async function getHeaders(token) {
|
|
19
|
+
export async function getHeaders(token) {
|
|
30
20
|
let saToken = "";
|
|
31
21
|
if (!token) {
|
|
32
22
|
saToken = await getToken();
|
|
@@ -49,9 +39,9 @@ async function getHeaders(token) {
|
|
|
49
39
|
* @param opts - the request options from node-fetch
|
|
50
40
|
* @returns the agent for undici
|
|
51
41
|
*/
|
|
52
|
-
function getHTTPSAgent(opts) {
|
|
42
|
+
export function getHTTPSAgent(opts) {
|
|
53
43
|
// In cluster there will be agent - testing or dev no
|
|
54
|
-
const agentOptions = opts.agent instanceof
|
|
44
|
+
const agentOptions = opts.agent instanceof httpsAgent
|
|
55
45
|
? {
|
|
56
46
|
ca: opts.agent.options.ca,
|
|
57
47
|
cert: opts.agent.options.cert,
|
|
@@ -62,7 +52,7 @@ function getHTTPSAgent(opts) {
|
|
|
62
52
|
cert: undefined,
|
|
63
53
|
key: undefined,
|
|
64
54
|
};
|
|
65
|
-
return new
|
|
55
|
+
return new Agent({
|
|
66
56
|
keepAliveMaxTimeout: 600000,
|
|
67
57
|
keepAliveTimeout: 600000,
|
|
68
58
|
bodyTimeout: 0,
|
|
@@ -74,9 +64,9 @@ function getHTTPSAgent(opts) {
|
|
|
74
64
|
*
|
|
75
65
|
* @returns token or null
|
|
76
66
|
*/
|
|
77
|
-
async function getToken() {
|
|
67
|
+
export async function getToken() {
|
|
78
68
|
try {
|
|
79
|
-
return (await
|
|
69
|
+
return (await fs.promises.readFile(K8S_SA_TOKEN_PATH, "utf8")).trim();
|
|
80
70
|
}
|
|
81
71
|
catch {
|
|
82
72
|
return null;
|
|
@@ -91,8 +81,8 @@ async function getToken() {
|
|
|
91
81
|
* @param excludeName - (optional) exclude the name from the path
|
|
92
82
|
* @returns the path to the resource
|
|
93
83
|
*/
|
|
94
|
-
function pathBuilder(serverUrl, model, filters, excludeName = false) {
|
|
95
|
-
const matchedKind = filters.kindOverride ||
|
|
84
|
+
export function pathBuilder(serverUrl, model, filters, excludeName = false) {
|
|
85
|
+
const matchedKind = filters.kindOverride || modelToGroupVersionKind(model.name);
|
|
96
86
|
// If the kind is not specified and the model is not a KubernetesObject, throw an error
|
|
97
87
|
if (!matchedKind) {
|
|
98
88
|
throw new Error(`Kind not specified for ${model.name}`);
|
|
@@ -114,7 +104,7 @@ function pathBuilder(serverUrl, model, filters, excludeName = false) {
|
|
|
114
104
|
// Build the complete path to the resource
|
|
115
105
|
const path = [base, namespace, plural, name].filter(Boolean).join("/");
|
|
116
106
|
// Generate the URL object
|
|
117
|
-
const url = new
|
|
107
|
+
const url = new URL(path, serverUrl);
|
|
118
108
|
// Add field selectors to the query params
|
|
119
109
|
if (filters.fields) {
|
|
120
110
|
const fieldSelector = Object.entries(filters.fields)
|
|
@@ -144,8 +134,8 @@ function pathBuilder(serverUrl, model, filters, excludeName = false) {
|
|
|
144
134
|
* @param method - the HTTP method to use
|
|
145
135
|
* @returns the fetch options and server URL
|
|
146
136
|
*/
|
|
147
|
-
async function k8sCfg(method) {
|
|
148
|
-
const kubeConfig = new
|
|
137
|
+
export async function k8sCfg(method) {
|
|
138
|
+
const kubeConfig = new KubeConfig();
|
|
149
139
|
kubeConfig.loadFromDefault();
|
|
150
140
|
const cluster = kubeConfig.getCurrentCluster();
|
|
151
141
|
if (!cluster) {
|
|
@@ -185,9 +175,9 @@ const isEvictionPayload = (payload) => payload !== null &&
|
|
|
185
175
|
*
|
|
186
176
|
* @returns the parsed JSON response
|
|
187
177
|
*/
|
|
188
|
-
async function k8sExec(model, filters, method, payload, applyCfg = { force: false }) {
|
|
178
|
+
export async function k8sExec(model, filters, method, payload, applyCfg = { force: false }) {
|
|
189
179
|
const reconstruct = async (method) => {
|
|
190
|
-
const configMethod = method ===
|
|
180
|
+
const configMethod = method === FetchMethods.LOG ? FetchMethods.GET : method;
|
|
191
181
|
const { opts, serverUrl } = await k8sCfg(configMethod);
|
|
192
182
|
// Build the base path once, using excludeName only for standard POST requests
|
|
193
183
|
const shouldExcludeName = method === "POST" && !(payload && isEvictionPayload(payload));
|
|
@@ -205,17 +195,17 @@ async function k8sExec(model, filters, method, payload, applyCfg = { force: fals
|
|
|
205
195
|
};
|
|
206
196
|
};
|
|
207
197
|
const { opts, serverUrl } = await reconstruct(method);
|
|
208
|
-
const url = serverUrl instanceof
|
|
198
|
+
const url = serverUrl instanceof URL ? serverUrl : new URL(serverUrl);
|
|
209
199
|
switch (opts.method) {
|
|
210
200
|
// PATCH_STATUS is a special case that uses the PATCH method on status subresources
|
|
211
201
|
case "PATCH_STATUS":
|
|
212
202
|
opts.method = "PATCH";
|
|
213
203
|
url.pathname = `${url.pathname}/status`;
|
|
214
|
-
opts.headers["Content-Type"] =
|
|
204
|
+
opts.headers["Content-Type"] = PatchStrategy.MergePatch;
|
|
215
205
|
payload = { status: payload.status };
|
|
216
206
|
break;
|
|
217
207
|
case "PATCH":
|
|
218
|
-
opts.headers["Content-Type"] =
|
|
208
|
+
opts.headers["Content-Type"] = PatchStrategy.JsonPatch;
|
|
219
209
|
break;
|
|
220
210
|
case "APPLY":
|
|
221
211
|
opts.headers["Content-Type"] = SSA_CONTENT_TYPE;
|
|
@@ -228,7 +218,7 @@ async function k8sExec(model, filters, method, payload, applyCfg = { force: fals
|
|
|
228
218
|
if (payload) {
|
|
229
219
|
opts.body = JSON.stringify(payload);
|
|
230
220
|
}
|
|
231
|
-
const resp = await
|
|
221
|
+
const resp = await fetch(url, opts);
|
|
232
222
|
if (resp.ok) {
|
|
233
223
|
return resp.data;
|
|
234
224
|
}
|
package/dist/fluent/watch.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from "events";
|
|
2
2
|
import { GenericClass } from "../types";
|
|
3
|
-
import {
|
|
3
|
+
import { WatchAction, Filters } from "./shared-types";
|
|
4
4
|
export declare enum WatchEvent {
|
|
5
5
|
/** Watch is connected successfully */
|
|
6
6
|
CONNECT = "connect",
|
|
@@ -67,13 +67,6 @@ export declare class Watcher<T extends GenericClass> {
|
|
|
67
67
|
start(): Promise<AbortController>;
|
|
68
68
|
/** Close the watch. Also available on the AbortController returned by {@link Watcher.start}. */
|
|
69
69
|
close(): void;
|
|
70
|
-
/**
|
|
71
|
-
* Get a unique ID for the watch based on the model and filters.
|
|
72
|
-
* This is useful for caching the watch data or resource versions.
|
|
73
|
-
*
|
|
74
|
-
* @returns the watch CacheID
|
|
75
|
-
*/
|
|
76
|
-
getCacheID(): string;
|
|
77
70
|
/**
|
|
78
71
|
* Subscribe to watch events. This is an EventEmitter that emits the following events:
|
|
79
72
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../../src/fluent/watch.ts"],"names":[],"mappings":"
|
|
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,UAAU,CAAC;AAG9D,OAAO,EAAgC,WAAW,EAAE,OAAO,EAAgB,MAAM,gBAAgB,CAAC;AAClG,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;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