Merge pull request #11674 from ilya-zuyev/ilyaz/m1_amd64

Allow running amd64 binary on M1
pull/11749/head
Medya Ghazizadeh 2021-06-25 15:15:28 -04:00 committed by GitHub
commit 52d88fb628
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 10 deletions

View File

@ -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"
@ -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{
@ -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")})
}

View File

@ -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()

View File

@ -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"
@ -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)
}

View File

@ -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"
@ -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

View File

@ -18,7 +18,6 @@ package machine
import (
"path"
"runtime"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
@ -26,6 +25,7 @@ import (
"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"
)
@ -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

View File

@ -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"
@ -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