kubevirt / kubevirtci

Contains cluster definitions and client tools to quickly spin up and destroy ephemeral and scalable k8s and ocp clusters for testing
Apache License 2.0
82 stars 119 forks source link

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

Open iholder101 opened 1 month ago

iholder101 commented 1 month ago

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:

iholder101 commented 1 month ago

/label good-first-issue

dosubot[bot] commented 1 month ago

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 kubevirt/kubevirt#7421, kubevirt/kubevirt#6854, kubevirt/kubevirt#6891, and kubevirt/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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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

iholder101 commented 1 month ago

@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!

Acedus commented 2 weeks ago

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.