From dc77e4a780bf94316793ab616706a0b8ba32f198 Mon Sep 17 00:00:00 2001 From: Shubharanshu Mahapatra Date: Sat, 20 Jul 2024 07:53:18 -0700 Subject: [PATCH] fix: application of override provisioning script only on qemu in amd systems Signed-off-by: Shubharanshu Mahapatra --- pkg/config/lima_config_applier_darwin.go | 10 ++-- pkg/config/lima_config_applier_darwin_test.go | 52 +++++++++++-------- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/pkg/config/lima_config_applier_darwin.go b/pkg/config/lima_config_applier_darwin.go index 9537323d0..cc3b1bc3a 100644 --- a/pkg/config/lima_config_applier_darwin.go +++ b/pkg/config/lima_config_applier_darwin.go @@ -14,10 +14,14 @@ import ( ) // configureVirtualizationFramework changes settings that will only apply to the VM after a new init. +// T0 run cross compiled container images we use lima #Fast Mode 1 or # Fast Mode 2 depending on the configuration +// If we use vz on an arm host we configure rosetta as true and bin fmt as true to register rosetta to binfmt_misc. +// For every other scenario we use qemu user mode emulation to run cross compiled containers +// Link: https://github.com/lima-vm/lima/blob/3075bd91186483d88fb248aa2f0f84576e49c1ff/website/content/en/docs/config/multi-arch/_index.md?plain=1#L43 func (lca *limaConfigApplier) configureVirtualizationFramework(limaCfg *limayaml.LimaYAML) (*limayaml.LimaYAML, error) { hasSupport, hasSupportErr := SupportsVirtualizationFramework(lca.cmdCreator) if *lca.cfg.Rosetta && - lca.systemDeps.Arch() == "arm64" { + lca.systemDeps.Arch() == "arm64" && *lca.cfg.VMType == "vz" { if hasSupportErr != nil { return nil, fmt.Errorf("failed to check for virtualization framework support: %w", hasSupportErr) } @@ -44,15 +48,15 @@ func (lca *limaConfigApplier) configureVirtualizationFramework(limaCfg *limayaml case "qemu": { limaCfg.MountType = pointer.String("reverse-sshfs") + } default: return nil, fmt.Errorf("unsupported vm type \"%s\" for macOS", *lca.cfg.VMType) } - + userModeEmulationInstallationScript(limaCfg) limaCfg.Rosetta.Enabled = pointer.Bool(false) limaCfg.Rosetta.BinFmt = pointer.Bool(false) limaCfg.VMType = lca.cfg.VMType - userModeEmulationInstallationScript(limaCfg) } return limaCfg, nil diff --git a/pkg/config/lima_config_applier_darwin_test.go b/pkg/config/lima_config_applier_darwin_test.go index 212005f5f..8f79dee5f 100644 --- a/pkg/config/lima_config_applier_darwin_test.go +++ b/pkg/config/lima_config_applier_darwin_test.go @@ -386,25 +386,25 @@ func TestDiskLimaConfigApplier_Apply(t *testing.T) { deps *mocks.LimaConfigApplierSystemDeps, ) { err := afero.WriteFile(fs, "/default.yaml", []byte(` - vmType: "qemu" - provision: - - mode: system - script: | - # cross-arch tools - #!/bin/bash - qemu_pkgs="" - if [ ! -f /usr/bin/qemu-aarch64-static ]; then - qemu_pkgs="$qemu_pkgs qemu-user-static-aarch64" - elif [ ! -f /usr/bin/qemu-aarch64-static ]; then - qemu_pkgs="$qemu_pkgs qemu-user-static-arm" - elif [ ! -f /usr/bin/qemu-aarch64-static ]; then - qemu_pkgs="$qemu_pkgs qemu-user-static-x86" - fi - - if [[ $qemu_pkgs ]]; then - dnf install -y --setopt=install_weak_deps=False ${qemu_pkgs} - fi - `), 0o600) +vmType: "qemu" +provision: +- mode: system + script: | + # cross-arch tools + #!/bin/bash + qemu_pkgs="" + if [ ! -f /usr/bin/qemu-aarch64-static ]; then + qemu_pkgs="$qemu_pkgs qemu-user-static-aarch64" + elif [ ! -f /usr/bin/qemu-aarch64-static ]; then + qemu_pkgs="$qemu_pkgs qemu-user-static-arm" + elif [ ! -f /usr/bin/qemu-aarch64-static ]; then + qemu_pkgs="$qemu_pkgs qemu-user-static-x86" + fi + + if [[ $qemu_pkgs ]]; then + dnf install -y --setopt=install_weak_deps=False ${qemu_pkgs} + fi +`), 0o600) require.NoError(t, err) cmd.EXPECT().Output().Return([]byte("13.0.0"), nil) creator.EXPECT().Create("sw_vers", "-productVersion").Return(cmd) @@ -427,9 +427,17 @@ func TestDiskLimaConfigApplier_Apply(t *testing.T) { require.Equal(t, "vz", *limaCfg.VMType) require.Equal(t, "virtiofs", *limaCfg.MountType) - require.Equal(t, true, *limaCfg.Rosetta.BinFmt) - require.Equal(t, true, *limaCfg.Rosetta.Enabled) - require.Len(t, limaCfg.Provision, 0) + arch := runtime.GOARCH + if arch == "arm64" { + require.Equal(t, true, *limaCfg.Rosetta.BinFmt) + require.Equal(t, true, *limaCfg.Rosetta.Enabled) + require.Len(t, limaCfg.Provision, 0) + } else if arch == "amd64" { + require.Equal(t, false, *limaCfg.Rosetta.BinFmt) + require.Equal(t, false, *limaCfg.Rosetta.Enabled) + require.Equal(t, qemuPkgScriptWithHeader, limaCfg.Provision[0].Script) + } + }, want: nil, },