Skip to content

Commit 7c32d9a

Browse files
authored
Merge pull request #197 from TomNeyland/command-arguments
Support commands with arguments in Exec
2 parents 63cbc28 + d77d2ec commit 7c32d9a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/exec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ export class Exec {
1717
}
1818
}
1919

20-
// TODO: make command an array and support multiple args
2120
/**
2221
* @param {string} namespace - The namespace of the pod to exec the command inside.
2322
* @param {string} podName - The name of the pod to exec the command inside.
2423
* @param {string} containerName - The name of the container in the pod to exec the command inside.
25-
* @param {string} command - The command to execute.
24+
* @param {(string|string[])} command - The command or command and arguments to execute.
2625
* @param {stream.Writable} stdout - The stream to write stdout data from the command.
2726
* @param {stream.Writable} stderr - The stream to write stderr data from the command.
2827
* @param {stream.Readable} stdin - The strream to write stdin data into the command.
@@ -31,7 +30,7 @@ export class Exec {
3130
* A callback to received the status (e.g. exit code) from the command, optional.
3231
* @return {string} This is the result
3332
*/
34-
public async exec(namespace: string, podName: string, containerName: string, command: string,
33+
public async exec(namespace: string, podName: string, containerName: string, command: string | string[],
3534
stdout: stream.Writable | null, stderr: stream.Writable | null, stdin: stream.Readable | null,
3635
tty: boolean,
3736
statusCallback?: (status: V1Status) => void): Promise<WebSocket> {

src/exec_test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ describe('Exec', () => {
2222
const pod = 'somepod';
2323
const container = 'container';
2424
const cmd = 'command';
25+
const cmdArray = ['command', 'arg1', 'arg2'];
2526
const path = `/api/v1/namespaces/${namespace}/pods/${pod}/exec`;
2627

2728
await exec.exec(
@@ -48,6 +49,12 @@ describe('Exec', () => {
4849
namespace, pod, container, cmd, null, errStream, isStream, true);
4950
args = `stdout=false&stderr=true&stdin=true&tty=true&command=${cmd}&container=${container}`;
5051
verify(fakeWebSocket.connect(`${path}?${args}`, null, anyFunction())).called();
52+
53+
await exec.exec(
54+
namespace, pod, container, cmdArray, null, errStream, isStream, true);
55+
// tslint:disable-next-line:max-line-length
56+
args = `stdout=false&stderr=true&stdin=true&tty=true&command=${cmdArray[0]}&command=${cmdArray[1]}&command=${cmdArray[2]}&container=${container}`;
57+
verify(fakeWebSocket.connect(`${path}?${args}`, null, anyFunction())).called();
5158
});
5259

5360
it('should correctly attach to streams', async () => {

0 commit comments

Comments
 (0)