Skip to content

Commit

Permalink
Merge pull request #7867 from kubernetes/hyperv-cleanup
Browse files Browse the repository at this point in the history
hyperv: Check for Get-Wmiobject err before parsing output
  • Loading branch information
tstromberg committed Apr 24, 2020
2 parents e3afeb3 + e6669b8 commit 47b769b
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions pkg/minikube/registry/drvs/hyperv/hyperv.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,19 @@ func status() registry.State {

cmd := exec.CommandContext(ctx, path, "@(Get-Wmiobject Win32_ComputerSystem).HypervisorPresent")
out, err := cmd.CombinedOutput()
if string(out) != "True\r\n" {

if err != nil {
errorMessage := fmt.Errorf("%s failed:\n%s", strings.Join(cmd.Args, " "), out)
fixMessage := "Start PowerShell as Administrator, and run: 'Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All'"
fixMessage := "Start PowerShell as an Administrator"
return registry.State{Installed: false, Error: errorMessage, Fix: fixMessage, Doc: docURL}
}

// If timed out, prompt different error and suggestion messages
// See https://github.com/kubernetes/minikube/issues/6579
if ctx.Err() != nil {
errorMessage = fmt.Errorf("%s exited unexpectedly:\n%s", strings.Join(cmd.Args, " "), ctx.Err())
fixMessage = "If you have Hyper-V configured correctly, please try start again with `--force` specified"
}
// Get-Wmiobject does not return an error code for false
if strings.TrimSpace(string(out)) != "True" {
errorMessage := fmt.Errorf("%s returned %q", strings.Join(cmd.Args, " "), out)
fixMessage := "Enable Hyper-V: Start PowerShell as Administrator, and run: 'Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All'"
return registry.State{Installed: false, Error: errorMessage, Fix: fixMessage, Doc: docURL}
}

return registry.State{Installed: true, Healthy: true}
}

0 comments on commit 47b769b

Please sign in to comment.