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

When SSHing into a KubevirtCI, long terminal commands are not wrapped, therefore looking weird #1280

Open
iholder101 opened this issue Sep 15, 2024 · 7 comments
Labels
good-first-issue Identifies an issue that has been specifically created or selected for first-time contributors. kind/bug

Comments

@iholder101
Copy link
Contributor

What happened:
When SSHing into a KubevirtCI node, if the command is long enough, it is not warpped by instead being messy overriding the beginning of the command:

> ./cluster-up/ssh.sh node02
Last login: Sun Sep 15 08:35:14 2024 from 192.168.66.2

# This is short enough, looking good
[vagrant@node02 ~]$ find -regex '.*pod.*' -type d -exec cat {}/memory.max \;
[vagrant@node02 ~]$

# Adding `&& ls {}` at the end of the find exec command
{} \;t@node02 ~]$                                                            s \;                                                                          l 
\;agrant@node02 ~]$ find -regex '.*pod.*' -type d -exec cat {}/memory.max &&  \;

This is how it looks like:
image

What you expected to happen:
The command to be wrapped into a new line in a human-readable way.

How to reproduce it (as minimally and precisely as possible):
As explained above. 100% reproducible.

Environment:

  • KubeVirt version (use virtctl version): v1.3 (main)
@iholder101
Copy link
Contributor Author

/label good-first-issue

@kubevirt-bot kubevirt-bot added the good-first-issue Identifies an issue that has been specifically created or selected for first-time contributors. label Sep 15, 2024
Copy link

dosubot bot commented Sep 15, 2024

The issue you're experiencing with long terminal commands not wrapping correctly when SSHing into a KubeVirtCI node could be related to terminal settings or configurations. Here are a few things you can check or try:

  1. Terminal Settings: Ensure that your local terminal emulator settings are configured to handle line wrapping correctly. This can usually be found in the preferences or settings menu of your terminal application.

  2. Terminal Type: Verify that the terminal type (TERM environment variable) is set correctly. You can check this by running echo $TERM in your SSH session. Common values are xterm, xterm-256color, etc. You can try setting it explicitly before running your commands:

    export TERM=xterm-256color
  3. SSH Configuration: The virtctl ssh command and the underlying SSH configuration might influence terminal behavior. Ensure that the SSH session requests a pseudo-terminal (PTY) and handles window size changes correctly. The KubeVirt repository has code comments related to these configurations:

    // requestPty requests a pseudo-terminal for the SSH session and sets up window size change handling.
    func requestPty(session *ssh.Session) error {
        w, h, err := term.GetSize(int(os.Stdin.Fd()))
        if err != nil {
            return err
        }
    
        if err := session.RequestPty(
            os.Getenv("TERM"),
            h, w,
            ssh.TerminalModes{},
        ); err != nil {
            return err
        }
    
        go resizeSessionOnWindowChange(session, os.Stdin.Fd())
    
        return nil
    }

    This ensures that the terminal size is correctly set and adjusted during the SSH session [1].

  4. Shell Configuration: Check if there are any custom shell configurations or profiles on the KubeVirtCI nodes that might affect terminal behavior. This includes .bashrc, .bash_profile, or other shell initialization files.

  5. Known Issues: There have been previous discussions and fixes related to SSH session display problems in the KubeVirt repository. For example, PRs Properly manage knownhosts files kubevirt#7421, [virtctl] Bump crypto ssh to make the preauth authentiation for some newer ssh server configurations work kubevirt#6854, [virtctl] Don't change terminal settings if not run in a terminal kubevirt#6891, and [release-0.48] [virtctl] Don't change terminal settings if not run in a terminal kubevirt#6902 address various SSH and terminal issues [2].

By checking these configurations and settings, you may be able to resolve the issue with command wrapping in your SSH sessions.

To continue talking to Dosu, mention @dosu.

@Acedus
Copy link

Acedus commented Sep 16, 2024

Seems like a PTY issue along with SIGWINCH not being handled properly.
Execing into the node's container and then running ssh.sh seems to work fine.
Also verified this by doing the following:

$ podman exec -it <kubevirtci container> sh
$ trap 'echo test' WINCH

Resizing the terminal doesn't do anything.

@akalenyu
Copy link
Contributor

TBH this may be a general RFE for virtctl console (virtctl ssh seems to be aware according to dosu)

Back to the subject, for the kubevirtci ssh script, I don't think we're aware of SIGWINCH or try to do any resizing at all.
As a quick W/A one could run stty size on the host machine and apply the same values on the kvci node

@brianmcarey
Copy link
Member

@iholder101 - does this belong more to kubevirt/kubevirtci? I can transfer the issue if you want?

@iholder101
Copy link
Contributor Author

@iholder101 - does this belong more to kubevirt/kubevirtci? I can transfer the issue if you want?

Yes, feel free to do so if you think that's more appropriate! Thanks!

@brianmcarey brianmcarey transferred this issue from kubevirt/kubevirt Sep 24, 2024
@Acedus
Copy link

Acedus commented Oct 8, 2024

TBH this may be a general RFE for virtctl console (virtctl ssh seems to be aware according to dosu)

FYI @akalenyu (this interested me). The only feasible way I can think of achieving this in the current setup where the serial console is accessed through a virt-handler unix socket connection is to execute stty size directly upon receiving a SIGWINCH event. This is due to the connection being to a character device, which makes it impossible to perform more complex operations like sending an ioctl TIOCGWINSZ to the tty. While the VNC protocol supports terminal resizing, serial consoles simply don't.

Another way (hypothetically speaking) is to change the way by which virt-handler communicates with the device, making it a device on its side instead of a unix socket and then sending ioctl to that device.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good-first-issue Identifies an issue that has been specifically created or selected for first-time contributors. kind/bug
Projects
None yet
Development

No branches or pull requests

5 participants