Skip to content

Commit

Permalink
fix: application of override provisioning script only on qemu in amd …
Browse files Browse the repository at this point in the history
…systems

Signed-off-by: Shubharanshu Mahapatra <shubhum@amazon.com>
  • Loading branch information
Shubhranshu153 committed Jul 24, 2024
1 parent 0c5686e commit dc77e4a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 25 deletions.
10 changes: 7 additions & 3 deletions pkg/config/lima_config_applier_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -44,15 +48,15 @@ func (lca *limaConfigApplier) configureVirtualizationFramework(limaCfg *limayaml
case "qemu":
{
limaCfg.MountType = pointer.String("reverse-sshfs")

}

Check failure on line 52 in pkg/config/lima_config_applier_darwin.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary trailing newline (whitespace)
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
Expand Down
52 changes: 30 additions & 22 deletions pkg/config/lima_config_applier_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}

},

Check failure on line 441 in pkg/config/lima_config_applier_darwin_test.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary trailing newline (whitespace)
want: nil,
},
Expand Down

0 comments on commit dc77e4a

Please sign in to comment.