Skip to content

Commit

Permalink
Merge pull request kubernetes-client#197 from TomNeyland/command-argu…
Browse files Browse the repository at this point in the history
…ments

Support commands with arguments in Exec
  • Loading branch information
k8s-ci-robot authored Jan 31, 2019
2 parents 63cbc28 + d77d2ec commit 7c32d9a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ export class Exec {
}
}

// TODO: make command an array and support multiple args
/**
* @param {string} namespace - The namespace of the pod to exec the command inside.
* @param {string} podName - The name of the pod to exec the command inside.
* @param {string} containerName - The name of the container in the pod to exec the command inside.
* @param {string} command - The command to execute.
* @param {(string|string[])} command - The command or command and arguments to execute.
* @param {stream.Writable} stdout - The stream to write stdout data from the command.
* @param {stream.Writable} stderr - The stream to write stderr data from the command.
* @param {stream.Readable} stdin - The strream to write stdin data into the command.
Expand All @@ -31,7 +30,7 @@ export class Exec {
* A callback to received the status (e.g. exit code) from the command, optional.
* @return {string} This is the result
*/
public async exec(namespace: string, podName: string, containerName: string, command: string,
public async exec(namespace: string, podName: string, containerName: string, command: string | string[],
stdout: stream.Writable | null, stderr: stream.Writable | null, stdin: stream.Readable | null,
tty: boolean,
statusCallback?: (status: V1Status) => void): Promise<WebSocket> {
Expand Down
7 changes: 7 additions & 0 deletions src/exec_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('Exec', () => {
const pod = 'somepod';
const container = 'container';
const cmd = 'command';
const cmdArray = ['command', 'arg1', 'arg2'];
const path = `/api/v1/namespaces/${namespace}/pods/${pod}/exec`;

await exec.exec(
Expand All @@ -48,6 +49,12 @@ describe('Exec', () => {
namespace, pod, container, cmd, null, errStream, isStream, true);
args = `stdout=false&stderr=true&stdin=true&tty=true&command=${cmd}&container=${container}`;
verify(fakeWebSocket.connect(`${path}?${args}`, null, anyFunction())).called();

await exec.exec(
namespace, pod, container, cmdArray, null, errStream, isStream, true);
// tslint:disable-next-line:max-line-length
args = `stdout=false&stderr=true&stdin=true&tty=true&command=${cmdArray[0]}&command=${cmdArray[1]}&command=${cmdArray[2]}&container=${container}`;
verify(fakeWebSocket.connect(`${path}?${args}`, null, anyFunction())).called();
});

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

0 comments on commit 7c32d9a

Please sign in to comment.