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

How to set the terminal stty cols and rows through exec API ? #3641

Closed
gohonsen opened this issue Aug 16, 2024 · 11 comments
Closed

How to set the terminal stty cols and rows through exec API ? #3641

gohonsen opened this issue Aug 16, 2024 · 11 comments
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines.

Comments

@gohonsen
Copy link

Describe the bug
Hey, I want to enter the k8s pod container to run shell commands through web terminal, but I found that after the web terminal page size changed, I cann't synchronize set terminal size through exec API, and the page display is disordered.
Is there any way to set the terminal stty cols and rows ? Thanks a lot

Client Version
18.0.1

Kubernetes Version
v1.28.0

Java Version
Java 8

@brendandburns
Copy link
Contributor

This isn't currently supported. You can read resize messages from the stream via Exec.getResizeStream() but you can't write to that stream currently.

We need something like the following in the Javascript client:

https://github.com/kubernetes-client/javascript/blob/70f651ca7e5c8d3647c071ab4f6aeb89f4ccae14/src/exec.ts#L66

We'd be happy to take a PR for this support.

@brendandburns
Copy link
Contributor

brendandburns commented Aug 16, 2024

Alternately, you could use ExecProcess.getInputStream(4).write("{ 'width': foo, 'height': bar}") that should work.

public OutputStream getResizeStream() {

@gohonsen
Copy link
Author

gohonsen commented Aug 21, 2024

@brendandburns I got it, the codes like this:

Exec.ExecutionBuilder executionBuilder = k8sExec.newExecutionBuilder(namespace, podName, new String[]{shellPath});
executionBuilder.setTty(tty);
executionBuilder.setContainer(containerName);
execProcess = (Exec.ExecProcess) executionBuilder.execute();
resizeOutStream = execProcess.getResizeStream();
outputStream = execProcess.getOutputStream();
inputStream = execProcess.getInputStream();
String resize = "{"Width":" + cols + ","Height":" + rows + "}";
resizeOutStream.write(resize.getBytes());

and it works, thanks.

@brendandburns
Copy link
Contributor

Glad it's working. Making this a little easier could be a good first issue, so I'll leave this open in case someone wants to take it on.

@brendandburns brendandburns added the good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. label Aug 21, 2024
@sriganeshres
Copy link

@brendandburns i want to work on this issue. But the problem i cant setup the code properly can you send me the steps to setup the code.

@sriganeshres
Copy link

image
i have done this till now.

thanks

@sriganeshres
Copy link

then i did this
image
next how should i proceed to do the required changes and test and contribute. It is some what tricky to a begginer to this code base. can you kindly please help me.

@brendandburns
Copy link
Contributor

@sriganeshres the second command is to regenerate the code, you don't need to do that.

What you need to do is edit this file:

you may not use this file except in compliance with the License.

To add a function like setTerminalSize(int widthColumns, int heightColumns) and which does code similar to #3641 (comment).

If you need help with git or making a PR, please see instructions here: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request?tool=cli

@sriganeshres
Copy link

thank you @brendandburns

@sriganeshres
Copy link

@brendandburns I have added a PR #3657 for this. Thanks for the help and understanding.

@brendandburns
Copy link
Contributor

@sriganeshres thank you. In the future, you can just push new commits to the same branch and this PR will update, you don't need to create a new PR. I will close this PR given the new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines.
Projects
None yet
Development

No branches or pull requests

3 participants