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

Enable libkrun provider to open a debug console #22759

Merged
merged 1 commit into from
Jun 12, 2024

Conversation

slp
Copy link
Contributor

@slp slp commented May 20, 2024

When running with "log-level=debug" and libkrun as machine provider, spawn a Terminal to execute "krunkit" to enable users to have full access to the VMs console for debugging purposes.

Users obtain an interactive, text console with scrollback. It's possible to interact with both the kernel and GRUB2. To obtain even additional debugging information, users can add "console=hvc0" to the linux kernel command line through GRUB2 (it may be worth considering extending the initial configuration of the VM to add that argument by default).

Does this PR introduce a user-facing change?

None

Copy link

Ephemeral COPR build failed. @containers/packit-build please check.

@mheon
Copy link
Member

mheon commented May 20, 2024

I'm not sure I like adding significant side effects to --log-level=debug... Can't this be another option?

Comment on lines 293 to 297
os.Chmod(kdFile.Path, 0744)

f.WriteString("#!/bin/sh\n")
f.WriteString(fmt.Sprintf("exec %s", strings.Join(cmd.Args, " ")))
f.Close()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must check errors

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, wil fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

os.Chmod(kdFile.Path, 0744)

f.WriteString("#!/bin/sh\n")
f.WriteString(fmt.Sprintf("exec %s", strings.Join(cmd.Args, " ")))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strings.Join() on the Args will not work, this does not handle special chars/spaces etc... and will just break with hard to diagnose errors.

I am not sure what the purpose of spawning another terminal is, couldn't we just attach it to the current podman machine start command stdout/err?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strings.Join() on the Args will not work, this does not handle special chars/spaces etc... and will just break with hard to diagnose errors.

What's the preferred way to do it?

I am not sure what the purpose of spawning another terminal is, couldn't we just attach it to the current podman machine start command stdout/err?

I think the UX is significantly better this way. Stealing podman's stdout/stdin feels weird, I would expect podman to display debugging messages and not be interactive, just as happens with other provides.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strings.Join() on the Args will not work, this does not handle special chars/spaces etc... and will just break with hard to diagnose errors.

What's the preferred way to do it?

I don't think there is any ready to use interface for writing string slices arguments as shell escaped args. Looping over the args and using fmt.Sprintf("%q",arg) may work although I am unsure if it handles quoting like the shell.

But maybe stepping back why do you have to create this tmp script anyway, can't you append the args to the terminal command?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what the purpose of spawning another terminal is, couldn't we just attach it to the current podman machine start command stdout/err?

I think the UX is significantly better this way. Stealing podman's stdout/stdin feels weird, I would expect podman to display debugging messages and not be interactive, just as happens with other provides.

But isn't this a fundamental different behaviour here, you are spawning the full krun in another terminal unlike vfkit which is started as direct child and then opens a GUI window.

We don't do it today but I think we should read stderr in order to return the error strings to the user if something fails. I don't see how this would work with your solution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is any ready to use interface for writing string slices arguments as shell escaped args. Looping over the args and using fmt.Sprintf("%q",arg) may work although I am unsure if it handles quoting like the shell.

Did it this way in v2, thanks!

But maybe stepping back why do you have to create this tmp script anyway, can't you append the args to the terminal command?

On macOS, /usr/bin/open allows you to pass arguments to Terminal itself but, AFAIK, there isn't a way to tell Terminal to pass any arguments to command being executed on it. Ref: https://stackoverflow.com/questions/29510815/how-to-pass-command-line-arguments-to-a-program-run-with-the-open-command

@baude
Copy link
Member

baude commented May 31, 2024

I think @slp is on the right track here. What he is proposing follows the same model as the other providers. Paul's point about how the various providers are or are not children and their subsequent "terminals" is also valid. But I think this is the closest we have; and not having this function, of a spawned terminal, is more of a risk that anything.

Long term the hope is that all providers would drop a boot.log file which would show the last boot up, similar to capturing the serial console output. But we need an interactive terminal with libkrun today.

@slp my advice is to address any code reviews and get this passing tests. Thanks for the contribution.

@rhatdan
Copy link
Member

rhatdan commented Jun 6, 2024

@Luap99 PTAL

@slp
Copy link
Contributor Author

slp commented Jun 6, 2024

I think we need here the "No New Tests" label to have CI to move forward.

return nil, nil, err
}
for arg := range cmd.Args {
_, err = f.WriteString(fmt.Sprintf("%q", arg))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you never add a space between the args so I don't see how this can work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't push the latest amend, sorry.

@rhatdan rhatdan added the No New Tests Allow PR to proceed without adding regression tests label Jun 6, 2024
When running with "log-level=debug" and libkrun as machine provider,
spawn a Terminal to execute "krunkit" to enable users to have full
access to the VMs console for debugging purposes.

Users obtain an interactive, text console with scrollback. It's possible
to interact with both the kernel and GRUB2. To obtain even additional
debugging information, users can add "console=hvc0" to the linux kernel
command line through GRUB2 (it may be worth considering extending the
initial configuration of the VM to add that argument by default).

Signed-off-by: Sergio Lopez <slp@redhat.com>
@baude
Copy link
Member

baude commented Jun 7, 2024

/approve

Copy link
Contributor

openshift-ci bot commented Jun 7, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: baude, slp

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 7, 2024
return nil, nil, err
}

cmd = exec.Command("/usr/bin/open", "-Wa", "Terminal", kdFile.Path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i assume this will exist on all Mac installations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's part of the base OS: https://www.unix.com/man-page/osx/1/open/

@baude
Copy link
Member

baude commented Jun 7, 2024

one question, else LGTM

@rhatdan
Copy link
Member

rhatdan commented Jun 10, 2024

@Luap99 PTANL

@cgwalters
Copy link
Contributor

/lgtm
(Just jumping in here to progress some PRs, I was tempted to bikeshed shell quoting too but eh 😄 )

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jun 12, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit 009a244 into containers:main Jun 12, 2024
90 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. machine No New Tests Allow PR to proceed without adding regression tests release-note-none
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants