Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: override provisioning script #1043

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
)

// 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 @@
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 @@
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,10 +427,18 @@

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
Loading