add cpu count limit error type for kic drivers
parent
e84eddccf1
commit
4caf260279
|
|
@ -155,15 +155,7 @@ func runStart(cmd *cobra.Command, args []string) {
|
|||
ds, alts, specified := selectDriver(existing)
|
||||
starter, err := provisionWithDriver(cmd, ds, existing)
|
||||
if err != nil {
|
||||
if errors.Is(err, oci.ErrWindowsContainers) {
|
||||
out.ErrLn("")
|
||||
out.ErrT(out.Conflict, "Your Docker Desktop container os type is Windows but Linux is required.")
|
||||
out.T(out.Warning, "Please change Docker settings to use Linux containers instead of Windows containers.")
|
||||
out.T(out.Documentation, "https://minikube.sigs.k8s.io/docs/drivers/docker/#verify-docker-container-type-is-linux")
|
||||
exit.UsageT(`You can verify your Docker container type by running:
|
||||
{{.command}}
|
||||
`, out.V{"command": "docker info --format '{{.OSType}}'"})
|
||||
}
|
||||
maybeExitWithAdvice(err)
|
||||
if specified {
|
||||
// If the user specified a driver, don't fallback to anything else
|
||||
exit.WithError("error provisioning host", err)
|
||||
|
|
@ -1042,3 +1034,30 @@ func getKubernetesVersion(old *config.ClusterConfig) string {
|
|||
}
|
||||
return nv
|
||||
}
|
||||
|
||||
// maybeExitWithAdvice before exiting will try to check for different error types and provide advice
|
||||
func maybeExitWithAdvice(err error) {
|
||||
if errors.Is(err, oci.ErrWindowsContainers) {
|
||||
out.ErrLn("")
|
||||
out.ErrT(out.Conflict, "Your Docker Desktop container os type is Windows but Linux is required.")
|
||||
out.T(out.Warning, "Please change Docker settings to use Linux containers instead of Windows containers.")
|
||||
out.T(out.Documentation, "https://minikube.sigs.k8s.io/docs/drivers/docker/#verify-docker-container-type-is-linux")
|
||||
exit.UsageT(`You can verify your Docker container type by running:
|
||||
{{.command}}
|
||||
`, out.V{"command": "docker info --format '{{.OSType}}'"})
|
||||
}
|
||||
|
||||
if errors.Is(err, oci.ErrCPUCountLimit) {
|
||||
out.ErrLn("")
|
||||
out.ErrT(out.Conflict, "Your {{.name}} doesn't have enough CPUs. ", out.V{"name": viper.GetString("driver")})
|
||||
if runtime.GOOS != "linux" && viper.GetString("driver") == "docker" {
|
||||
out.T(out.Warning, "Please consider changing your Docker desktop's resources.")
|
||||
out.T(out.Documentation, "https://docs.docker.com/config/containers/resource_constraints/")
|
||||
} else {
|
||||
out.T(out.Warning, "Please ensure your system has at least {{.cpu_counts}} CPU cores", out.V{"cpu_counts": viper.GetInt(cpus)})
|
||||
}
|
||||
|
||||
exit.UsageT("Esnure your system has enough CPUs")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,3 +20,6 @@ import "errors"
|
|||
|
||||
// ErrWindowsContainers is thrown when docker been configured to run windows containers instead of Linux
|
||||
var ErrWindowsContainers = errors.New("docker container type is windows")
|
||||
|
||||
// ErrCPUCountLimit is thrown when docker daemon doesn't have enough CPUs for the requested container
|
||||
var ErrCPUCountLimit = errors.New("not enough CPUs is available for container")
|
||||
|
|
|
|||
|
|
@ -251,7 +251,11 @@ func createContainer(ociBin string, image string, opts ...createOpt) error {
|
|||
args = append(args, image)
|
||||
args = append(args, o.ContainerArgs...)
|
||||
|
||||
if _, err := runCmd(exec.Command(ociBin, args...)); err != nil {
|
||||
if rr, err := runCmd(exec.Command(ociBin, args...)); err != nil {
|
||||
// full error: docker: Error response from daemon: Range of CPUs is from 0.01 to 8.00, as there are only 8 CPUs available.
|
||||
if strings.Contains(rr.Output(), "Range of CPUs is from") && strings.Contains(rr.Output(), "CPUs available") { // CPUs available
|
||||
return ErrCPUCountLimit
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -366,6 +366,12 @@ func startHost(api libmachine.API, cc *config.ClusterConfig, n *config.Node) (*h
|
|||
return host, exists, err
|
||||
}
|
||||
|
||||
// don't try to re-create if cpu count is not enough
|
||||
if errors.Is(err, oci.ErrCPUCountLimit) {
|
||||
glog.Infof("will skip retrying to create machine because error is not retriable: %v", err)
|
||||
return host, exists, err
|
||||
}
|
||||
|
||||
out.ErrT(out.Embarrassed, "StartHost failed, but will try again: {{.error}}", out.V{"error": err})
|
||||
// Try again, but just once to avoid making the logs overly confusing
|
||||
time.Sleep(5 * time.Second)
|
||||
|
|
|
|||
Loading…
Reference in New Issue