Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exec example for copying files to pod #67

Closed
cmosgh opened this issue Aug 1, 2018 · 4 comments
Closed

Exec example for copying files to pod #67

cmosgh opened this issue Aug 1, 2018 · 4 comments

Comments

@cmosgh
Copy link
Contributor

cmosgh commented Aug 1, 2018

Managed to download file from pod by creating a writestream and using it as stdout

const downloadCommand = ["tar", "czpf", "-", `${remotePath}`];
const localFile = fs.createWriteStream(localPath);
Exec.exec(nameSpace, podName, containerName, downloadCommand, localFile, null, null, false);

But I wouldn't know how to upload a file/folder to the container.

Anyone can help me out?

@brendandburns
Copy link
Contributor

brendandburns commented Aug 1, 2018

The exec command takes streams for stdin

If you pass a stream that contains the tar file as the stdin stream and the command should be a command that untars from stdin.

Hope that helps.

@cmosgh
Copy link
Contributor Author

cmosgh commented Aug 2, 2018

@brendandburns Any ideas what am I doing wrong?

const file = fs.createReadStream(tmpTarResultFile);//which I have and I can see it is a proper tgz
const uploadCommand = ["tar", "xzf", "-"];
Exec.exec(namespace, podName, containerName, uploadCommand, null, null, file, false);

And I am always getting

buffer.js:186
    throw new TypeError('"value" argument must not be a number');
    ^

TypeError: "value" argument must not be a number
    at Function.Buffer.from (buffer.js:186:11)
    at ReadStream.stdin.on (/pathToProject/node_modules/@kubernetes/client-node/dist/web-socket-handler.js:42:33)
    at emitOne (events.js:116:13)
    at ReadStream.emit (events.js:211:7)
    at ReadStream.Readable.read (_stream_readable.js:475:10)
    at flow (_stream_readable.js:846:34)
    at resume_ (_stream_readable.js:828:3)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickDomainCallback (internal/process/next_tick.js:218:9)

@cmosgh
Copy link
Contributor Author

cmosgh commented Aug 2, 2018

Done some digging and it seems that
https://github.com/kubernetes-client/javascript/blob/master/node-client/src/web-socket-handler.ts#L46 should be

const buff = Buffer.from(data, data.length + 1);

instead of

const buff = Buffer.from(data.length + 1);

And that way it works

@cmosgh
Copy link
Contributor Author

cmosgh commented Aug 2, 2018

Created PR #69 and followed the instructions for cla/linuxfoundation but it still says its not ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants