-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpod-exec-tty.ts
executable file
·44 lines (36 loc) · 1.4 KB
/
pod-exec-tty.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env -S deno run --unstable --allow-env --allow-read --allow-net
import { tunnelBeta, makeClientProviderChain } from '../client.ts';
import { CoreV1Api } from '../builtin/core@v1/mod.ts';
// Set up an experimental client which can use Websockets
const client = await makeClientProviderChain(tunnelBeta.WebsocketRestClient).getClient();
const coreApi = new CoreV1Api(client);
// Launch a process into a particular container
const tunnel = await coreApi
.namespace('media')
.podExec('sabnzbd-srv-0', {
command: ['bash', '-i'],
stdin: true,
stdout: true,
tty: true,
});
// Report the initial terminal size
await tunnel.ttySetSize(Deno.consoleSize());
// Set up our parent tty for passthru
Deno.stdin.setRaw(true, { cbreak: true });
// Pass several signals into the container tty
Deno.addSignalListener('SIGINT', () => tunnel.ttyWriteSignal('INTR'));
Deno.addSignalListener('SIGQUIT', () => tunnel.ttyWriteSignal('QUIT'));
Deno.addSignalListener('SIGTSTP', () => tunnel.ttyWriteSignal('SUSP'));
// Connect our stdin/stdout with the tunnel's
await Deno.stdin.readable.pipeThrough({
writable: tunnel.stdin,
readable: tunnel.stdout,
}).pipeTo(Deno.stdout.writable);
// Copy the remote command's exit code, if any
const status = await tunnel.status;
if (typeof status.exitCode == 'number') {
Deno.exit(status.exitCode);
} else {
console.error('Kubernetes says:', status.message);
Deno.exit(1);
}