-
-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vm: add support for macOS Virtualization.Framework (#504)
* vm: add support for virtualization.framework * vm: add support for Rosetta on m1 devices * vm: manually enable rosetta, fixes #494 * vm: enable reachable address for VZ driver * vm: disable qemu when rosetta is enabled * vm: fix dns error for ip address * misc: minor refactor - network address * cli: add vm driver to status command * vm: fix default mount type for qemu driver * chore: rename driver to vmType in config * k3s: update to v1.25.4+k3s1 * cli: fix broken flag due to refactor ci: use Go version 1.19 * cli: fix broken flag due to refactor * ci: use go 1.19 and macOS 12
- Loading branch information
Showing
20 changed files
with
217 additions
and
986 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,13 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"strconv" | ||
|
||
_ "github.com/abiosoft/colima/cmd" // for other commands | ||
_ "github.com/abiosoft/colima/cmd/daemon" // for vmnet daemon | ||
_ "github.com/abiosoft/colima/embedded" // for embedded assets | ||
|
||
"github.com/abiosoft/colima/cmd/root" | ||
"github.com/abiosoft/colima/config" | ||
"github.com/abiosoft/colima/daemon/process/gvproxy" | ||
"github.com/abiosoft/colima/daemon/process/vmnet" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func main() { | ||
_, cmd := filepath.Split(os.Args[0]) | ||
switch cmd { | ||
case "qemu-system-x86_64", "qemu-system-aarch64": | ||
qemuWrapper(cmd) | ||
default: | ||
root.Execute() | ||
} | ||
} | ||
|
||
func qemuWrapper(qemu string) { | ||
if profile := os.Getenv(config.SubprocessProfileEnvVar); profile != "" { | ||
config.SetProfile(profile) | ||
} | ||
|
||
gvproxyInfo := gvproxy.Info() | ||
vmnetInfo := vmnet.Info() | ||
|
||
// check if qemu is meant to run by lima | ||
// decided by -pidfile flag | ||
qemuRunning := false | ||
for _, arg := range os.Args { | ||
if arg == "-pidfile" { | ||
qemuRunning = true | ||
break | ||
} | ||
} | ||
|
||
args := os.Args[1:] // forward all args | ||
var extraFiles []*os.File | ||
|
||
gvproxyEnabled, _ := strconv.ParseBool(os.Getenv(gvproxy.SubProcessEnvVar)) | ||
vmnetEnabled, _ := strconv.ParseBool(os.Getenv(vmnet.SubProcessEnvVar)) | ||
|
||
if qemuRunning && gvproxyEnabled { | ||
// vmnet should come first as it would be added by Lima and would have the fd 3 | ||
|
||
// vmnet | ||
if vmnetEnabled { | ||
fd := os.NewFile(3, vmnetInfo.Socket.File()) | ||
extraFiles = append(extraFiles, fd) | ||
} | ||
|
||
// gvproxy | ||
{ | ||
conn, err := net.Dial("unix", gvproxyInfo.Socket.File()) | ||
if err != nil { | ||
logrus.Fatal(fmt.Errorf("error connecting to gvproxy socket: %w", err)) | ||
} | ||
fd, err := conn.(*net.UnixConn).File() | ||
if err != nil { | ||
logrus.Fatal(fmt.Errorf("error retrieving fd for gvproxy socket: %w", err)) | ||
} | ||
extraFiles = append(extraFiles, fd) | ||
} | ||
|
||
// gvproxy fd | ||
fd := strconv.Itoa(2 + len(extraFiles)) | ||
args = append(args, | ||
"-netdev", "socket,id=vlan,fd="+fd, | ||
"-device", "virtio-net-pci,netdev=vlan,mac="+gvproxyInfo.MacAddress, | ||
) | ||
} | ||
|
||
cmd := exec.Command(qemu, args...) | ||
|
||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
cmd.Stdin = os.Stdin | ||
|
||
if len(extraFiles) > 0 { | ||
cmd.ExtraFiles = append(cmd.ExtraFiles, extraFiles...) | ||
} | ||
|
||
err := cmd.Run() | ||
if err != nil { | ||
if err, ok := err.(*exec.ExitError); ok { | ||
os.Exit(err.ExitCode()) | ||
} | ||
os.Exit(1) | ||
} | ||
|
||
root.Execute() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.