Skip to content

Commit

Permalink
vz: add support for nested virtualization
Browse files Browse the repository at this point in the history
Signed-off-by: Abiola Ibrahim <git@abiosoft.com>
  • Loading branch information
abiosoft committed Aug 6, 2024
1 parent 6c2bfaa commit b946be0
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
10 changes: 10 additions & 0 deletions pkg/limayaml/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,16 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
y.Rosetta.BinFmt = ptr.Of(false)
}

if y.NestedVirtualization == nil {
y.NestedVirtualization = d.NestedVirtualization
}
if o.NestedVirtualization != nil {
y.NestedVirtualization = o.NestedVirtualization
}
if y.NestedVirtualization == nil {
y.NestedVirtualization = ptr.Of(false)
}

if y.Plain == nil {
y.Plain = d.Plain
}
Expand Down
9 changes: 8 additions & 1 deletion pkg/limayaml/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ func TestFillDefault(t *testing.T) {
CACertificates: CACertificates{
RemoveDefaults: ptr.Of(false),
},
Plain: ptr.Of(false),
NestedVirtualization: ptr.Of(false),
Plain: ptr.Of(false),
}

defaultPortForward := PortForward{
Expand Down Expand Up @@ -274,6 +275,8 @@ func TestFillDefault(t *testing.T) {
BinFmt: ptr.Of(false),
}

expect.NestedVirtualization = ptr.Of(false)

FillDefault(&y, &LimaYAML{}, &LimaYAML{}, filePath)
assert.DeepEqual(t, &y, &expect, opts...)

Expand Down Expand Up @@ -401,6 +404,7 @@ func TestFillDefault(t *testing.T) {
Enabled: ptr.Of(true),
BinFmt: ptr.Of(true),
},
NestedVirtualization: ptr.Of(true),
}

expect = d
Expand Down Expand Up @@ -608,6 +612,7 @@ func TestFillDefault(t *testing.T) {
Enabled: ptr.Of(false),
BinFmt: ptr.Of(false),
},
NestedVirtualization: ptr.Of(false),
}

y = filledDefaults
Expand Down Expand Up @@ -663,6 +668,8 @@ func TestFillDefault(t *testing.T) {
}
expect.Plain = ptr.Of(false)

expect.NestedVirtualization = ptr.Of(false)

FillDefault(&y, &d, &o, filePath)
assert.DeepEqual(t, &y, &expect, opts...)
}
11 changes: 6 additions & 5 deletions pkg/limayaml/limayaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ type LimaYAML struct {
DNS []net.IP `yaml:"dns,omitempty" json:"dns,omitempty"`
HostResolver HostResolver `yaml:"hostResolver,omitempty" json:"hostResolver,omitempty"`
// `useHostResolver` was deprecated in Lima v0.8.1, removed in Lima v0.14.0. Use `hostResolver.enabled` instead.
PropagateProxyEnv *bool `yaml:"propagateProxyEnv,omitempty" json:"propagateProxyEnv,omitempty"`
CACertificates CACertificates `yaml:"caCerts,omitempty" json:"caCerts,omitempty"`
Rosetta Rosetta `yaml:"rosetta,omitempty" json:"rosetta,omitempty"`
Plain *bool `yaml:"plain,omitempty" json:"plain,omitempty"`
TimeZone *string `yaml:"timezone,omitempty" json:"timezone,omitempty"`
PropagateProxyEnv *bool `yaml:"propagateProxyEnv,omitempty" json:"propagateProxyEnv,omitempty"`
CACertificates CACertificates `yaml:"caCerts,omitempty" json:"caCerts,omitempty"`
Rosetta Rosetta `yaml:"rosetta,omitempty" json:"rosetta,omitempty"`
Plain *bool `yaml:"plain,omitempty" json:"plain,omitempty"`
TimeZone *string `yaml:"timezone,omitempty" json:"timezone,omitempty"`
NestedVirtualization *bool `yaml:"nestedVirtualization,omitempty" json:"nestedVirtualization,omitempty"`
}

