Skip to content

Commit

Permalink
Merge pull request #17325 from spowelljr/checkForHyperVMemoryValidation
Browse files Browse the repository at this point in the history
Add Hyper-V memory validation for odd numbers
  • Loading branch information
medyagh authored Oct 4, 2023
2 parents 9ff7852 + 816de95 commit daf0e66
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions pkg/minikube/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions pkg/minikube/reason/reason.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit daf0e66

Please sign in to comment.