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

Allow running amd64 binary on M1 #11674

Merged
merged 5 commits into from
Jun 25, 2021
Merged
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
7 changes: 3 additions & 4 deletions cmd/minikube/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ import (
"strings"
"time"

"k8s.io/minikube/pkg/minikube/notify"
"k8s.io/minikube/pkg/version"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
Expand All @@ -41,9 +38,11 @@ import (
"k8s.io/minikube/pkg/minikube/detect"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/notify"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/reason"
"k8s.io/minikube/pkg/minikube/translate"
"k8s.io/minikube/pkg/version"
)

var dirs = [...]string{
Expand Down Expand Up @@ -96,7 +95,7 @@ func Execute() {
}

if runtime.GOOS == "darwin" && detect.IsAmd64M1Emulation() {
exit.Message(reason.WrongBinaryM1, "You are trying to run amd64 binary on M1 system. Please use darwin/arm64 binary instead (Download at {{.url}}.)",
out.Infof("You are trying to run amd64 binary on M1 system. Please consider running darwin/arm64 binary instead (Download at {{.url}}.)",
out.V{"url": notify.DownloadURL(version.GetVersion(), "darwin", "arm64")})
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/minikube/detect/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ func IsAmd64M1Emulation() bool {
return runtime.GOARCH == "amd64" && strings.HasPrefix(cpuid.CPU.BrandName, "VirtualApple")
}

// EffectiveArch return architecture to use in minikube VM/container
// may differ from host arch
func EffectiveArch() string {
if IsAmd64M1Emulation() {
return "arm64"
}
return runtime.GOARCH
}

// MinikubeInstalledViaSnap returns true if the minikube binary path includes "snap".
func MinikubeInstalledViaSnap() bool {
ex, err := os.Executable()
Expand Down
4 changes: 3 additions & 1 deletion pkg/minikube/download/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"path"
"runtime"

"k8s.io/minikube/pkg/minikube/detect"

"github.com/blang/semver"
"github.com/pkg/errors"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -70,7 +72,7 @@ func Binary(binary, version, osName, archName string) (string, error) {
return "", errors.Wrapf(err, "download failed: %s", url)
}

if osName == runtime.GOOS && archName == runtime.GOARCH {
if osName == runtime.GOOS && archName == detect.EffectiveArch() {
if err = os.Chmod(targetFilepath, 0755); err != nil {
return "", errors.Wrapf(err, "chmod +x %s", targetFilepath)
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/minikube/download/preload.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
"net/http"
"os"
"path/filepath"
"runtime"

"cloud.google.com/go/storage"
"google.golang.org/api/option"
"k8s.io/minikube/pkg/minikube/detect"

"github.com/pkg/errors"
"github.com/spf13/viper"
Expand Down Expand Up @@ -70,7 +70,8 @@ func TarballName(k8sVersion, containerRuntime string) string {
} else {
storageDriver = "overlay2"
}
return fmt.Sprintf("preloaded-images-k8s-%s-%s-%s-%s-%s.tar.lz4", PreloadVersion, k8sVersion, containerRuntime, storageDriver, runtime.GOARCH)
arch := detect.EffectiveArch()
return fmt.Sprintf("preloaded-images-k8s-%s-%s-%s-%s-%s.tar.lz4", PreloadVersion, k8sVersion, containerRuntime, storageDriver, arch)
}

// returns the name of the checksum file
Expand Down
4 changes: 2 additions & 2 deletions pkg/minikube/machine/cache_binaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ package machine

import (
"path"
"runtime"

"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
"k8s.io/klog/v2"
"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/bootstrapper"
"k8s.io/minikube/pkg/minikube/command"
"k8s.io/minikube/pkg/minikube/detect"
"k8s.io/minikube/pkg/minikube/download"
)

Expand Down Expand Up @@ -53,7 +53,7 @@ func CacheBinariesForBootstrapper(version string, clusterBootstrapper string, ex
}
bin := bin // https://golang.org/doc/faq#closures_and_goroutines
g.Go(func() error {
if _, err := download.Binary(bin, version, "linux", runtime.GOARCH); err != nil {
if _, err := download.Binary(bin, version, "linux", detect.EffectiveArch()); err != nil {
return errors.Wrapf(err, "caching binary %s", bin)
}
return nil
Expand Down
4 changes: 3 additions & 1 deletion pkg/minikube/node/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"runtime"
"strings"

"k8s.io/minikube/pkg/minikube/detect"

"github.com/pkg/errors"
"github.com/spf13/viper"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -97,7 +99,7 @@ func CacheKubectlBinary(k8sVersion string) (string, error) {
binary = "kubectl.exe"
}

return download.Binary(binary, k8sVersion, runtime.GOOS, runtime.GOARCH)
return download.Binary(binary, k8sVersion, runtime.GOOS, detect.EffectiveArch())
}

// doCacheBinaries caches Kubernetes binaries in the foreground
Expand Down