openk8s 0.0.1 → 1.0.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.
Files changed (35) hide show
  1. package/README.md +194 -40
  2. package/bin/openk8s.js +2 -0
  3. package/package.json +52 -6
  4. package/src/app/app-state.ts +461 -0
  5. package/src/app/app.tsx +708 -0
  6. package/src/app/components/inspector.tsx +449 -0
  7. package/src/app/components/kind-rows.tsx +66 -0
  8. package/src/app/components/notification-tray.tsx +59 -0
  9. package/src/app/components/overlays/delete-confirm-overlay.tsx +79 -0
  10. package/src/app/components/overlays/helm-rollback-overlay.tsx +86 -0
  11. package/src/app/components/overlays/index.ts +12 -0
  12. package/src/app/components/overlays/logs-dialog.tsx +303 -0
  13. package/src/app/components/overlays/port-forward-overlay.tsx +184 -0
  14. package/src/app/components/overlays/scale-dialog.tsx +96 -0
  15. package/src/app/components/overlays/select-overlay.tsx +68 -0
  16. package/src/app/components/overlays/shared.tsx +18 -0
  17. package/src/app/components/port-forwards-tray.tsx +57 -0
  18. package/src/app/components/resource-rows.tsx +120 -0
  19. package/src/app/hooks/use-app-keyboard.ts +723 -0
  20. package/src/app/hooks/use-app-side-effects.ts +39 -0
  21. package/src/app/hooks/use-clipboard.ts +54 -0
  22. package/src/app/hooks/use-data-fetching.ts +366 -0
  23. package/src/app/hooks/use-log-stream.ts +113 -0
  24. package/src/app/hooks/use-port-forward.ts +149 -0
  25. package/src/app/persistence.ts +44 -0
  26. package/src/app/theme.ts +95 -0
  27. package/src/app/use-polling-tick.ts +27 -0
  28. package/src/app/utils.ts +274 -0
  29. package/src/index.tsx +8 -0
  30. package/src/lib/k8s/k8s-format.ts +42 -0
  31. package/src/lib/k8s/resource-detail-builder.ts +545 -0
  32. package/src/lib/k8s/resource-parser.ts +308 -0
  33. package/src/lib/k8s/types.ts +164 -0
  34. package/src/lib/kubectl/kubectl-service.ts +1116 -0
  35. package/src/lib/kubectl/spawn-utils.ts +81 -0
@@ -0,0 +1,81 @@
1
+ import { spawn, type ChildProcess, type StdioOptions } from "node:child_process";
2
+
3
+ const DEFAULT_TIMEOUT_MS = 15_000;
4
+
5
+ export interface RunCommandOptions {
6
+ command: string;
7
+ args: string[];
8
+ timeoutMs?: number | undefined;
9
+ }
10
+
11
+ export interface CommandResult {
12
+ stdout: string;
13
+ stderr: string;
14
+ }
15
+
16
+ export function runCommand(options: RunCommandOptions): Promise<CommandResult> {
17
+ return new Promise((resolve, reject) => {
18
+ let settled = false;
19
+ const child = spawn(options.command, options.args, { env: process.env, stdio: ["pipe", "pipe", "pipe"] });
20
+ const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
21
+
22
+ const timeoutId = setTimeout(() => {
23
+ if (settled) {
24
+ return;
25
+ }
26
+ settled = true;
27
+ child.kill("SIGTERM");
28
+ reject(new Error(`${options.command} ${options.args.slice(0, 4).join(" ")} timed out after ${timeoutMs / 1_000}s`));
29
+ }, timeoutMs);
30
+
31
+ let stdout = "";
32
+ let stderr = "";
33
+
34
+ child.stdout.on("data", (chunk: Buffer | string) => {
35
+ stdout += chunk.toString();
36
+ });
37
+
38
+ child.stderr.on("data", (chunk: Buffer | string) => {
39
+ stderr += chunk.toString();
40
+ });
41
+
42
+ child.on("error", (error) => {
43
+ clearTimeout(timeoutId);
44
+ settled = true;
45
+ reject(error);
46
+ });
47
+
48
+ child.on("close", (code) => {
49
+ clearTimeout(timeoutId);
50
+
51
+ if (settled) {
52
+ return;
53
+ }
54
+
55
+ if (code === 0) {
56
+ settled = true;
57
+ resolve({ stdout, stderr });
58
+ return;
59
+ }
60
+
61
+ settled = true;
62
+ const message = stderr.trim() || `${options.command} ${options.args.join(" ")} failed`;
63
+ reject(new Error(message));
64
+ });
65
+ });
66
+ }
67
+
68
+ export function runText(options: RunCommandOptions): Promise<string> {
69
+ return runCommand(options).then((result) => result.stdout);
70
+ }
71
+
72
+ export function runJson<T>(options: RunCommandOptions): Promise<T> {
73
+ return runCommand(options).then((result) => JSON.parse(result.stdout) as T);
74
+ }
75
+
76
+ export function startPersistentProcess(options: { command: string; args: string[]; stdio?: StdioOptions }): ChildProcess {
77
+ return spawn(options.command, options.args, {
78
+ env: process.env,
79
+ stdio: options.stdio ?? ["ignore", "pipe", "pipe"],
80
+ });
81
+ }