type (
Expand Down
17 changes: 17 additions & 0 deletions pkg/vz/vm_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"syscall"

"github.com/Code-Hex/vz/v3"
"github.com/coreos/go-semver/semver"
"github.com/docker/go-units"
"github.com/lima-vm/go-qcow2reader"
"github.com/lima-vm/go-qcow2reader/image/raw"
Expand All @@ -25,6 +26,7 @@ import (
"github.com/lima-vm/lima/pkg/nativeimgutil"
"github.com/lima-vm/lima/pkg/networks"
"github.com/lima-vm/lima/pkg/networks/usernet"
"github.com/lima-vm/lima/pkg/osutil"
"github.com/lima-vm/lima/pkg/store"
"github.com/lima-vm/lima/pkg/store/filenames"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -239,6 +241,21 @@ func attachPlatformConfig(driver *driver.BaseDriver, vmConfig *vz.VirtualMachine
if err != nil {
return err
}

// nested virt
if *driver.Yaml.NestedVirtualization {
macOSProductVersion, err := osutil.ProductVersion()
if err != nil {
return fmt.Errorf("failed to get macOS product version: %w", err)
}

if macOSProductVersion.LessThan(*semver.New("15.0.0")) {
return fmt.Errorf("nested virtualization requires macOS 15 or newer")
}

platformConfig.SetNestedVirtualizationEnabled(true)

Check failure on line 256 in pkg/vz/vm_darwin.go

View workflow job for this annotation

GitHub Actions / Artifacts Darwin

platformConfig.SetNestedVirtualizationEnabled undefined (type *"github.com/Code-Hex/vz/v3".GenericPlatformConfiguration has no field or method SetNestedVirtualizationEnabled)

Check failure on line 256 in pkg/vz/vm_darwin.go

View workflow job for this annotation

GitHub Actions / Integration tests

platformConfig.SetNestedVirtualizationEnabled undefined (type *"github.com/Code-Hex/vz/v3".GenericPlatformConfiguration has no field or method SetNestedVirtualizationEnabled)

Check failure on line 256 in pkg/vz/vm_darwin.go

View workflow job for this annotation

GitHub Actions / Upgrade test (v0.15.1)

platformConfig.SetNestedVirtualizationEnabled undefined (type *"github.com/Code-Hex/vz/v3".GenericPlatformConfiguration has no field or method SetNestedVirtualizationEnabled)

Check failure on line 256 in pkg/vz/vm_darwin.go

View workflow job for this annotation

GitHub Actions / Upgrade test (v0.15.1)

platformConfig.SetNestedVirtualizationEnabled undefined (type *"github.com/Code-Hex/vz/v3".GenericPlatformConfiguration has no field or method SetNestedVirtualizationEnabled)

Check failure on line 256 in pkg/vz/vm_darwin.go

View workflow job for this annotation

GitHub Actions / Upgrade test (v0.15.1)

platformConfig.SetNestedVirtualizationEnabled undefined (type *"github.com/Code-Hex/vz/v3".GenericPlatformConfiguration has no field or method SetNestedVirtualizationEnabled)

Check failure on line 256 in pkg/vz/vm_darwin.go

View workflow job for this annotation

GitHub Actions / VMNet test

platformConfig.SetNestedVirtualizationEnabled undefined (type *"github.com/Code-Hex/vz/v3".GenericPlatformConfiguration has no field or method SetNestedVirtualizationEnabled)

Check failure on line 256 in pkg/vz/vm_darwin.go

View workflow job for this annotation

GitHub Actions / vz (experimental/vz.yaml)

platformConfig.SetNestedVirtualizationEnabled undefined (type *"github.com/Code-Hex/vz/v3".GenericPlatformConfiguration has no field or method SetNestedVirtualizationEnabled)

Check failure on line 256 in pkg/vz/vm_darwin.go

View workflow job for this annotation

GitHub Actions / vz (fedora.yaml)

platformConfig.SetNestedVirtualizationEnabled undefined (type *"github.com/Code-Hex/vz/v3".GenericPlatformConfiguration has no field or method SetNestedVirtualizationEnabled)
}

vmConfig.SetPlatformVirtualMachineConfiguration(platformConfig)
return nil
}
Expand Down
1 change: 1 addition & 0 deletions pkg/vz/vz_driver_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var knownYamlProperties = []string{
"Mounts",
"MountType",
"MountInotify",
"NestedVirtualization",
"Networks",
"OS",
"Param",
Expand Down

0 comments on commit b946be0

Please sign in to comment.