diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 6fe437d61e..365d4b04e8 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -1006,8 +1006,8 @@ Suggested workarounds: } defer conn.Close() } - - if _, err := r.RunCmd(exec.Command("/bin/bash", "-c", "nslookup kubernetes.io")); err != nil { + w + if _, err := r.RunCmd(exec.Command("nslookup", "kubernetes.io")); err != nil { out.WarningT("VM is unable to resolve DNS hosts: {[.error}}", out.V{"error": err}) } diff --git a/pkg/drivers/none/none.go b/pkg/drivers/none/none.go index 3013e0703f..236fa97034 100644 --- a/pkg/drivers/none/none.go +++ b/pkg/drivers/none/none.go @@ -225,12 +225,12 @@ func (d *Driver) RunSSHCommandFromDriver() error { func stopKubelet(cr command.Runner) error { glog.Infof("stopping kubelet.service ...") stop := func() error { - cmdStop := exec.Command("/bin/bash", "sudo systemctl stop kubelet.service") + cmdStop := exec.Command("sudo", "systemctl", "stop", "kubelet.service") if rr, err := cr.RunCmd(cmdStop); err != nil { glog.Errorf("temporary error for %q : %v", rr.Command(), err) } var out bytes.Buffer - cmdCheck := exec.Command("/bin/bash", "-c", "sudo systemctl show -p SubState kubelet") + cmdCheck := exec.Command("sudo", "systemctl", "show", "-p", "SubState", "kubelet") cmdCheck.Stdout = &out cmdCheck.Stderr = &out if rr, err := cr.RunCmd(cmdCheck); err != nil { @@ -252,7 +252,7 @@ func stopKubelet(cr command.Runner) error { // restartKubelet restarts the kubelet func restartKubelet(cr command.Runner) error { glog.Infof("restarting kubelet.service ...") - c := exec.Command("/bin/bash", "-c", "sudo systemctl restart kubelet.service") + c := exec.Command("sudo", "systemctl", "restart", "kubelet.service") if _, err := cr.RunCmd(c); err != nil { return errors.Wrapf(err, "restartKubelet") } @@ -262,7 +262,7 @@ func restartKubelet(cr command.Runner) error { // checkKubelet returns an error if the kubelet is not running. func checkKubelet(cr command.Runner) error { glog.Infof("checking for running kubelet ...") - c := exec.Command("/bin/bash", "-c", "systemctl is-active --quiet service kubelet") + c := exec.Command("systemctl", "is-active", "--quiet", "service", "kubelet") if _, err := cr.RunCmd(c); err != nil { return errors.Wrap(err, "checkKubelet") } diff --git a/pkg/minikube/bootstrapper/certs.go b/pkg/minikube/bootstrapper/certs.go index 484a51e028..c651f0e85c 100644 --- a/pkg/minikube/bootstrapper/certs.go +++ b/pkg/minikube/bootstrapper/certs.go @@ -332,8 +332,7 @@ func getSubjectHash(cr command.Runner, filePath string) (string, error) { // OpenSSL binary required in minikube ISO func configureCACerts(cr command.Runner, caCerts map[string]string) error { hasSSLBinary := true - c := exec.Command("/bin/bash", "-c", "openssl version") - _, err := cr.RunCmd(c) + _, err := cr.RunCmd(exec.Command("openssl version")) if err != nil { hasSSLBinary = false } @@ -348,8 +347,7 @@ func configureCACerts(cr command.Runner, caCerts map[string]string) error { _, err := cr.RunCmd(exec.Command("/bin/bash", "-c", fmt.Sprintf("sudo test -f %s", certStorePath))) if err != nil { - c = exec.Command("/bin/bash", "-c", fmt.Sprintf("sudo ln -s '%s' '%s'", caCertFile, certStorePath)) - + c := exec.Command("/bin/bash", "-c", fmt.Sprintf("sudo ln -s '%s' '%s'", caCertFile, certStorePath)) if _, err := cr.RunCmd(c); err != nil { return errors.Wrapf(err, "error making symbol link for certificate %s", caCertFile) } diff --git a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go index ea192f26c7..1b54a023f6 100644 --- a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go +++ b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go @@ -137,7 +137,7 @@ func NewKubeadmBootstrapper(api libmachine.API) (*Bootstrapper, error) { // GetKubeletStatus returns the kubelet status func (k *Bootstrapper) GetKubeletStatus() (string, error) { - rr, err := k.c.RunCmd(exec.Command("/bin/bash", "-c", "sudo systemctl is-active kubelet")) + rr, err := k.c.RunCmd(exec.Command("sudo", "systemctl", "is-active", "kubelet")) if err != nil { return "", errors.Wrapf(err, "getting kublet status. command: %q", rr.Command()) } @@ -222,15 +222,15 @@ func etcdDataDir() string { // createCompatSymlinks creates compatibility symlinks to transition running services to new directory structures func (k *Bootstrapper) createCompatSymlinks() error { legacyEtcd := "/data/minikube" - rr, err := k.c.RunCmd(exec.Command("/bin/bash", "-c", fmt.Sprintf("sudo test -d %s", legacyEtcd))) - if err != nil { - glog.Infof("%s check failed, skipping compat symlinks: %v", legacyEtcd, err) + + if _, err := k.c.RunCmd(exec.Command("sudo", "test", "-d", legacyEtcd)); err != nil { + glog.Infof("%s skipping compat symlinks: %v", legacyEtcd, err) return nil } glog.Infof("Found %s, creating compatibility symlinks ...", legacyEtcd) - c := exec.Command("/bin/bash", "-c", fmt.Sprintf("sudo ln -s %s %s", legacyEtcd, etcdDataDir())) - if rr, err = k.c.RunCmd(c); err != nil { + c := exec.Command("sudo", "ln", "-s", legacyEtcd, etcdDataDir()) + if rr, err := k.c.RunCmd(c); err != nil { return errors.Wrapf(err, "create symlink failed: %s", rr.Command()) } return nil @@ -300,7 +300,7 @@ func (k *Bootstrapper) StartCluster(k8s config.KubernetesConfig) error { // adjustResourceLimits makes fine adjustments to pod resources that aren't possible via kubeadm config. func (k *Bootstrapper) adjustResourceLimits() error { - rr, err := k.c.RunCmd(exec.Command("/bin/bash", "-c", "cat /proc/$(pgrep kube-apiserver)/oom_adj")) + rr, err := k.c.RunCmd(exec.Command("cat", "/proc/$(pgrep kube-apiserver)/oom_adj")) if err != nil { return errors.Wrap(err, "oom_adj check. command: %q output: %q") } @@ -313,7 +313,7 @@ func (k *Bootstrapper) adjustResourceLimits() error { // Prevent the apiserver from OOM'ing before other pods, as it is our gateway into the cluster. // It'd be preferable to do this via Kubernetes, but kubeadm doesn't have a way to set pod QoS. - if rr, err = k.c.RunCmd(exec.Command("/bin/bash", "-c", "echo -10 | sudo tee /proc/$(pgrep kube-apiserver)/oom_adj")); err != nil { + if _, err = k.c.RunCmd(exec.Command("/bin/bash", "-c", "echo -10 | sudo tee /proc/$(pgrep kube-apiserver)/oom_adj")); err != nil { return errors.Wrap(err, fmt.Sprintf("oom_adj adjust")) } @@ -466,7 +466,7 @@ func (k *Bootstrapper) waitForAPIServer(k8s config.KubernetesConfig) error { // To give a better error message, first check for process existence via ssh // Needs minutes in case the image isn't cached (such as with v1.10.x) err := wait.PollImmediate(time.Millisecond*300, time.Minute*3, func() (bool, error) { - rr, ierr := k.c.RunCmd(exec.Command("/bin/bash", "-c", "sudo pgrep kube-apiserver")) + rr, ierr := k.c.RunCmd(exec.Command("sudo", "pgrep", "kube-apiserver")) if ierr != nil { glog.Warningf("pgrep apiserver: %v cmd: %s", ierr, rr.Command()) return false, nil diff --git a/pkg/minikube/cruntime/containerd.go b/pkg/minikube/cruntime/containerd.go index 6be7030fca..fab3d0a8df 100644 --- a/pkg/minikube/cruntime/containerd.go +++ b/pkg/minikube/cruntime/containerd.go @@ -126,7 +126,7 @@ func (r *Containerd) Style() out.StyleEnum { // Version retrieves the current version of this runtime func (r *Containerd) Version() (string, error) { - c := exec.Command("/bin/bash", "-c", "containerd --version") + c := exec.Command("containerd", "--version") rr, err := r.Runner.RunCmd(c) if err != nil { return "", errors.Wrapf(err, "containerd check version.") @@ -154,14 +154,14 @@ func (r *Containerd) DefaultCNI() bool { // Active returns if containerd is active on the host func (r *Containerd) Active() bool { - c := exec.Command("/bin/bash", "-c", "systemctl is-active --quiet service containerd") + c := exec.Command("systemctl", "is-active", "--quiet", "service", "containerd") _, err := r.Runner.RunCmd(c) return err == nil } // Available returns an error if it is not possible to use this runtime on a host func (r *Containerd) Available() error { - c := exec.Command("/bin/bash", "-c", "command -v containerd") + c := exec.Command("command", "-v", "containerd") if _, err := r.Runner.RunCmd(c); err != nil { return errors.Wrap(err, "check containerd availability.") } @@ -205,7 +205,7 @@ func (r *Containerd) Enable(disOthers bool) error { return err } // Otherwise, containerd will fail API requests with 'Unimplemented' - c := exec.Command("/bin/bash", "-c", "sudo systemctl restart containerd") + c := exec.Command("sudo", "systemctl", "restart", "containerd") if _, err := r.Runner.RunCmd(c); err != nil { return errors.Wrap(err, "enable containrd.") } @@ -214,7 +214,7 @@ func (r *Containerd) Enable(disOthers bool) error { // Disable idempotently disables containerd on a host func (r *Containerd) Disable() error { - c := exec.Command("/bin/bash", "-c", "sudo systemctl stop containerd") + c := exec.Command("sudo", "systemctl", "stop", "containerd") if _, err := r.Runner.RunCmd(c); err != nil { return errors.Wrapf(err, "disable containrd.") } diff --git a/pkg/minikube/cruntime/crio.go b/pkg/minikube/cruntime/crio.go index 70a6cb51ad..0b7b26b359 100644 --- a/pkg/minikube/cruntime/crio.go +++ b/pkg/minikube/cruntime/crio.go @@ -46,7 +46,7 @@ func (r *CRIO) Style() out.StyleEnum { // Version retrieves the current version of this runtime func (r *CRIO) Version() (string, error) { - c := exec.Command("/bin/bash", "-c", "crio --version") + c := exec.Command("crio", "--version") rr, err := r.Runner.RunCmd(c) if err != nil { return "", errors.Wrap(err, "crio version.") @@ -73,7 +73,7 @@ func (r *CRIO) DefaultCNI() bool { // Available returns an error if it is not possible to use this runtime on a host func (r *CRIO) Available() error { - c := exec.Command("/bin/bash", "-c", "command -v crio") + c := exec.Command("command", "-v", "crio") if _, err := r.Runner.RunCmd(c); err != nil { return errors.Wrapf(err, "check crio available.") } @@ -83,7 +83,7 @@ func (r *CRIO) Available() error { // Active returns if CRIO is active on the host func (r *CRIO) Active() bool { - c := exec.Command("/bin/bash", "-c", "systemctl is-active --quiet service crio") + c := exec.Command("systemctl", "is-active", "--quiet", "service", "crio") _, err := r.Runner.RunCmd(c) return err == nil } @@ -105,7 +105,7 @@ func (r *CRIO) Enable(disOthers bool) error { return err } - if _, err := r.Runner.RunCmd(exec.Command("/bin/bash", "-c", "sudo systemctl restart crio")); err != nil { + if _, err := r.Runner.RunCmd(exec.Command("sudo", "systemctl", "restart", "crio")); err != nil { return errors.Wrapf(err, "enable crio.") } return nil @@ -113,7 +113,7 @@ func (r *CRIO) Enable(disOthers bool) error { // Disable idempotently disables CRIO on a host func (r *CRIO) Disable() error { - if _, err := r.Runner.RunCmd(exec.Command("/bin/bash", "-c", "sudo systemctl stop crio")); err != nil { + if _, err := r.Runner.RunCmd(exec.Command("sudo", "systemctl", "stop", "crio")); err != nil { return errors.Wrapf(err, "disable crio.") } return nil @@ -122,7 +122,7 @@ func (r *CRIO) Disable() error { // LoadImage loads an image into this runtime func (r *CRIO) LoadImage(path string) error { glog.Infof("Loading image: %s", path) - c := exec.Command("/bin/bash", "-c", fmt.Sprintf("sudo podman load -i %s", path)) + c := exec.Command("sudo", "podman", "load", "-i", path) if _, err := r.Runner.RunCmd(c); err != nil { return errors.Wrap(err, "LoadImage crio.") } diff --git a/pkg/minikube/cruntime/cruntime.go b/pkg/minikube/cruntime/cruntime.go index ac36f35b04..09db37d162 100644 --- a/pkg/minikube/cruntime/cruntime.go +++ b/pkg/minikube/cruntime/cruntime.go @@ -131,7 +131,7 @@ func disableOthers(me Manager, cr CommandRunner) error { // enableIPForwarding configures IP forwarding, which is handled normally by Docker // Context: https://github.com/kubernetes/kubeadm/issues/1062 func enableIPForwarding(cr CommandRunner) error { - c := exec.Command("/bin/bash", "-c", "sudo modprobe br_netfilter") + c := exec.Command("sudo", "modprobe", "br_netfilter") if _, err := cr.RunCmd(c); err != nil { return errors.Wrap(err, "br_netfilter.") } diff --git a/pkg/minikube/cruntime/docker.go b/pkg/minikube/cruntime/docker.go index c857c8406f..abe00a6f6f 100644 --- a/pkg/minikube/cruntime/docker.go +++ b/pkg/minikube/cruntime/docker.go @@ -48,7 +48,7 @@ func (r *Docker) Style() out.StyleEnum { // Version retrieves the current version of this runtime func (r *Docker) Version() (string, error) { // Note: the server daemon has to be running, for this call to return successfully - c := exec.Command("/bin/bash", "-c", "docker version --format '{{.Server.Version}}'") + c := exec.Command("docker", "version", "--format", "'{{.Server.Version}}'") rr, err := r.Runner.RunCmd(c) if err != nil { return "", err @@ -74,7 +74,7 @@ func (r *Docker) Available() error { // Active returns if docker is active on the host func (r *Docker) Active() bool { - c := exec.Command("/bin/bash", "-c", "systemctl is-active --quiet service docker") + c := exec.Command("systemctl", "is-active", "--quiet", "service", "docker") _, err := r.Runner.RunCmd(c) return err == nil } @@ -86,7 +86,7 @@ func (r *Docker) Enable(disOthers bool) error { glog.Warningf("disableOthers: %v", err) } } - c := exec.Command("/bin/bash", "-c", "sudo systemctl start docker") + c := exec.Command("sudo", "systemctl", "start", "docker") if _, err := r.Runner.RunCmd(c); err != nil { return errors.Wrap(err, "enable docker.") } @@ -95,7 +95,7 @@ func (r *Docker) Enable(disOthers bool) error { // Disable idempotently disables Docker on a host func (r *Docker) Disable() error { - c := exec.Command("/bin/bash", "-c", "sudo systemctl stop docker docker.socket") + c := exec.Command("sudo", "systemctl", "stop", "docker", "docker.socket") if _, err := r.Runner.RunCmd(c); err != nil { return errors.Wrap(err, "disable docker") } @@ -105,7 +105,7 @@ func (r *Docker) Disable() error { // LoadImage loads an image into this runtime func (r *Docker) LoadImage(path string) error { glog.Infof("Loading image: %s", path) - c := exec.Command("/bin/bash", "-c", fmt.Sprintf("docker load -i %s", path)) + c := exec.Command("docker", "load", "-i", path) if _, err := r.Runner.RunCmd(c); err != nil { return errors.Wrap(err, "loadimage docker.") } diff --git a/test/integration/fn_tunnel_cmd.go b/test/integration/fn_tunnel_cmd.go index 56d97a9223..b9e43c8cc2 100644 --- a/test/integration/fn_tunnel_cmd.go +++ b/test/integration/fn_tunnel_cmd.go @@ -43,7 +43,7 @@ func validateTunnelCmd(ctx context.Context, t *testing.T, profile string) { if runtime.GOOS != "windows" { // Otherwise minikube fails waiting for a password. - if err := exec.Command("/bin/bash", "-c", "sudo -n route").Run(); err != nil { + if err := exec.Command("sudo", "-n", "route").Run(); err != nil { t.Skipf("password required to execute 'route', skipping testTunnel: %v", err) } }