Skip to content

Commit

Permalink
chore: patch kubernetes-client with health class (podman-desktop#10074)
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe Martin <[email protected]>
  • Loading branch information
feloy authored Nov 25, 2024
1 parent 0f9c9f9 commit ef90803
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 19 deletions.
100 changes: 100 additions & 0 deletions patches/@[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,103 @@ index 3f7f6d2942d046a375f01a6c5a49d8b5cad8e2a7..f36613e12c280266768f5e7575c0970c
case 'ADDED':
case 'MODIFIED':
addOrUpdateObject(this.objects, obj, this.callbackCache[informer_1.ADD].slice(), this.callbackCache[informer_1.UPDATE].slice());
diff --git a/dist/health.d.ts b/dist/health.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..aeedff6524c952b712330d02738898a99071632d
--- /dev/null
+++ b/dist/health.d.ts
@@ -0,0 +1,10 @@
+import { KubeConfig } from './config';
+import { RequestOptions } from 'node:https';
+export declare class Health {
+ config: KubeConfig;
+ constructor(config: KubeConfig);
+ readyz(opts: RequestOptions): Promise<boolean>;
+ livez(opts: RequestOptions): Promise<boolean>;
+ private healthz;
+ private check;
+}
diff --git a/dist/health.js b/dist/health.js
new file mode 100644
index 0000000000000000000000000000000000000000..bdd7eb7e3105431a2195c2a3f63a28a3598ce4d1
--- /dev/null
+++ b/dist/health.js
@@ -0,0 +1,54 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.Health = void 0;
+const tslib_1 = require("tslib");
+const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
+class Health {
+ constructor(config) {
+ this.config = config;
+ }
+ async readyz(opts) {
+ return this.check('/readyz', opts);
+ }
+ async livez(opts) {
+ return this.check('/livez', opts);
+ }
+ async healthz(opts) {
+ return this.check('/healthz', opts);
+ }
+ async check(path, opts) {
+ const cluster = this.config.getCurrentCluster();
+ if (!cluster) {
+ throw new Error('No currently active cluster');
+ }
+ const requestURL = new URL(cluster.server + path);
+ const requestInit = await this.config.applyToFetchOptions(opts);
+ if (opts.signal) {
+ requestInit.signal = opts.signal;
+ }
+ requestInit.method = 'GET';
+ try {
+ const response = await (0, node_fetch_1.default)(requestURL.toString(), requestInit);
+ const status = response.status;
+ if (status === 200) {
+ return true;
+ }
+ if (status === 404) {
+ if (path === '/healthz') {
+ // /livez/readyz return 404 and healthz also returns 404, let's consider it is live
+ return true;
+ }
+ return this.healthz(opts);
+ }
+ return false;
+ }
+ catch (err) {
+ if (err instanceof Error && err.name === 'AbortError') {
+ throw err;
+ }
+ throw new Error('Error occurred in health request');
+ }
+ }
+}
+exports.Health = Health;
+//# sourceMappingURL=health.js.map
\ No newline at end of file
diff --git a/dist/index.d.ts b/dist/index.d.ts
index 04f5e65e76c7cec21d02d29613e6ed04ff72c79f..2f1798f1c85920e7c3c425db1cab225eed72f2b5 100644
--- a/dist/index.d.ts
+++ b/dist/index.d.ts
@@ -14,5 +14,6 @@ export * from './cp';
export * from './patch';
export * from './metrics';
export * from './object';
+export * from './health';
export { ConfigOptions, User, Cluster, Context } from './config_types';
export { AbortError, FetchError } from 'node-fetch';
diff --git a/dist/index.js b/dist/index.js
index 9c3ad1c9cbe64251c4e7cd6de0ebb4f5543243f6..64d0491a7df5ca623f0aacb0f251a43a4de5e017 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -18,6 +18,7 @@ tslib_1.__exportStar(require("./cp"), exports);
tslib_1.__exportStar(require("./patch"), exports);
tslib_1.__exportStar(require("./metrics"), exports);
tslib_1.__exportStar(require("./object"), exports);
+tslib_1.__exportStar(require("./health"), exports);
// Export AbortError and FetchError so that instanceof checks in user code will definitely use the same instances
var node_fetch_1 = require("node-fetch");
Object.defineProperty(exports, "AbortError", { enumerable: true, get: function () { return node_fetch_1.AbortError; } });
38 changes: 19 additions & 19 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ef90803

Please sign in to comment.