diff --git a/cmd/minikube/cmd/root.go b/cmd/minikube/cmd/root.go index 6c2e26f3c6dd..269b74752e39 100644 --- a/cmd/minikube/cmd/root.go +++ b/cmd/minikube/cmd/root.go @@ -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")}) } diff --git a/pkg/minikube/detect/detect.go b/pkg/minikube/detect/detect.go index 097a9fb48eeb..7407f2020207 100644 --- a/pkg/minikube/detect/detect.go +++ b/pkg/minikube/detect/detect.go @@ -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() diff --git a/pkg/minikube/download/binary.go b/pkg/minikube/download/binary.go index f370e912b1ad..83743558475c 100644 --- a/pkg/minikube/download/binary.go +++ b/pkg/minikube/download/binary.go @@ -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) } diff --git a/pkg/minikube/download/preload.go b/pkg/minikube/download/preload.go index d7ef9b1b6c8a..832476a64cf1 100644 --- a/pkg/minikube/download/preload.go +++ b/pkg/minikube/download/preload.go @@ -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 diff --git a/pkg/minikube/machine/cache_binaries.go b/pkg/minikube/machine/cache_binaries.go index 44faeddddbf4..4356577e842c 100644 --- a/pkg/minikube/machine/cache_binaries.go +++ b/pkg/minikube/machine/cache_binaries.go @@ -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 diff --git a/pkg/minikube/node/cache.go b/pkg/minikube/node/cache.go index e05e78819864..d58f24ca341a 100644 --- a/pkg/minikube/node/cache.go +++ b/pkg/minikube/node/cache.go @@ -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