From 0292755ea81ac572841fb3ce17da1e137bc80280 Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Fri, 29 Sep 2023 16:32:27 -0700 Subject: [PATCH 1/2] Add Hyper-V memory validation --- cmd/minikube/cmd/start.go | 11 ++++++++++- pkg/minikube/driver/driver.go | 5 +++++ pkg/minikube/reason/reason.go | 6 ++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 62449d7ba7ae..bac4934fd636 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -1178,6 +1178,10 @@ func validateRequestedMemorySize(req int, drvName string) { `The requested memory allocation of {{.requested}}MiB does not leave room for system overhead (total system memory: {{.system_limit}}MiB). You may face stability issues.`, out.V{"requested": req, "system_limit": sysLimit, "advised": advised}) } + + if driver.IsHyperV(drvName) && req%2 == 1 { + exitIfNotForced(reason.RsrcInvalidHyperVMemory, "Hyper-V requires that memory MB be an even number, {{.memory}}MB was specified", out.V{"memory": req}) + } } // validateCPUCount validates the cpu count matches the minimum recommended & not exceeding the available cpu count @@ -1507,7 +1511,12 @@ func noLimitMemory(sysLimit, containerLimit int, drvName string) int { // Because of this allow more system overhead to prevent out of memory issues sysOverhead = 1536 } - return sysLimit - sysOverhead + mem := sysLimit - sysOverhead + // Hyper-V requires an even number of MB, so if odd remove one MB + if driver.IsHyperV(drvName) && mem%2 == 1 { + mem-- + } + return mem } // This function validates if the --registry-mirror diff --git a/pkg/minikube/driver/driver.go b/pkg/minikube/driver/driver.go index 21928e7fad6f..06f1e31f67e6 100644 --- a/pkg/minikube/driver/driver.go +++ b/pkg/minikube/driver/driver.go @@ -198,6 +198,11 @@ func IsVMware(name string) bool { return name == VMware } +// IsHyperV check if the driver is Hyper-V +func IsHyperV(name string) bool { + return name == HyperV +} + // AllowsPreload returns if preload is allowed for the driver func AllowsPreload(driverName string) bool { return !BareMetal(driverName) && !IsSSH(driverName) diff --git a/pkg/minikube/reason/reason.go b/pkg/minikube/reason/reason.go index 4d300dd0b875..16d4268e7b57 100644 --- a/pkg/minikube/reason/reason.go +++ b/pkg/minikube/reason/reason.go @@ -217,6 +217,12 @@ var ( Style: style.UnmetRequirement, URL: "https://docs.docker.com/docker-for-mac/#resources", } + // invalid memory value for Hyper-V + RsrcInvalidHyperVMemory = Kind{ + ID: "RSRC_INVALID_HYPERV_MEMORY", + ExitCode: ExResourceError, + Style: style.UnmetRequirement, + } // insufficient disk storage available to the docker driver RsrcInsufficientDockerStorage = Kind{ From 816de95c2401294e7a1fa06e3d6bab2ae3bb06a6 Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Mon, 2 Oct 2023 14:21:36 -0700 Subject: [PATCH 2/2] suggest memory value --- cmd/minikube/cmd/start.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index bac4934fd636..11cfeabd458c 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -1180,7 +1180,7 @@ func validateRequestedMemorySize(req int, drvName string) { } if driver.IsHyperV(drvName) && req%2 == 1 { - exitIfNotForced(reason.RsrcInvalidHyperVMemory, "Hyper-V requires that memory MB be an even number, {{.memory}}MB was specified", out.V{"memory": req}) + exitIfNotForced(reason.RsrcInvalidHyperVMemory, "Hyper-V requires that memory MB be an even number, {{.memory}}MB was specified, try passing `--memory {{.suggestMemory}}`", out.V{"memory": req, "suggestMemory": req - 1}) } }