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 Sep 19, 2024
1 parent 133979a commit 9943267
Show file tree
Hide file tree
Showing 5 changed files with 46 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 @@ -735,6 +735,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 @@ -106,7 +106,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 @@ -293,6 +294,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 @@ -420,6 +423,7 @@ func TestFillDefault(t *testing.T) {
Enabled: ptr.Of(true),
BinFmt: ptr.Of(true),
},
NestedVirtualization: ptr.Of(true),
}

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

y = filledDefaults
Expand Down Expand Up @@ -690,6 +695,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...)
}
Expand Down
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
21 changes: 21 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,25 @@ 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)
}

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

View workflow job for this annotation

GitHub Actions / Artifacts Darwin

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

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

View workflow job for this annotation

GitHub Actions / Integration tests

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

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

View workflow job for this annotation

GitHub Actions / VMNet test

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

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

View workflow job for this annotation

GitHub Actions / vz (default.yaml)

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

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

View workflow job for this annotation

GitHub Actions / vz (fedora.yaml)

platformConfig.IsNestedVirtualizationSupported undefined (type *"github.com/Code-Hex/vz/v3".GenericPlatformConfiguration has no field or method IsNestedVirtualizationSupported)
if macOSProductVersion.LessThan(*semver.New("15.0.0")) {
return errors.New("nested virtualization requires macOS 15 or newer")
}

Check failure on line 255 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 255 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 255 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 255 in pkg/vz/vm_darwin.go

View workflow job for this annotation

GitHub Actions / vz (default.yaml)

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

Check failure on line 255 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)
if !platformConfig.IsNestedVirtualizationSupported() {
return errors.New("nested virtualization is not supported on this device")
}

platformConfig.SetNestedVirtualizationEnabled(true)
}

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 9943267

Please sign in to comment.