Skip to content

Commit daf0e66

Browse files
authored
Merge pull request #17325 from spowelljr/checkForHyperVMemoryValidation
Add Hyper-V memory validation for odd numbers
2 parents 9ff7852 + 816de95 commit daf0e66

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

cmd/minikube/cmd/start.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,10 @@ func validateRequestedMemorySize(req int, drvName string) {
11781178
`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.`,
11791179
out.V{"requested": req, "system_limit": sysLimit, "advised": advised})
11801180
}
1181+
1182+
if driver.IsHyperV(drvName) && req%2 == 1 {
1183+
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})
1184+
}
11811185
}
11821186

11831187
// 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 {
15071511
// Because of this allow more system overhead to prevent out of memory issues
15081512
sysOverhead = 1536
15091513
}
1510-
return sysLimit - sysOverhead
1514+
mem := sysLimit - sysOverhead
1515+
// Hyper-V requires an even number of MB, so if odd remove one MB
1516+
if driver.IsHyperV(drvName) && mem%2 == 1 {
1517+
mem--
1518+
}
1519+
return mem
15111520
}
15121521

15131522
// This function validates if the --registry-mirror

pkg/minikube/driver/driver.go

+5
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ func IsVMware(name string) bool {
198198
return name == VMware
199199
}
200200

201+
// IsHyperV check if the driver is Hyper-V
202+
func IsHyperV(name string) bool {
203+
return name == HyperV
204+
}
205+
201206
// AllowsPreload returns if preload is allowed for the driver
202207
func AllowsPreload(driverName string) bool {
203208
return !BareMetal(driverName) && !IsSSH(driverName)

pkg/minikube/reason/reason.go

+6
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ var (
217217
Style: style.UnmetRequirement,
218218
URL: "https://docs.docker.com/docker-for-mac/#resources",
219219
}
220+
// invalid memory value for Hyper-V
221+
RsrcInvalidHyperVMemory = Kind{
222+
ID: "RSRC_INVALID_HYPERV_MEMORY",
223+
ExitCode: ExResourceError,
224+
Style: style.UnmetRequirement,
225+
}
220226

221227
// insufficient disk storage available to the docker driver
222228
RsrcInsufficientDockerStorage = Kind{

0 commit comments

Comments
 (0)