From d1431f67a6b08f39eddbd60698f12cbf8f70a040 Mon Sep 17 00:00:00 2001 From: Ilya Zuyev Date: Wed, 7 Apr 2021 15:44:03 -0700 Subject: [PATCH] exit if run amd64 binary on M1 cpu --- cmd/minikube/cmd/root.go | 4 ++++ go.mod | 3 ++- go.sum | 2 ++ pkg/minikube/detect/detect.go | 8 ++++++++ pkg/minikube/reason/reason.go | 1 + 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cmd/minikube/cmd/root.go b/cmd/minikube/cmd/root.go index 5f63436e8b..d1369d6143 100644 --- a/cmd/minikube/cmd/root.go +++ b/cmd/minikube/cmd/root.go @@ -93,6 +93,10 @@ 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.") + } + _, callingCmd := filepath.Split(os.Args[0]) if callingCmd == "kubectl" { diff --git a/go.mod b/go.mod index dcd7e49986..30886a0fa7 100644 --- a/go.mod +++ b/go.mod @@ -38,7 +38,7 @@ require ( github.com/hectane/go-acl v0.0.0-20190604041725-da78bae5fc95 // indirect github.com/hooklift/assert v0.0.0-20170704181755-9d1defd6d214 // indirect github.com/hooklift/iso9660 v0.0.0-20170318115843-1cf07e5970d8 - github.com/intel-go/cpuid v0.0.0-20181003105527-1a4a6f06a1c6 // indirect + github.com/intel-go/cpuid v0.0.0-20181003105527-1a4a6f06a1c6 github.com/johanneswuerbach/nfsexports v0.0.0-20200318065542-c48c3734757f github.com/juju/clock v0.0.0-20190205081909-9c5c9712527c github.com/juju/errors v0.0.0-20190806202954-0232dcc7464d // indirect @@ -50,6 +50,7 @@ require ( github.com/juju/utils v0.0.0-20180820210520-bf9cc5bdd62d // indirect github.com/juju/version v0.0.0-20180108022336-b64dbd566305 // indirect github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 + github.com/klauspost/cpuid v1.2.0 github.com/libvirt/libvirt-go v3.9.0+incompatible github.com/machine-drivers/docker-machine-driver-vmware v0.1.1 github.com/mattbaird/jsonpatch v0.0.0-20200820163806-098863c1fc24 diff --git a/go.sum b/go.sum index 81dc14aeaa..fab5029ebd 100644 --- a/go.sum +++ b/go.sum @@ -642,6 +642,7 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o github.com/klauspost/compress v1.11.2/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.11.3 h1:dB4Bn0tN3wdCzQxnS8r06kV74qN/TAfaIS0bVE8h3jc= github.com/klauspost/compress v1.11.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= +github.com/klauspost/cpuid v1.2.0 h1:NMpwD2G9JSFOE1/TJjGSo5zG7Yb2bTe7eq1jH+irmeE= github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -808,6 +809,7 @@ github.com/opencontainers/selinux v1.8.0/go.mod h1:RScLhm78qiWa2gbVCcGkC7tCGdgk3 github.com/otiai10/copy v1.5.0 h1:SoXDGnlTUZoqB/wSuj/Y5L6T5i6iN4YRAcMCd+JnLNU= github.com/otiai10/copy v1.5.0/go.mod h1:XWfuS3CrI0R6IE0FbgHsEazaXO8G0LpMp9o8tos0x4E= github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE= +github.com/otiai10/curr v1.0.0 h1:TJIWdbX0B+kpNagQrjgq8bCMrbhiuX73M2XwgtDMoOI= github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs= github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo= github.com/otiai10/mint v1.3.2 h1:VYWnrP5fXmz1MXvjuUvcBrXSjGE6xjON+axB/UrpO3E= diff --git a/pkg/minikube/detect/detect.go b/pkg/minikube/detect/detect.go index 9e26bf628f..568b26894a 100644 --- a/pkg/minikube/detect/detect.go +++ b/pkg/minikube/detect/detect.go @@ -17,8 +17,11 @@ limitations under the License. package detect import ( + . "github.com/klauspost/cpuid" "net/http" "os" + "runtime" + "strings" ) // IsMicrosoftWSL will return true if process is running in WSL in windows @@ -43,3 +46,8 @@ func IsCloudShell() bool { _, e := os.LookupEnv("CLOUDSHELL_ENVIRONMENT") return e } + +// IsAmd64M1Emulation determines whether amd64 minikube binary is running on M1 mac in emulation mode +func IsAmd64M1Emulation() bool { + return runtime.GOARCH == "amd64" && strings.HasPrefix(CPU.BrandName, "VirtualApple") +} \ No newline at end of file diff --git a/pkg/minikube/reason/reason.go b/pkg/minikube/reason/reason.go index 40dc02acb7..655743803c 100644 --- a/pkg/minikube/reason/reason.go +++ b/pkg/minikube/reason/reason.go @@ -81,6 +81,7 @@ var ( Interrupted = Kind{ID: "MK_INTERRUPTED", ExitCode: ExProgramConflict} WrongBinaryWSL = Kind{ID: "MK_WRONG_BINARY_WSL", ExitCode: ExProgramUnsupported} + WrongBinaryM1 = Kind{ID: "MK_WRONG_BINARY_M1", ExitCode: ExProgramUnsupported} NewAPIClient = Kind{ID: "MK_NEW_APICLIENT", ExitCode: ExProgramError} InternalAddonEnable = Kind{ID: "MK_ADDON_ENABLE", ExitCode: ExProgramError}