Merge pull request #22759 from slp/krun-debug

Enable libkrun provider to open a debug console
This commit is contained in:
openshift-merge-bot[bot]
2024-06-12 06:30:04 +00:00
committed by GitHub
2 changed files with 44 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import (
"fmt" "fmt"
"net" "net"
"os" "os"
"os/exec"
"syscall" "syscall"
"time" "time"
@ -275,6 +276,42 @@ func StartGenericAppleVM(mc *vmconfigs.MachineConfig, cmdBinary string, bootload
logrus.Debugf("helper command-line: %v", cmd.Args) logrus.Debugf("helper command-line: %v", cmd.Args)
if mc.LibKrunHypervisor != nil && logrus.IsLevelEnabled(logrus.DebugLevel) {
rtDir, err := mc.RuntimeDir()
if err != nil {
return nil, nil, err
}
kdFile, err := rtDir.AppendToNewVMFile("krunkit-debug.sh", nil)
if err != nil {
return nil, nil, err
}
f, err := os.Create(kdFile.Path)
if err != nil {
return nil, nil, err
}
err = os.Chmod(kdFile.Path, 0744)
if err != nil {
return nil, nil, err
}
_, err = f.WriteString("#!/bin/sh\nexec ")
if err != nil {
return nil, nil, err
}
for _, arg := range cmd.Args {
_, err = f.WriteString(fmt.Sprintf("%q ", arg))
if err != nil {
return nil, nil, err
}
}
err = f.Close()
if err != nil {
return nil, nil, err
}
cmd = exec.Command("/usr/bin/open", "-Wa", "Terminal", kdFile.Path)
}
if err := cmd.Start(); err != nil { if err := cmd.Start(); err != nil {
return nil, nil, err return nil, nil, err
} }

View File

@ -9,6 +9,7 @@ import (
"github.com/containers/podman/v5/pkg/machine/vmconfigs" "github.com/containers/podman/v5/pkg/machine/vmconfigs"
vfConfig "github.com/crc-org/vfkit/pkg/config" vfConfig "github.com/crc-org/vfkit/pkg/config"
"github.com/crc-org/vfkit/pkg/rest" "github.com/crc-org/vfkit/pkg/rest"
"github.com/sirupsen/logrus"
) )
func GetDefaultDevices(mc *vmconfigs.MachineConfig) ([]vfConfig.VirtioDevice, *define.VMFile, error) { func GetDefaultDevices(mc *vmconfigs.MachineConfig) ([]vfConfig.VirtioDevice, *define.VMFile, error) {
@ -41,7 +42,12 @@ func GetDefaultDevices(mc *vmconfigs.MachineConfig) ([]vfConfig.VirtioDevice, *d
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
devices = append(devices, disk, rng, serial, readyDevice) devices = append(devices, disk, rng, readyDevice)
if mc.LibKrunHypervisor == nil || !logrus.IsLevelEnabled(logrus.DebugLevel) {
// If libkrun is the provider and we want to show the debug console,
// don't add a virtio serial device to avoid redirecting the output.
devices = append(devices, serial)
}
if mc.AppleHypervisor != nil && mc.AppleHypervisor.Vfkit.Rosetta { if mc.AppleHypervisor != nil && mc.AppleHypervisor.Vfkit.Rosetta {
rosetta := &vfConfig.RosettaShare{ rosetta := &vfConfig.RosettaShare{