kubernetes-fluent-client 3.3.4 → 3.3.6
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 -1
- package/.lintstagedrc.json +2 -1
- package/.prettierignore +2 -1
- package/CODEOWNERS +3 -4
- package/codeql-config.yaml +3 -0
- package/dist/fetch.d.ts +1 -1
- package/dist/fetch.d.ts.map +1 -1
- package/dist/fetch.js +7 -38
- package/dist/fileSystem.js +17 -7
- package/dist/fluent/types.d.ts +8 -0
- package/dist/fluent/types.d.ts.map +1 -1
- package/dist/fluent/utils.d.ts +23 -5
- package/dist/fluent/utils.d.ts.map +1 -1
- package/dist/fluent/utils.js +80 -18
- package/dist/fluent/watch.d.ts +0 -3
- package/dist/fluent/watch.d.ts.map +1 -1
- package/dist/fluent/watch.js +10 -58
- package/dist/generate.js +17 -7
- package/dist/index.js +17 -7
- package/dist/postProcessing.js +17 -7
- package/eslint.config.mjs +1 -1
- package/package.json +25 -9
- package/src/fetch.ts +7 -16
- package/src/fluent/types.ts +7 -1
- package/src/fluent/utils.ts +83 -24
- package/src/fluent/watch.ts +19 -63
- package/test/datastore.crd.yaml +59 -0
- package/test/webapp.crd.yaml +62 -0
package/.husky/pre-commit
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
npx lint-staged --verbose
|
|
1
|
+
npx lint-staged --verbose
|
package/.lintstagedrc.json
CHANGED
package/.prettierignore
CHANGED
package/CODEOWNERS
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
* @
|
|
1
|
+
* @defenseunicorns/pepr
|
|
2
2
|
|
|
3
3
|
# Additional privileged files
|
|
4
|
-
/CODEOWNERS @jeff-mccoy @
|
|
5
|
-
/cosign.pub @jeff-mccoy @
|
|
4
|
+
/CODEOWNERS @jeff-mccoy @daveworth
|
|
5
|
+
/cosign.pub @jeff-mccoy @daveworth
|
|
6
6
|
/LICENSE @jeff-mccoy @austenbryan
|
|
7
|
-
|
package/dist/fetch.d.ts
CHANGED
package/dist/fetch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAIA,
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAIA,OAAO,EAAwB,WAAW,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAExE,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI;IAC7B,IAAI,EAAE,CAAC,CAAC;IACR,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAsB,KAAK,CAAC,CAAC,EAC3B,GAAG,EAAE,GAAG,GAAG,WAAW,EACtB,IAAI,CAAC,EAAE,WAAW,GACjB,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CA+B3B"}
|
package/dist/fetch.js
CHANGED
|
@@ -1,33 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
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
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
5
|
exports.fetch = fetch;
|
|
29
6
|
const http_status_codes_1 = require("http-status-codes");
|
|
30
|
-
const
|
|
7
|
+
const undici_1 = require("undici");
|
|
31
8
|
/**
|
|
32
9
|
* Perform an async HTTP call and return the parsed JSON response, optionally
|
|
33
10
|
* as a specific type.
|
|
@@ -44,11 +21,11 @@ const node_fetch_1 = __importStar(require("node-fetch"));
|
|
|
44
21
|
async function fetch(url, init) {
|
|
45
22
|
let data = undefined;
|
|
46
23
|
try {
|
|
47
|
-
const resp = await (0,
|
|
24
|
+
const resp = await (0, undici_1.fetch)(url, init);
|
|
48
25
|
const contentType = resp.headers.get("content-type") || "";
|
|
49
26
|
// Parse the response as JSON if the content type is JSON
|
|
50
27
|
if (contentType.includes("application/json")) {
|
|
51
|
-
data = await resp.json();
|
|
28
|
+
data = (await resp.json());
|
|
52
29
|
}
|
|
53
30
|
else {
|
|
54
31
|
// Otherwise, return however the response was read
|
|
@@ -62,21 +39,13 @@ async function fetch(url, init) {
|
|
|
62
39
|
};
|
|
63
40
|
}
|
|
64
41
|
catch (e) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const status = parseInt(e.code || "400");
|
|
68
|
-
return {
|
|
69
|
-
data,
|
|
70
|
-
ok: false,
|
|
71
|
-
status,
|
|
72
|
-
statusText: e.message,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
42
|
+
const status = parseInt(e?.code) || http_status_codes_1.StatusCodes.BAD_REQUEST;
|
|
43
|
+
const statusText = e?.message || "Unknown error";
|
|
75
44
|
return {
|
|
76
45
|
data,
|
|
77
46
|
ok: false,
|
|
78
|
-
status
|
|
79
|
-
statusText
|
|
47
|
+
status,
|
|
48
|
+
statusText,
|
|
80
49
|
};
|
|
81
50
|
}
|
|
82
51
|
}
|
package/dist/fileSystem.js
CHANGED
|
@@ -17,13 +17,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
17
17
|
}) : function(o, v) {
|
|
18
18
|
o["default"] = v;
|
|
19
19
|
});
|
|
20
|
-
var __importStar = (this && this.__importStar) || function (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
20
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
21
|
+
var ownKeys = function(o) {
|
|
22
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
+
var ar = [];
|
|
24
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
25
|
+
return ar;
|
|
26
|
+
};
|
|
27
|
+
return ownKeys(o);
|
|
28
|
+
};
|
|
29
|
+
return function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
27
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
38
|
exports.NodeFileSystem = void 0;
|
|
29
39
|
const fs = __importStar(require("fs"));
|
package/dist/fluent/types.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
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 { RequestInit as UndiciRequestInit } from "undici";
|
|
4
5
|
import { GenericClass, GroupVersionKind } from "../types";
|
|
5
6
|
import { WatchCfg, Watcher } from "./watch";
|
|
6
7
|
import https from "https";
|
|
7
8
|
import { SecureClientSessionOptions } from "http2";
|
|
9
|
+
/**
|
|
10
|
+
* Fetch options and server URL
|
|
11
|
+
*/
|
|
12
|
+
export type K8sConfigPromise = Promise<{
|
|
13
|
+
opts: UndiciRequestInit;
|
|
14
|
+
serverUrl: string | URL;
|
|
15
|
+
}>;
|
|
8
16
|
/**
|
|
9
17
|
* Agent options for the the http2Watch
|
|
10
18
|
*/
|
|
@@ -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,CAAC;
|
|
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,CAAC;AAC7C,OAAO,EAAE,WAAW,IAAI,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,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KAAK,GACP,KAAK,CAAC;AAEV,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAC7D,KAAK,GACL,CAAC,SAAS,MAAM,GACd;KACG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK;CACpF,CAAC,MAAM,CAAC,CAAC,GACV,EAAE,CAAC"}
|
package/dist/fluent/utils.d.ts
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
|
+
import { RequestInit } from "node-fetch";
|
|
1
2
|
import { URL } from "url";
|
|
3
|
+
import { Dispatcher } from "undici";
|
|
2
4
|
import { GenericClass } from "../types";
|
|
3
|
-
import { ApplyCfg, FetchMethods, Filters } from "./types";
|
|
5
|
+
import { ApplyCfg, FetchMethods, Filters, K8sConfigPromise } from "./types";
|
|
6
|
+
/**
|
|
7
|
+
* Get the headers for a request
|
|
8
|
+
*
|
|
9
|
+
* @returns the headers for undici
|
|
10
|
+
*/
|
|
11
|
+
export declare function getHeaders(): Promise<Record<string, string>>;
|
|
12
|
+
/**
|
|
13
|
+
* Get the agent for a request
|
|
14
|
+
*
|
|
15
|
+
* @param opts - the request options from node-fetch
|
|
16
|
+
* @returns the agent for undici
|
|
17
|
+
*/
|
|
18
|
+
export declare function getHTTPSAgent(opts: RequestInit): Dispatcher | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Read the serviceAccount Token
|
|
21
|
+
*
|
|
22
|
+
* @returns token or null
|
|
23
|
+
*/
|
|
24
|
+
export declare function getToken(): Promise<string | null>;
|
|
4
25
|
/**
|
|
5
26
|
* Generate a path to a Kubernetes resource
|
|
6
27
|
*
|
|
@@ -22,10 +43,7 @@ export declare function pathBuilder<T extends GenericClass>(serverUrl: string, m
|
|
|
22
43
|
* @param method - the HTTP method to use
|
|
23
44
|
* @returns the fetch options and server URL
|
|
24
45
|
*/
|
|
25
|
-
export declare function k8sCfg(method: FetchMethods):
|
|
26
|
-
opts: import("node-fetch").RequestInit;
|
|
27
|
-
serverUrl: string;
|
|
28
|
-
}>;
|
|
46
|
+
export declare function k8sCfg(method: FetchMethods): K8sConfigPromise;
|
|
29
47
|
/**
|
|
30
48
|
* Execute a request against the Kubernetes API server.
|
|
31
49
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/fluent/utils.ts"],"names":[],"mappings":"
|
|
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,CAAC;AAI3C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAM5E;;;;GAIG;AACH,wBAAsB,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAYlE;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,GAAG,UAAU,GAAG,SAAS,CAqBvE;AACD;;;;GAIG;AACH,wBAAsB,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAMvD;AACD;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,YAAY,EAChD,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,OAAO,EAChB,WAAW,UAAQ,OAwDpB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,gBAAgB,CAoBnE;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,OAAO,CAAC,CAAC,SAAS,YAAY,EAAE,CAAC,EACrD,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,YAAY,EACpB,OAAO,CAAC,EAAE,CAAC,GAAG,OAAO,EACrB,QAAQ,GAAE,QAA2B,cAyDtC"}
|
package/dist/fluent/utils.js
CHANGED
|
@@ -1,15 +1,80 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
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
|
+
};
|
|
4
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.getHeaders = getHeaders;
|
|
9
|
+
exports.getHTTPSAgent = getHTTPSAgent;
|
|
10
|
+
exports.getToken = getToken;
|
|
5
11
|
exports.pathBuilder = pathBuilder;
|
|
6
12
|
exports.k8sCfg = k8sCfg;
|
|
7
13
|
exports.k8sExec = k8sExec;
|
|
8
14
|
const client_node_1 = require("@kubernetes/client-node");
|
|
9
15
|
const url_1 = require("url");
|
|
16
|
+
const undici_1 = require("undici");
|
|
17
|
+
const https_1 = require("https");
|
|
10
18
|
const fetch_1 = require("../fetch");
|
|
11
19
|
const kinds_1 = require("../kinds");
|
|
20
|
+
const fs_1 = __importDefault(require("fs"));
|
|
12
21
|
const SSA_CONTENT_TYPE = "application/apply-patch+yaml";
|
|
22
|
+
const K8S_SA_TOKEN_PATH = "/var/run/secrets/kubernetes.io/serviceaccount/token";
|
|
23
|
+
/**
|
|
24
|
+
* Get the headers for a request
|
|
25
|
+
*
|
|
26
|
+
* @returns the headers for undici
|
|
27
|
+
*/
|
|
28
|
+
async function getHeaders() {
|
|
29
|
+
const token = await getToken();
|
|
30
|
+
const headers = {
|
|
31
|
+
"Content-Type": "application/json",
|
|
32
|
+
"User-Agent": "kubernetes-fluent-client",
|
|
33
|
+
};
|
|
34
|
+
if (token) {
|
|
35
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
36
|
+
}
|
|
37
|
+
return headers;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get the agent for a request
|
|
41
|
+
*
|
|
42
|
+
* @param opts - the request options from node-fetch
|
|
43
|
+
* @returns the agent for undici
|
|
44
|
+
*/
|
|
45
|
+
function getHTTPSAgent(opts) {
|
|
46
|
+
// In cluster there will be agent - testing or dev no
|
|
47
|
+
const agentOptions = opts.agent instanceof https_1.Agent
|
|
48
|
+
? {
|
|
49
|
+
ca: opts.agent.options.ca,
|
|
50
|
+
cert: opts.agent.options.cert,
|
|
51
|
+
key: opts.agent.options.key,
|
|
52
|
+
}
|
|
53
|
+
: {
|
|
54
|
+
ca: undefined,
|
|
55
|
+
cert: undefined,
|
|
56
|
+
key: undefined,
|
|
57
|
+
};
|
|
58
|
+
return new undici_1.Agent({
|
|
59
|
+
keepAliveMaxTimeout: 600000,
|
|
60
|
+
keepAliveTimeout: 600000,
|
|
61
|
+
bodyTimeout: 0,
|
|
62
|
+
connect: agentOptions,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Read the serviceAccount Token
|
|
67
|
+
*
|
|
68
|
+
* @returns token or null
|
|
69
|
+
*/
|
|
70
|
+
async function getToken() {
|
|
71
|
+
try {
|
|
72
|
+
return (await fs_1.default.promises.readFile(K8S_SA_TOKEN_PATH, "utf8")).trim();
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
13
78
|
/**
|
|
14
79
|
* Generate a path to a Kubernetes resource
|
|
15
80
|
*
|
|
@@ -79,19 +144,15 @@ async function k8sCfg(method) {
|
|
|
79
144
|
if (!cluster) {
|
|
80
145
|
throw new Error("No currently active cluster");
|
|
81
146
|
}
|
|
82
|
-
//
|
|
83
|
-
const opts = await kubeConfig.applyToFetchOptions({
|
|
147
|
+
// Get TLS Options
|
|
148
|
+
const opts = await kubeConfig.applyToFetchOptions({});
|
|
149
|
+
// Transform the TLS options & auth headers, as needed
|
|
150
|
+
const undiciRequestUnit = {
|
|
151
|
+
headers: await getHeaders(),
|
|
84
152
|
method,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
// Set the user agent like kubectl does
|
|
89
|
-
"User-Agent": `kubernetes-fluent-client`,
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
// Enable compression
|
|
93
|
-
opts.compress = true;
|
|
94
|
-
return { opts, serverUrl: cluster.server };
|
|
153
|
+
dispatcher: getHTTPSAgent(opts),
|
|
154
|
+
};
|
|
155
|
+
return { opts: undiciRequestUnit, serverUrl: cluster.server };
|
|
95
156
|
}
|
|
96
157
|
/**
|
|
97
158
|
* Execute a request against the Kubernetes API server.
|
|
@@ -109,29 +170,30 @@ async function k8sExec(model, filters, method, payload, applyCfg = { force: fals
|
|
|
109
170
|
const configMethod = method === "LOG" ? "GET" : method;
|
|
110
171
|
const { opts, serverUrl } = await k8sCfg(configMethod);
|
|
111
172
|
const isPost = method === "POST";
|
|
112
|
-
const baseUrl = pathBuilder(serverUrl, model, filters, isPost);
|
|
173
|
+
const baseUrl = pathBuilder(serverUrl.toString(), model, filters, isPost);
|
|
113
174
|
if (method === "LOG") {
|
|
114
175
|
baseUrl.pathname = `${baseUrl.pathname}/log`;
|
|
115
176
|
}
|
|
116
177
|
return {
|
|
117
|
-
|
|
178
|
+
serverUrl: baseUrl,
|
|
118
179
|
opts,
|
|
119
180
|
};
|
|
120
181
|
};
|
|
121
|
-
const { opts,
|
|
182
|
+
const { opts, serverUrl } = await reconstruct(method);
|
|
183
|
+
const url = serverUrl instanceof url_1.URL ? serverUrl : new url_1.URL(serverUrl);
|
|
122
184
|
switch (opts.method) {
|
|
123
185
|
// PATCH_STATUS is a special case that uses the PATCH method on status subresources
|
|
124
186
|
case "PATCH_STATUS":
|
|
125
187
|
opts.method = "PATCH";
|
|
126
188
|
url.pathname = `${url.pathname}/status`;
|
|
127
|
-
opts.headers
|
|
189
|
+
opts.headers["Content-Type"] = client_node_1.PatchStrategy.MergePatch;
|
|
128
190
|
payload = { status: payload.status };
|
|
129
191
|
break;
|
|
130
192
|
case "PATCH":
|
|
131
|
-
opts.headers
|
|
193
|
+
opts.headers["Content-Type"] = client_node_1.PatchStrategy.JsonPatch;
|
|
132
194
|
break;
|
|
133
195
|
case "APPLY":
|
|
134
|
-
opts.headers
|
|
196
|
+
opts.headers["Content-Type"] = SSA_CONTENT_TYPE;
|
|
135
197
|
opts.method = "PATCH";
|
|
136
198
|
url.searchParams.set("fieldManager", "pepr");
|
|
137
199
|
url.searchParams.set("fieldValidation", "Strict");
|
package/dist/fluent/watch.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { EventEmitter } from "events";
|
|
2
|
-
import { RequestInit } from "node-fetch";
|
|
3
|
-
import { Agent } from "undici";
|
|
4
2
|
import { GenericClass } from "../types";
|
|
5
3
|
import { Filters, WatchAction } from "./types";
|
|
6
4
|
export declare enum WatchEvent {
|
|
@@ -84,6 +82,5 @@ export declare class Watcher<T extends GenericClass> {
|
|
|
84
82
|
* @returns an EventEmitter
|
|
85
83
|
*/
|
|
86
84
|
get events(): EventEmitter;
|
|
87
|
-
static getHTTPSAgent: (opts: RequestInit) => Agent;
|
|
88
85
|
}
|
|
89
86
|
//# sourceMappingURL=watch.d.ts.map
|
|
@@ -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;
|
|
1
|
+
{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,EAAE,QAAQ,GAAE,QAAa;IA0CzF;;;;OAIG;IACU,KAAK,IAAI,OAAO,CAAC,eAAe,CAAC;IAO9C,gGAAgG;IACzF,KAAK;IAQZ;;;;;OAKG;IACI,UAAU;IAWjB;;;;;;OAMG;IACH,IAAW,MAAM,IAAI,YAAY,CAEhC;CA0VF"}
|
package/dist/fluent/watch.js
CHANGED
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
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
|
-
var _a;
|
|
8
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
5
|
exports.Watcher = exports.WatchEvent = void 0;
|
|
10
6
|
const crypto_1 = require("crypto");
|
|
11
7
|
const events_1 = require("events");
|
|
12
|
-
const https_1 = __importDefault(require("https"));
|
|
13
8
|
const undici_1 = require("undici");
|
|
14
9
|
const fetch_1 = require("../fetch");
|
|
15
10
|
const types_1 = require("./types");
|
|
16
11
|
const utils_1 = require("./utils");
|
|
17
12
|
const stream_1 = require("stream");
|
|
18
|
-
const fs_1 = __importDefault(require("fs"));
|
|
19
13
|
var WatchEvent;
|
|
20
14
|
(function (WatchEvent) {
|
|
21
15
|
/** Watch is connected successfully */
|
|
@@ -78,8 +72,6 @@ class Watcher {
|
|
|
78
72
|
#resourceVersion;
|
|
79
73
|
// Track the list of items in the cache
|
|
80
74
|
#cache = new Map();
|
|
81
|
-
// Token Path
|
|
82
|
-
#TOKEN_PATH = "/var/run/secrets/kubernetes.io/serviceaccount/token";
|
|
83
75
|
/**
|
|
84
76
|
* Setup a Kubernetes watcher for the specified model and filters. The callback function will be called for each event received.
|
|
85
77
|
* The watch can be aborted by calling {@link Watcher.close} or by calling abort() on the AbortController returned by {@link Watcher.start}.
|
|
@@ -163,19 +155,6 @@ class Watcher {
|
|
|
163
155
|
get events() {
|
|
164
156
|
return this.#events;
|
|
165
157
|
}
|
|
166
|
-
/**
|
|
167
|
-
* Read the serviceAccount Token
|
|
168
|
-
*
|
|
169
|
-
* @returns token or null
|
|
170
|
-
*/
|
|
171
|
-
async #getToken() {
|
|
172
|
-
try {
|
|
173
|
-
return (await fs_1.default.promises.readFile(this.#TOKEN_PATH, "utf8")).trim();
|
|
174
|
-
}
|
|
175
|
-
catch {
|
|
176
|
-
return null;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
158
|
/**
|
|
180
159
|
* Build the URL and request options for the watch.
|
|
181
160
|
*
|
|
@@ -188,7 +167,8 @@ class Watcher {
|
|
|
188
167
|
#buildURL = async (isWatch, resourceVersion, continueToken) => {
|
|
189
168
|
// Build the path and query params for the resource, excluding the name
|
|
190
169
|
const { opts, serverUrl } = await (0, utils_1.k8sCfg)("GET");
|
|
191
|
-
const
|
|
170
|
+
const k8sUrl = serverUrl instanceof URL ? serverUrl.toString() : serverUrl;
|
|
171
|
+
const url = (0, utils_1.pathBuilder)(k8sUrl, this.#model, this.#filters, true);
|
|
192
172
|
// Enable the watch query param
|
|
193
173
|
if (isWatch) {
|
|
194
174
|
url.searchParams.set("watch", "true");
|
|
@@ -206,7 +186,7 @@ class Watcher {
|
|
|
206
186
|
}
|
|
207
187
|
// Add the abort signal to the request options
|
|
208
188
|
opts.signal = this.#abortController.signal;
|
|
209
|
-
return { opts, url };
|
|
189
|
+
return { opts, serverUrl: url };
|
|
210
190
|
};
|
|
211
191
|
/**
|
|
212
192
|
* Retrieve the list of resources and process the events.
|
|
@@ -216,9 +196,9 @@ class Watcher {
|
|
|
216
196
|
*/
|
|
217
197
|
#list = async (continueToken, removedItems) => {
|
|
218
198
|
try {
|
|
219
|
-
const { opts,
|
|
199
|
+
const { opts, serverUrl } = await this.#buildURL(false, undefined, continueToken);
|
|
220
200
|
// Make the request to list the resources
|
|
221
|
-
const response = await (0, fetch_1.fetch)(
|
|
201
|
+
const response = await (0, fetch_1.fetch)(serverUrl, opts);
|
|
222
202
|
const list = response.data;
|
|
223
203
|
// If the request fails, emit an error event and return
|
|
224
204
|
if (!response.ok) {
|
|
@@ -328,26 +308,6 @@ class Watcher {
|
|
|
328
308
|
this.#events.emit(WatchEvent.DATA_ERROR, err);
|
|
329
309
|
}
|
|
330
310
|
};
|
|
331
|
-
static getHTTPSAgent = (opts) => {
|
|
332
|
-
// In cluster there will be agent - testing or dev no
|
|
333
|
-
const agentOptions = opts.agent instanceof https_1.default.Agent
|
|
334
|
-
? {
|
|
335
|
-
ca: opts.agent.options.ca,
|
|
336
|
-
cert: opts.agent.options.cert,
|
|
337
|
-
key: opts.agent.options.key,
|
|
338
|
-
}
|
|
339
|
-
: {
|
|
340
|
-
ca: undefined,
|
|
341
|
-
cert: undefined,
|
|
342
|
-
key: undefined,
|
|
343
|
-
};
|
|
344
|
-
return new undici_1.Agent({
|
|
345
|
-
keepAliveMaxTimeout: 600000,
|
|
346
|
-
keepAliveTimeout: 600000,
|
|
347
|
-
bodyTimeout: 0,
|
|
348
|
-
connect: agentOptions,
|
|
349
|
-
});
|
|
350
|
-
};
|
|
351
311
|
/**
|
|
352
312
|
* Watch for changes to the resource.
|
|
353
313
|
*/
|
|
@@ -356,19 +316,12 @@ class Watcher {
|
|
|
356
316
|
// Start with a list operation
|
|
357
317
|
await this.#list();
|
|
358
318
|
// Build the URL and request options
|
|
359
|
-
const { opts,
|
|
360
|
-
const
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
"User-Agent": "kubernetes-fluent-client",
|
|
364
|
-
};
|
|
365
|
-
if (token) {
|
|
366
|
-
headers["Authorization"] = `Bearer ${token}`;
|
|
367
|
-
}
|
|
368
|
-
const response = await (0, undici_1.fetch)(url, {
|
|
369
|
-
headers,
|
|
370
|
-
dispatcher: _a.getHTTPSAgent(opts),
|
|
319
|
+
const { opts, serverUrl } = await this.#buildURL(true, this.#resourceVersion);
|
|
320
|
+
const response = await (0, undici_1.fetch)(serverUrl, {
|
|
321
|
+
headers: await (0, utils_1.getHeaders)(),
|
|
322
|
+
...opts,
|
|
371
323
|
});
|
|
324
|
+
const url = serverUrl instanceof URL ? serverUrl : new URL(serverUrl);
|
|
372
325
|
// If the request is successful, start listening for events
|
|
373
326
|
if (response.ok) {
|
|
374
327
|
// Reset the pending reconnect flag
|
|
@@ -484,4 +437,3 @@ class Watcher {
|
|
|
484
437
|
};
|
|
485
438
|
}
|
|
486
439
|
exports.Watcher = Watcher;
|
|
487
|
-
_a = Watcher;
|
package/dist/generate.js
CHANGED
|
@@ -17,13 +17,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
17
17
|
}) : function(o, v) {
|
|
18
18
|
o["default"] = v;
|
|
19
19
|
});
|
|
20
|
-
var __importStar = (this && this.__importStar) || function (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
20
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
21
|
+
var ownKeys = function(o) {
|
|
22
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
+
var ar = [];
|
|
24
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
25
|
+
return ar;
|
|
26
|
+
};
|
|
27
|
+
return ownKeys(o);
|
|
28
|
+
};
|
|
29
|
+
return function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
27
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
38
|
exports.convertCRDtoTS = convertCRDtoTS;
|
|
29
39
|
exports.prepareInputData = prepareInputData;
|
package/dist/index.js
CHANGED
|
@@ -17,13 +17,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
17
17
|
}) : function(o, v) {
|
|
18
18
|
o["default"] = v;
|
|
19
19
|
});
|
|
20
|
-
var __importStar = (this && this.__importStar) || function (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
20
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
21
|
+
var ownKeys = function(o) {
|
|
22
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
+
var ar = [];
|
|
24
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
25
|
+
return ar;
|
|
26
|
+
};
|
|
27
|
+
return ownKeys(o);
|
|
28
|
+
};
|
|
29
|
+
return function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
27
37
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
28
38
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
29
39
|
};
|
package/dist/postProcessing.js
CHANGED
|
@@ -17,13 +17,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
17
17
|
}) : function(o, v) {
|
|
18
18
|
o["default"] = v;
|
|
19
19
|
});
|
|
20
|
-
var __importStar = (this && this.__importStar) || function (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
20
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
21
|
+
var ownKeys = function(o) {
|
|
22
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
+
var ar = [];
|
|
24
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
25
|
+
return ar;
|
|
26
|
+
};
|
|
27
|
+
return ownKeys(o);
|
|
28
|
+
};
|
|
29
|
+
return function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
27
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
38
|
exports.postProcessing = postProcessing;
|
|
29
39
|
exports.mapFilesToCRD = mapFilesToCRD;
|
package/eslint.config.mjs
CHANGED
|
@@ -16,7 +16,7 @@ const compat = new FlatCompat({
|
|
|
16
16
|
|
|
17
17
|
export default [
|
|
18
18
|
{
|
|
19
|
-
ignores: ["**/node_modules", "**/dist", "**/__mocks__", "e2e
|
|
19
|
+
ignores: ["**/node_modules", "**/dist", "**/__mocks__", "e2e/**"],
|
|
20
20
|
},
|
|
21
21
|
...compat.extends(
|
|
22
22
|
"eslint:recommended",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kubernetes-fluent-client",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.6",
|
|
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",
|
|
@@ -10,7 +10,12 @@
|
|
|
10
10
|
"build": "tsc",
|
|
11
11
|
"semantic-release": "semantic-release",
|
|
12
12
|
"test": "jest src --coverage",
|
|
13
|
-
"test:e2e": "jest e2e",
|
|
13
|
+
"test:e2e": "jest e2e --runInBand",
|
|
14
|
+
"test:e2e:prep-crds": "kubectl apply -f test/ && npx ts-node src/cli.ts crd ./test/datastore.crd.yaml e2e && npx ts-node src/cli.ts crd https://raw.githubusercontent.com/defenseunicorns/kubernetes-fluent-client/refs/heads/main/test/webapp.crd.yaml e2e",
|
|
15
|
+
"test:e2e:prep-cluster": "k3d cluster create kfc-dev --k3s-arg '--debug@server:0' --wait && kubectl rollout status deployment -n kube-system",
|
|
16
|
+
"test:e2e:prep-image": "npm run build && npm pack && npm i kubernetes-fluent-client-0.0.0-development.tgz --no-save",
|
|
17
|
+
"test:e2e:run": "npm run test:e2e:prep-cluster && npm run test:e2e:prep-crds && npm run test:e2e:prep-image && jest e2e --runInBand && npm run test:e2e:cleanup",
|
|
18
|
+
"test:e2e:cleanup": "k3d cluster delete kfc-dev",
|
|
14
19
|
"format:check": "eslint src && prettier . --check",
|
|
15
20
|
"format:fix": "eslint --fix src && prettier . --write",
|
|
16
21
|
"prepare": "if [ \"$NODE_ENV\" != 'production' ]; then husky; fi"
|
|
@@ -42,8 +47,8 @@
|
|
|
42
47
|
"http-status-codes": "2.3.0",
|
|
43
48
|
"node-fetch": "2.7.0",
|
|
44
49
|
"quicktype-core": "23.0.170",
|
|
45
|
-
"type-fest": "4.
|
|
46
|
-
"undici": "
|
|
50
|
+
"type-fest": "4.29.1",
|
|
51
|
+
"undici": "7.0.0",
|
|
47
52
|
"yargs": "17.7.2"
|
|
48
53
|
},
|
|
49
54
|
"devDependencies": {
|
|
@@ -56,18 +61,29 @@
|
|
|
56
61
|
"@types/readable-stream": "4.0.18",
|
|
57
62
|
"@types/urijs": "^1.19.25",
|
|
58
63
|
"@types/yargs": "17.0.33",
|
|
59
|
-
"@typescript-eslint/eslint-plugin": "8.
|
|
60
|
-
"@typescript-eslint/parser": "8.
|
|
61
|
-
"eslint-plugin-jsdoc": "50.
|
|
64
|
+
"@typescript-eslint/eslint-plugin": "8.16.0",
|
|
65
|
+
"@typescript-eslint/parser": "8.16.0",
|
|
66
|
+
"eslint-plugin-jsdoc": "50.6.0",
|
|
62
67
|
"globals": "^15.12.0",
|
|
63
68
|
"husky": "^9.1.6",
|
|
64
69
|
"jest": "29.7.0",
|
|
65
70
|
"lint-staged": "^15.2.10",
|
|
66
71
|
"nock": "13.5.6",
|
|
67
|
-
"prettier": "3.
|
|
72
|
+
"prettier": "3.4.1",
|
|
68
73
|
"semantic-release": "24.2.0",
|
|
69
74
|
"ts-jest": "29.2.5",
|
|
70
|
-
"typescript": "5.
|
|
75
|
+
"typescript": "5.7.2"
|
|
76
|
+
},
|
|
77
|
+
"overrides": {
|
|
78
|
+
"semantic-release@24.2.0": {
|
|
79
|
+
"npm": {
|
|
80
|
+
"glob": {
|
|
81
|
+
"foreground-child": {
|
|
82
|
+
"cross-spawn": "^7.0.6"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
71
87
|
},
|
|
72
88
|
"release": {
|
|
73
89
|
"branches": [
|
package/src/fetch.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
|
|
3
3
|
|
|
4
4
|
import { StatusCodes } from "http-status-codes";
|
|
5
|
-
import
|
|
5
|
+
import { fetch as undiciFetch, RequestInfo, RequestInit } from "undici";
|
|
6
6
|
|
|
7
7
|
export type FetchResponse<T> = {
|
|
8
8
|
data: T;
|
|
@@ -30,12 +30,12 @@ export async function fetch<T>(
|
|
|
30
30
|
): Promise<FetchResponse<T>> {
|
|
31
31
|
let data = undefined as unknown as T;
|
|
32
32
|
try {
|
|
33
|
-
const resp = await
|
|
33
|
+
const resp = await undiciFetch(url, init);
|
|
34
34
|
const contentType = resp.headers.get("content-type") || "";
|
|
35
35
|
|
|
36
36
|
// Parse the response as JSON if the content type is JSON
|
|
37
37
|
if (contentType.includes("application/json")) {
|
|
38
|
-
data = await resp.json();
|
|
38
|
+
data = (await resp.json()) as T;
|
|
39
39
|
} else {
|
|
40
40
|
// Otherwise, return however the response was read
|
|
41
41
|
data = (await resp.text()) as unknown as T;
|
|
@@ -48,23 +48,14 @@ export async function fetch<T>(
|
|
|
48
48
|
statusText: resp.statusText,
|
|
49
49
|
};
|
|
50
50
|
} catch (e) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const status = parseInt(e.code || "400");
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
data,
|
|
57
|
-
ok: false,
|
|
58
|
-
status,
|
|
59
|
-
statusText: e.message,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
51
|
+
const status = parseInt(e?.code) || StatusCodes.BAD_REQUEST;
|
|
52
|
+
const statusText = e?.message || "Unknown error";
|
|
62
53
|
|
|
63
54
|
return {
|
|
64
55
|
data,
|
|
65
56
|
ok: false,
|
|
66
|
-
status
|
|
67
|
-
statusText
|
|
57
|
+
status,
|
|
58
|
+
statusText,
|
|
68
59
|
};
|
|
69
60
|
}
|
|
70
61
|
}
|
package/src/fluent/types.ts
CHANGED
|
@@ -4,11 +4,17 @@
|
|
|
4
4
|
import { KubernetesListObject, KubernetesObject } from "@kubernetes/client-node";
|
|
5
5
|
import { Operation } from "fast-json-patch";
|
|
6
6
|
import type { PartialDeep } from "type-fest";
|
|
7
|
-
|
|
7
|
+
import { RequestInit as UndiciRequestInit } from "undici";
|
|
8
8
|
import { GenericClass, GroupVersionKind } from "../types";
|
|
9
9
|
import { WatchCfg, Watcher } from "./watch";
|
|
10
10
|
import https from "https";
|
|
11
11
|
import { SecureClientSessionOptions } from "http2";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Fetch options and server URL
|
|
15
|
+
*/
|
|
16
|
+
export type K8sConfigPromise = Promise<{ opts: UndiciRequestInit; serverUrl: string | URL }>;
|
|
17
|
+
|
|
12
18
|
/**
|
|
13
19
|
* Agent options for the the http2Watch
|
|
14
20
|
*/
|
package/src/fluent/utils.ts
CHANGED
|
@@ -2,16 +2,78 @@
|
|
|
2
2
|
// SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
|
|
3
3
|
|
|
4
4
|
import { KubeConfig, PatchStrategy } from "@kubernetes/client-node";
|
|
5
|
-
import {
|
|
5
|
+
import { RequestInit } from "node-fetch";
|
|
6
6
|
import { URL } from "url";
|
|
7
|
-
|
|
7
|
+
import { Agent, Dispatcher } from "undici";
|
|
8
|
+
import { Agent as httpsAgent } from "https";
|
|
8
9
|
import { fetch } from "../fetch";
|
|
9
10
|
import { modelToGroupVersionKind } from "../kinds";
|
|
10
11
|
import { GenericClass } from "../types";
|
|
11
|
-
import { ApplyCfg, FetchMethods, Filters } from "./types";
|
|
12
|
+
import { ApplyCfg, FetchMethods, Filters, K8sConfigPromise } from "./types";
|
|
13
|
+
import fs from "fs";
|
|
12
14
|
|
|
13
15
|
const SSA_CONTENT_TYPE = "application/apply-patch+yaml";
|
|
16
|
+
const K8S_SA_TOKEN_PATH = "/var/run/secrets/kubernetes.io/serviceaccount/token";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Get the headers for a request
|
|
20
|
+
*
|
|
21
|
+
* @returns the headers for undici
|
|
22
|
+
*/
|
|
23
|
+
export async function getHeaders(): Promise<Record<string, string>> {
|
|
24
|
+
const token = await getToken();
|
|
25
|
+
const headers: Record<string, string> = {
|
|
26
|
+
"Content-Type": "application/json",
|
|
27
|
+
"User-Agent": "kubernetes-fluent-client",
|
|
28
|
+
};
|
|
14
29
|
|
|
30
|
+
if (token) {
|
|
31
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return headers;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Get the agent for a request
|
|
39
|
+
*
|
|
40
|
+
* @param opts - the request options from node-fetch
|
|
41
|
+
* @returns the agent for undici
|
|
42
|
+
*/
|
|
43
|
+
export function getHTTPSAgent(opts: RequestInit): Dispatcher | undefined {
|
|
44
|
+
// In cluster there will be agent - testing or dev no
|
|
45
|
+
const agentOptions =
|
|
46
|
+
opts.agent instanceof httpsAgent
|
|
47
|
+
? {
|
|
48
|
+
ca: opts.agent.options.ca,
|
|
49
|
+
cert: opts.agent.options.cert,
|
|
50
|
+
key: opts.agent.options.key,
|
|
51
|
+
}
|
|
52
|
+
: {
|
|
53
|
+
ca: undefined,
|
|
54
|
+
cert: undefined,
|
|
55
|
+
key: undefined,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
return new Agent({
|
|
59
|
+
keepAliveMaxTimeout: 600000,
|
|
60
|
+
keepAliveTimeout: 600000,
|
|
61
|
+
bodyTimeout: 0,
|
|
62
|
+
connect: agentOptions,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Read the serviceAccount Token
|
|
67
|
+
*
|
|
68
|
+
* @returns token or null
|
|
69
|
+
*/
|
|
70
|
+
export async function getToken(): Promise<string | null> {
|
|
71
|
+
try {
|
|
72
|
+
return (await fs.promises.readFile(K8S_SA_TOKEN_PATH, "utf8")).trim();
|
|
73
|
+
} catch {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
15
77
|
/**
|
|
16
78
|
* Generate a path to a Kubernetes resource
|
|
17
79
|
*
|
|
@@ -94,7 +156,7 @@ export function pathBuilder<T extends GenericClass>(
|
|
|
94
156
|
* @param method - the HTTP method to use
|
|
95
157
|
* @returns the fetch options and server URL
|
|
96
158
|
*/
|
|
97
|
-
export async function k8sCfg(method: FetchMethods) {
|
|
159
|
+
export async function k8sCfg(method: FetchMethods): K8sConfigPromise {
|
|
98
160
|
const kubeConfig = new KubeConfig();
|
|
99
161
|
kubeConfig.loadFromDefault();
|
|
100
162
|
|
|
@@ -103,21 +165,17 @@ export async function k8sCfg(method: FetchMethods) {
|
|
|
103
165
|
throw new Error("No currently active cluster");
|
|
104
166
|
}
|
|
105
167
|
|
|
106
|
-
//
|
|
107
|
-
const opts = await kubeConfig.applyToFetchOptions({
|
|
108
|
-
method,
|
|
109
|
-
headers: {
|
|
110
|
-
// Set the default content type to JSON
|
|
111
|
-
"Content-Type": "application/json",
|
|
112
|
-
// Set the user agent like kubectl does
|
|
113
|
-
"User-Agent": `kubernetes-fluent-client`,
|
|
114
|
-
},
|
|
115
|
-
});
|
|
168
|
+
// Get TLS Options
|
|
169
|
+
const opts = await kubeConfig.applyToFetchOptions({});
|
|
116
170
|
|
|
117
|
-
//
|
|
118
|
-
|
|
171
|
+
// Transform the TLS options & auth headers, as needed
|
|
172
|
+
const undiciRequestUnit = {
|
|
173
|
+
headers: await getHeaders(),
|
|
174
|
+
method,
|
|
175
|
+
dispatcher: getHTTPSAgent(opts),
|
|
176
|
+
};
|
|
119
177
|
|
|
120
|
-
return { opts, serverUrl: cluster.server };
|
|
178
|
+
return { opts: undiciRequestUnit, serverUrl: cluster.server };
|
|
121
179
|
}
|
|
122
180
|
|
|
123
181
|
/**
|
|
@@ -138,37 +196,38 @@ export async function k8sExec<T extends GenericClass, K>(
|
|
|
138
196
|
payload?: K | unknown,
|
|
139
197
|
applyCfg: ApplyCfg = { force: false },
|
|
140
198
|
) {
|
|
141
|
-
const reconstruct = async (method: FetchMethods) => {
|
|
199
|
+
const reconstruct = async (method: FetchMethods): K8sConfigPromise => {
|
|
142
200
|
const configMethod = method === "LOG" ? "GET" : method;
|
|
143
201
|
const { opts, serverUrl } = await k8sCfg(configMethod);
|
|
144
202
|
const isPost = method === "POST";
|
|
145
|
-
const baseUrl = pathBuilder(serverUrl, model, filters, isPost);
|
|
203
|
+
const baseUrl = pathBuilder(serverUrl.toString(), model, filters, isPost);
|
|
146
204
|
if (method === "LOG") {
|
|
147
205
|
baseUrl.pathname = `${baseUrl.pathname}/log`;
|
|
148
206
|
}
|
|
149
207
|
return {
|
|
150
|
-
|
|
208
|
+
serverUrl: baseUrl,
|
|
151
209
|
opts,
|
|
152
210
|
};
|
|
153
211
|
};
|
|
154
212
|
|
|
155
|
-
const { opts,
|
|
213
|
+
const { opts, serverUrl } = await reconstruct(method);
|
|
214
|
+
const url: URL = serverUrl instanceof URL ? serverUrl : new URL(serverUrl);
|
|
156
215
|
|
|
157
216
|
switch (opts.method) {
|
|
158
217
|
// PATCH_STATUS is a special case that uses the PATCH method on status subresources
|
|
159
218
|
case "PATCH_STATUS":
|
|
160
219
|
opts.method = "PATCH";
|
|
161
220
|
url.pathname = `${url.pathname}/status`;
|
|
162
|
-
(opts.headers as
|
|
221
|
+
(opts.headers as Record<string, string>)["Content-Type"] = PatchStrategy.MergePatch;
|
|
163
222
|
payload = { status: (payload as { status: unknown }).status };
|
|
164
223
|
break;
|
|
165
224
|
|
|
166
225
|
case "PATCH":
|
|
167
|
-
(opts.headers as
|
|
226
|
+
(opts.headers as Record<string, string>)["Content-Type"] = PatchStrategy.JsonPatch;
|
|
168
227
|
break;
|
|
169
228
|
|
|
170
229
|
case "APPLY":
|
|
171
|
-
(opts.headers as
|
|
230
|
+
(opts.headers as Record<string, string>)["Content-Type"] = SSA_CONTENT_TYPE;
|
|
172
231
|
opts.method = "PATCH";
|
|
173
232
|
url.searchParams.set("fieldManager", "pepr");
|
|
174
233
|
url.searchParams.set("fieldValidation", "Strict");
|
package/src/fluent/watch.ts
CHANGED
|
@@ -3,15 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
import { createHash } from "crypto";
|
|
5
5
|
import { EventEmitter } from "events";
|
|
6
|
-
import
|
|
7
|
-
import { RequestInit } from "node-fetch";
|
|
8
|
-
import { Agent, fetch } from "undici";
|
|
6
|
+
import { fetch } from "undici";
|
|
9
7
|
import { fetch as wrappedFetch } from "../fetch";
|
|
10
8
|
import { GenericClass, KubernetesListObject } from "../types";
|
|
11
|
-
import { Filters, WatchAction, WatchPhase } from "./types";
|
|
12
|
-
import { k8sCfg, pathBuilder } from "./utils";
|
|
9
|
+
import { Filters, WatchAction, WatchPhase, K8sConfigPromise } from "./types";
|
|
10
|
+
import { k8sCfg, pathBuilder, getHeaders } from "./utils";
|
|
13
11
|
import { Readable } from "stream";
|
|
14
|
-
import fs from "fs";
|
|
15
12
|
|
|
16
13
|
export enum WatchEvent {
|
|
17
14
|
/** Watch is connected successfully */
|
|
@@ -99,8 +96,6 @@ export class Watcher<T extends GenericClass> {
|
|
|
99
96
|
// Track the list of items in the cache
|
|
100
97
|
#cache = new Map<string, InstanceType<T>>();
|
|
101
98
|
|
|
102
|
-
// Token Path
|
|
103
|
-
#TOKEN_PATH = "/var/run/secrets/kubernetes.io/serviceaccount/token";
|
|
104
99
|
/**
|
|
105
100
|
* Setup a Kubernetes watcher for the specified model and filters. The callback function will be called for each event received.
|
|
106
101
|
* The watch can be aborted by calling {@link Watcher.close} or by calling abort() on the AbortController returned by {@link Watcher.start}.
|
|
@@ -204,19 +199,6 @@ export class Watcher<T extends GenericClass> {
|
|
|
204
199
|
return this.#events;
|
|
205
200
|
}
|
|
206
201
|
|
|
207
|
-
/**
|
|
208
|
-
* Read the serviceAccount Token
|
|
209
|
-
*
|
|
210
|
-
* @returns token or null
|
|
211
|
-
*/
|
|
212
|
-
async #getToken() {
|
|
213
|
-
try {
|
|
214
|
-
return (await fs.promises.readFile(this.#TOKEN_PATH, "utf8")).trim();
|
|
215
|
-
} catch {
|
|
216
|
-
return null;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
202
|
/**
|
|
221
203
|
* Build the URL and request options for the watch.
|
|
222
204
|
*
|
|
@@ -226,11 +208,15 @@ export class Watcher<T extends GenericClass> {
|
|
|
226
208
|
*
|
|
227
209
|
* @returns the URL and request options
|
|
228
210
|
*/
|
|
229
|
-
#buildURL = async (
|
|
211
|
+
#buildURL = async (
|
|
212
|
+
isWatch: boolean,
|
|
213
|
+
resourceVersion?: string,
|
|
214
|
+
continueToken?: string,
|
|
215
|
+
): K8sConfigPromise => {
|
|
230
216
|
// Build the path and query params for the resource, excluding the name
|
|
231
217
|
const { opts, serverUrl } = await k8sCfg("GET");
|
|
232
|
-
|
|
233
|
-
const url = pathBuilder(
|
|
218
|
+
const k8sUrl = serverUrl instanceof URL ? serverUrl.toString() : serverUrl;
|
|
219
|
+
const url = pathBuilder(k8sUrl, this.#model, this.#filters, true);
|
|
234
220
|
|
|
235
221
|
// Enable the watch query param
|
|
236
222
|
if (isWatch) {
|
|
@@ -254,7 +240,7 @@ export class Watcher<T extends GenericClass> {
|
|
|
254
240
|
// Add the abort signal to the request options
|
|
255
241
|
opts.signal = this.#abortController.signal;
|
|
256
242
|
|
|
257
|
-
return { opts, url };
|
|
243
|
+
return { opts, serverUrl: url };
|
|
258
244
|
};
|
|
259
245
|
|
|
260
246
|
/**
|
|
@@ -265,10 +251,10 @@ export class Watcher<T extends GenericClass> {
|
|
|
265
251
|
*/
|
|
266
252
|
#list = async (continueToken?: string, removedItems?: Map<string, InstanceType<T>>) => {
|
|
267
253
|
try {
|
|
268
|
-
const { opts,
|
|
254
|
+
const { opts, serverUrl } = await this.#buildURL(false, undefined, continueToken);
|
|
269
255
|
|
|
270
256
|
// Make the request to list the resources
|
|
271
|
-
const response = await wrappedFetch<KubernetesListObject<InstanceType<T>>>(
|
|
257
|
+
const response = await wrappedFetch<KubernetesListObject<InstanceType<T>>>(serverUrl, opts);
|
|
272
258
|
const list = response.data;
|
|
273
259
|
|
|
274
260
|
// If the request fails, emit an error event and return
|
|
@@ -405,28 +391,6 @@ export class Watcher<T extends GenericClass> {
|
|
|
405
391
|
}
|
|
406
392
|
};
|
|
407
393
|
|
|
408
|
-
static getHTTPSAgent = (opts: RequestInit) => {
|
|
409
|
-
// In cluster there will be agent - testing or dev no
|
|
410
|
-
const agentOptions =
|
|
411
|
-
opts.agent instanceof https.Agent
|
|
412
|
-
? {
|
|
413
|
-
ca: opts.agent.options.ca,
|
|
414
|
-
cert: opts.agent.options.cert,
|
|
415
|
-
key: opts.agent.options.key,
|
|
416
|
-
}
|
|
417
|
-
: {
|
|
418
|
-
ca: undefined,
|
|
419
|
-
cert: undefined,
|
|
420
|
-
key: undefined,
|
|
421
|
-
};
|
|
422
|
-
|
|
423
|
-
return new Agent({
|
|
424
|
-
keepAliveMaxTimeout: 600000,
|
|
425
|
-
keepAliveTimeout: 600000,
|
|
426
|
-
bodyTimeout: 0,
|
|
427
|
-
connect: agentOptions,
|
|
428
|
-
});
|
|
429
|
-
};
|
|
430
394
|
/**
|
|
431
395
|
* Watch for changes to the resource.
|
|
432
396
|
*/
|
|
@@ -436,23 +400,15 @@ export class Watcher<T extends GenericClass> {
|
|
|
436
400
|
await this.#list();
|
|
437
401
|
|
|
438
402
|
// Build the URL and request options
|
|
439
|
-
const { opts,
|
|
440
|
-
|
|
441
|
-
const token = await this.#getToken();
|
|
442
|
-
const headers: Record<string, string> = {
|
|
443
|
-
"Content-Type": "application/json",
|
|
444
|
-
"User-Agent": "kubernetes-fluent-client",
|
|
445
|
-
};
|
|
403
|
+
const { opts, serverUrl } = await this.#buildURL(true, this.#resourceVersion);
|
|
446
404
|
|
|
447
|
-
|
|
448
|
-
headers
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
const response = await fetch(url, {
|
|
452
|
-
headers,
|
|
453
|
-
dispatcher: Watcher.getHTTPSAgent(opts),
|
|
405
|
+
const response = await fetch(serverUrl, {
|
|
406
|
+
headers: await getHeaders(),
|
|
407
|
+
...opts,
|
|
454
408
|
});
|
|
455
409
|
|
|
410
|
+
const url = serverUrl instanceof URL ? serverUrl : new URL(serverUrl);
|
|
411
|
+
|
|
456
412
|
// If the request is successful, start listening for events
|
|
457
413
|
if (response.ok) {
|
|
458
414
|
// Reset the pending reconnect flag
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
apiVersion: apiextensions.k8s.io/v1
|
|
2
|
+
kind: CustomResourceDefinition
|
|
3
|
+
metadata:
|
|
4
|
+
name: datastores.pepr.io
|
|
5
|
+
spec:
|
|
6
|
+
group: pepr.io
|
|
7
|
+
names:
|
|
8
|
+
plural: datastores
|
|
9
|
+
singular: datastore
|
|
10
|
+
kind: Datastore
|
|
11
|
+
shortNames:
|
|
12
|
+
- ds
|
|
13
|
+
scope: Namespaced
|
|
14
|
+
versions:
|
|
15
|
+
- name: v1alpha1
|
|
16
|
+
served: true
|
|
17
|
+
storage: true
|
|
18
|
+
schema:
|
|
19
|
+
openAPIV3Schema:
|
|
20
|
+
type: object
|
|
21
|
+
properties:
|
|
22
|
+
spec:
|
|
23
|
+
type: object
|
|
24
|
+
properties:
|
|
25
|
+
kind:
|
|
26
|
+
type: string
|
|
27
|
+
enum:
|
|
28
|
+
- sqlite
|
|
29
|
+
- valkey
|
|
30
|
+
description: "The type of datastore. Allowed values: sqlite, valkey."
|
|
31
|
+
accessModes:
|
|
32
|
+
type: array
|
|
33
|
+
items:
|
|
34
|
+
type: string
|
|
35
|
+
description: "The access modes for the datastore (e.g., ReadWriteOnce, ReadOnlyMany)."
|
|
36
|
+
capacity:
|
|
37
|
+
type: string
|
|
38
|
+
description: "The capacity of the datastore (e.g., 10Gi)."
|
|
39
|
+
hostPath:
|
|
40
|
+
type: string
|
|
41
|
+
description: "The host path for the datastore storage."
|
|
42
|
+
required:
|
|
43
|
+
- kind
|
|
44
|
+
- accessModes
|
|
45
|
+
- capacity
|
|
46
|
+
- hostPath
|
|
47
|
+
status:
|
|
48
|
+
type: object
|
|
49
|
+
properties:
|
|
50
|
+
observedGeneration:
|
|
51
|
+
type: integer
|
|
52
|
+
phase:
|
|
53
|
+
type: string
|
|
54
|
+
enum:
|
|
55
|
+
- "Failed"
|
|
56
|
+
- "Pending"
|
|
57
|
+
- "Ready"
|
|
58
|
+
subresources:
|
|
59
|
+
status: {}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
apiVersion: apiextensions.k8s.io/v1
|
|
2
|
+
kind: CustomResourceDefinition
|
|
3
|
+
metadata:
|
|
4
|
+
name: webapps.pepr.io
|
|
5
|
+
spec:
|
|
6
|
+
group: pepr.io
|
|
7
|
+
versions:
|
|
8
|
+
- name: v1alpha1
|
|
9
|
+
served: true
|
|
10
|
+
storage: true
|
|
11
|
+
subresources:
|
|
12
|
+
status: {}
|
|
13
|
+
schema:
|
|
14
|
+
openAPIV3Schema:
|
|
15
|
+
type: object
|
|
16
|
+
properties:
|
|
17
|
+
apiVersion:
|
|
18
|
+
type: string
|
|
19
|
+
kind:
|
|
20
|
+
type: string
|
|
21
|
+
metadata:
|
|
22
|
+
type: object
|
|
23
|
+
spec:
|
|
24
|
+
required:
|
|
25
|
+
- theme
|
|
26
|
+
- language
|
|
27
|
+
- replicas
|
|
28
|
+
type: object
|
|
29
|
+
properties:
|
|
30
|
+
theme:
|
|
31
|
+
type: string
|
|
32
|
+
description: "Theme defines the theme of the web application, either dark or light."
|
|
33
|
+
enum:
|
|
34
|
+
- "dark"
|
|
35
|
+
- "light"
|
|
36
|
+
language:
|
|
37
|
+
type: string
|
|
38
|
+
description: "Language defines the language of the web application, either English (en) or Spanish (es)."
|
|
39
|
+
enum:
|
|
40
|
+
- "en"
|
|
41
|
+
- "es"
|
|
42
|
+
replicas:
|
|
43
|
+
type: integer
|
|
44
|
+
description: "Replicas is the number of desired replicas."
|
|
45
|
+
status:
|
|
46
|
+
type: object
|
|
47
|
+
properties:
|
|
48
|
+
observedGeneration:
|
|
49
|
+
type: integer
|
|
50
|
+
phase:
|
|
51
|
+
type: string
|
|
52
|
+
enum:
|
|
53
|
+
- "Failed"
|
|
54
|
+
- "Pending"
|
|
55
|
+
- "Ready"
|
|
56
|
+
scope: Namespaced
|
|
57
|
+
names:
|
|
58
|
+
plural: webapps
|
|
59
|
+
singular: webapp
|
|
60
|
+
kind: WebApp
|
|
61
|
+
shortNames:
|
|
62
|
+
- wa
|