Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Hyper-V memory validation for odd numbers #17325

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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