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

linux: add solution message for noexec mount volumes #8597

Merged
merged 2 commits into from
Jun 29, 2020
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
1 change: 1 addition & 0 deletions cmd/minikube/cmd/node_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ var nodeStartCmd = &cobra.Command{
if err != nil {
_, err := maybeDeleteAndRetry(*cc, *n, nil, err)
sharifelgamal marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
node.MaybeExitWithAdvice(err)
exit.WithError("failed to start node", err)
}
}
Expand Down
35 changes: 2 additions & 33 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func runStart(cmd *cobra.Command, args []string) {
ds, alts, specified := selectDriver(existing)
starter, err := provisionWithDriver(cmd, ds, existing)
if err != nil {
maybeExitWithAdvice(err)
node.MaybeExitWithAdvice(err)
machine.MaybeDisplayAdvice(err, viper.GetString("driver"))
if specified {
// If the user specified a driver, don't fallback to anything else
Expand Down Expand Up @@ -193,6 +193,7 @@ func runStart(cmd *cobra.Command, args []string) {

kubeconfig, err := startWithDriver(starter, existing)
if err != nil {
node.MaybeExitWithAdvice(err)
exit.WithError("failed to start node", err)
}

Expand Down Expand Up @@ -1044,35 +1045,3 @@ 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, "{{.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 {
cpuCount := viper.GetInt(cpus)
if cpuCount == 2 {
out.T(out.Tip, "Please ensure your system has {{.cpu_counts}} CPU cores.", out.V{"cpu_counts": viper.GetInt(cpus)})
} else {
out.T(out.Tip, "Please ensure your {{.driver_name}} system has access to {{.cpu_counts}} CPU cores or reduce the number of the specified CPUs", out.V{"driver_name": viper.GetString("driver"), "cpu_counts": viper.GetInt(cpus)})
}
}

exit.UsageT("Ensure your {{.driver_name}} system has enough CPUs. The minimum allowed is 2 CPUs.", out.V{"driver_name": viper.GetString("driver")})
}

}
32 changes: 32 additions & 0 deletions pkg/minikube/bootstrapper/kubeadm/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright 2020 The Kubernetes Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package kubeadm

import "errors"

// FailFastError type is an error that could not be solved by trying again
type FailFastError struct {
Err error
}

func (f *FailFastError) Error() string {
return f.Err.Error()
}

// ErrNoExecLinux is thrown on linux when the kubeadm binaries are mounted in a noexec volume on Linux as seen in https://github.com/kubernetes/minikube/issues/8327#issuecomment-651288459
// this error could be seen on docker/podman or none driver.
var ErrNoExecLinux = &FailFastError{errors.New("mounted kubeadm binary is not executable")}
15 changes: 11 additions & 4 deletions pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ func (k *Bootstrapper) init(cfg config.ClusterConfig) error {
c := exec.Command("/bin/bash", "-c", fmt.Sprintf("%s init --config %s %s --ignore-preflight-errors=%s",
bsutil.InvokeKubeadm(cfg.KubernetesConfig.KubernetesVersion), conf, extraFlags, strings.Join(ignore, ",")))
if _, err := k.c.RunCmd(c); err != nil {
if strings.Contains(err.Error(), "'kubeadm': Permission denied") {
return ErrNoExecLinux
}
return errors.Wrap(err, "run")
}

Expand Down Expand Up @@ -348,11 +351,15 @@ func (k *Bootstrapper) StartCluster(cfg config.ClusterConfig) error {
return nil
}

out.ErrT(out.Conflict, "initialization failed, will try again: {{.error}}", out.V{"error": err})
if err := k.DeleteCluster(cfg.KubernetesConfig); err != nil {
glog.Warningf("delete failed: %v", err)
// retry again if it is not a fail fast error
if _, ff := err.(*FailFastError); !ff {
out.ErrT(out.Conflict, "initialization failed, will try again: {{.error}}", out.V{"error": err})
if err := k.DeleteCluster(cfg.KubernetesConfig); err != nil {
glog.Warningf("delete failed: %v", err)
}
return k.init(cfg)
}
return k.init(cfg)
return err
}

// client sets and returns a Kubernetes client to use to speak to a kubeadm launched apiserver
Expand Down
74 changes: 74 additions & 0 deletions pkg/minikube/node/advice.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
Copyright 2020 The Kubernetes Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package node

import (
"runtime"

"github.com/pkg/errors"
"github.com/spf13/viper"
"k8s.io/minikube/pkg/drivers/kic/oci"
"k8s.io/minikube/pkg/minikube/bootstrapper/kubeadm"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/out"
)

// MaybeExitWithAdvice before exiting will try to check for different error types and provide advice if we know for sure what the error is
func MaybeExitWithAdvice(err error) {
if err == nil {
return
}

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, "{{.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 {
cpuCount := viper.GetInt(cpus)
if cpuCount == 2 {
out.T(out.Tip, "Please ensure your system has {{.cpu_counts}} CPU cores.", out.V{"cpu_counts": viper.GetInt(cpus)})
} else {
out.T(out.Tip, "Please ensure your {{.driver_name}} system has access to {{.cpu_counts}} CPU cores or reduce the number of the specified CPUs", out.V{"driver_name": viper.GetString("driver"), "cpu_counts": viper.GetInt(cpus)})
}
}
exit.UsageT("Ensure your {{.driver_name}} system has enough CPUs. The minimum allowed is 2 CPUs.", out.V{"driver_name": viper.GetString("driver")})
}

if errors.Is(err, kubeadm.ErrNoExecLinux) {
out.ErrLn("")
out.ErrT(out.Conflict, "kubeadm binary is not executable !")
out.T(out.Documentation, "Try the solution in this link: https://github.com/kubernetes/minikube/issues/8327#issuecomment-651288459")
exit.UsageT(`Ensure the binaries are not mounted with "noexec" option. To check run:

$ findmnt

`)
}

}
1 change: 1 addition & 0 deletions pkg/minikube/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
const (
mountString = "mount-string"
createMount = "mount"
cpus = "cpus"
)

// Add adds a new node config to an existing cluster.
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/node/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ func Start(starter Starter, apiServer bool) (*kubeconfig.Settings, error) {
// setup kubeadm (must come after setupKubeconfig)
bs = setupKubeAdm(starter.MachineAPI, *starter.Cfg, *starter.Node, starter.Runner)
err = bs.StartCluster(*starter.Cfg)

if err != nil {
MaybeExitWithAdvice(err)
out.LogEntries("Error starting cluster", err, logs.FindProblems(cr, bs, *starter.Cfg, starter.Runner))
return nil, err
}
Expand Down