forked from kubernetes-client/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexec.ts
More file actions
34 lines (30 loc) · 1.3 KB
/
exec.ts
File metadata and controls
34 lines (30 loc) · 1.3 KB
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
import querystring = require('querystring');
import stream = require('stream');
import { WebSocketHandler } from './web-socket-handler';
import { KubeConfig } from './config';
export class Exec {
'handler': WebSocketHandler;
public constructor(config: KubeConfig) {
this.handler = new WebSocketHandler(config);
}
// TODO: make command an array and support multiple args
public async exec(namespace: string, podName: string, containerName: string, command: string, stdout: stream.Writable | any, stderr: stream.Writable | any, stdin: stream.Readable | any, tty: boolean): Promise<WebSocket> {
var query = {
stdout: stdout != null,
stderr: stderr != null,
stdin: stdin != null,
tty: tty,
command: command,
container: containerName
}
var queryStr = querystring.stringify(query);
var path = `/api/v1/namespaces/${namespace}/pods/${podName}/exec?${queryStr}`;
var conn = await this.handler.connect(path, null, (stream: number, buff: Buffer) => {
WebSocketHandler.handleStandardStreams(stream, buff, stdout, stderr);
});
if (stdin != null) {
WebSocketHandler.handleStandardInput(conn, stdin);
}
return conn as WebSocket;
}
}