Skip to content

Commit

Permalink
feat: Add symbol to specify custom qemu binaries (#870)
Browse files Browse the repository at this point in the history
Reviewed-by: Jakub Ciolek <jakub@unikraft.io>
Approved-by: Jakub Ciolek <jakub@unikraft.io>
  • Loading branch information
jake-ciolek committed Oct 11, 2023
2 parents 8cf3075 + dd10e24 commit 0565d63
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/runu/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

machineapi "kraftkit.sh/api/machine/v1alpha1"
"kraftkit.sh/cmdfactory"
"kraftkit.sh/config"
"kraftkit.sh/exec"
"kraftkit.sh/internal/set"
libcontainer "kraftkit.sh/libmocktainer"
Expand Down Expand Up @@ -271,6 +272,10 @@ func genMachineArgs(ctx context.Context, cID, rootDir, bundleRoot string) (args
return nil, fmt.Errorf("unsupported machine architecture: %s", mArch)
}

if config.G[config.KraftKit](ctx).Qemu != "" {
bin = config.G[config.KraftKit](ctx).Qemu
}

exe, err := exec.NewExecutable(bin, qCfg)
if err != nil {
return nil, fmt.Errorf("preparing machine executable: %w", err)
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type KraftKit struct {
Editor string `yaml:"editor" env:"KRAFTKIT_EDITOR" long:"editor" usage:"Set the text editor to open when prompt to edit a file"`
GitProtocol string `yaml:"git_protocol" env:"KRAFTKIT_GIT_PROTOCOL" long:"git-protocol" usage:"Preferred Git protocol to use" default:"https"`
Pager string `yaml:"pager,omitempty" env:"KRAFTKIT_PAGER" long:"pager" usage:"System pager to pipe output to"`
Qemu string `yaml:"qemu,omitempty" env:"KRAFTKIT_QEMU" long:"qemu" usage:"Path to QEMU executable" default:""`
HTTPUnixSocket string `yaml:"http_unix_socket,omitempty" env:"KRAFTKIT_HTTP_UNIX_SOCKET" long:"http-unix-sock" usage:"When making HTTP(S) connections, pipe requests via this shared socket"`
RuntimeDir string `yaml:"runtime_dir" env:"KRAFTKIT_RUNTIME_DIR" long:"runtime-dir" usage:"Directory for placing runtime files (e.g. pidfiles)"`
DefaultPlat string `yaml:"default_plat" env:"KRAFTKIT_DEFAULT_PLAT" usage:"The default platform to use when invoking platform-specific code" noattribute:"true"`
Expand Down
7 changes: 7 additions & 0 deletions machine/platform/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"strings"
"syscall"

"kraftkit.sh/config"
"kraftkit.sh/internal/set"
"kraftkit.sh/machine/qemu"
)
Expand Down Expand Up @@ -194,10 +195,16 @@ func Detect(ctx context.Context) (Platform, SystemMode, error) {
// Check if any QEMU binaries are installed on the host. Since we could not
// determine if virtualization extensions are possible at this point, at least
// guest emulation is possible with QEMU.
var customBin string
if config.G[config.KraftKit](ctx).Qemu != "" {
customBin = config.G[config.KraftKit](ctx).Qemu
}

for _, bin := range []string{
qemu.QemuSystemX86,
qemu.QemuSystemArm,
qemu.QemuSystemAarch64,
customBin,
} {
if _, err := exec.LookPath(bin); err != nil {
continue
Expand Down
4 changes: 4 additions & 0 deletions machine/qemu/v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func (service *machineV1alpha1Service) Create(ctx context.Context, machine *mach
return nil, fmt.Errorf("unsupported architecture: %s", machine.Spec.Architecture)
}

if config.G[config.KraftKit](ctx).Qemu != "" {
bin = config.G[config.KraftKit](ctx).Qemu
}

// Determine the version of QEMU so as to both determine whether it is a
// suitable version and to adjust the supplied command-line arguments.
qemuVersion, err := GetQemuVersionFromBin(ctx, bin)
Expand Down

0 comments on commit 0565d63

Please sign in to comment.