diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 62449d7ba7ae..11cfeabd458c 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, try passing `--memory {{.suggestMemory}}`", out.V{"memory": req, "suggestMemory": req - 1}) + } } // 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{