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

Refactor command runner interface, allow stdin writes #5530

Merged
merged 62 commits into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
809389c
implementing new interface RunCmd for exec_runner & fake_runner
medyagh Oct 2, 2019
8818324
move teePrefix from util to ssh_runner
medyagh Oct 2, 2019
eaa0171
move unit tests from util to command_runner
medyagh Oct 2, 2019
2f276e2
fix format type
medyagh Oct 3, 2019
27321d5
add ExecCmd and convert kubeadm,cert to new interface
medyagh Oct 4, 2019
36de216
fixing fake_runner for interface
medyagh Oct 4, 2019
c7af9e7
remove extra error wrap
medyagh Oct 4, 2019
4644207
improve error wrap
medyagh Oct 4, 2019
52dc6ad
travis buddy to only return error
medyagh Oct 4, 2019
12fab35
travis-buddy config
medyagh Oct 4, 2019
a6cf688
travisbuddy tweak
medyagh Oct 4, 2019
723f62c
tweak travisbuddy regex
medyagh Oct 4, 2019
d75f417
tweak travisbuddy regex again
medyagh Oct 4, 2019
7709c77
fix formatting
medyagh Oct 7, 2019
9df5618
fix fakerunner runcmd unit test
medyagh Oct 7, 2019
8fcdae9
refactor
medyagh Oct 7, 2019
a78deab
adding a new ExecCmd2
medyagh Oct 8, 2019
0c435b0
fix unit test for cert
medyagh Oct 8, 2019
b8181a0
move more to exec.Cmd2
medyagh Oct 8, 2019
9271463
get rid of ExecCmd2
medyagh Oct 8, 2019
91618aa
get rid of ExecCmd all the way
medyagh Oct 8, 2019
25e3d87
fixing with shelquote
medyagh Oct 9, 2019
83f736d
fix unit test for cert
medyagh Oct 9, 2019
da5cae6
shellquoting more
medyagh Oct 9, 2019
79e65c1
fix
medyagh Oct 9, 2019
7109b22
refactor more
medyagh Oct 9, 2019
57ac160
move everything to RunCmd
medyagh Oct 10, 2019
fcf17fb
bin bash all the way
medyagh Oct 10, 2019
f8b38d2
Merge remote-tracking branch 'upstream/master' into NewCmdRunner
medyagh Oct 10, 2019
466123a
fix some lint nad test
medyagh Oct 10, 2019
c71b677
fix more commands to bin bash
medyagh Oct 11, 2019
eac0220
add unit test for cmdToStr
medyagh Oct 11, 2019
3909925
fix more stuf
medyagh Oct 12, 2019
749c34a
adding a logging to make sure jenkins is running right thing
medyagh Oct 12, 2019
1da56c5
printing minikube version and commit id before test
medyagh Oct 12, 2019
5c9d98f
echo minikube version in integration script
medyagh Oct 12, 2019
a7de6c7
add minikube binary version
medyagh Oct 12, 2019
aace212
fix unit test, remove mount fake runner
medyagh Oct 14, 2019
74b7054
fixing logs
medyagh Oct 15, 2019
48cd862
fix stdout,stderr
medyagh Oct 21, 2019
6bd5d9b
Merge remote-tracking branch 'upstream/master' into NewCmdRunner
medyagh Oct 21, 2019
342397a
convert more to exec.Command
medyagh Oct 21, 2019
6faf9cd
lint and code review
medyagh Oct 21, 2019
6e1c4f6
trying to fix logs
medyagh Oct 21, 2019
05bbcf7
remove uneeded wrap output
medyagh Oct 21, 2019
45e5beb
fixing pointer and teeSSH
medyagh Oct 22, 2019
900123b
Fixing pointer and unit test
medyagh Oct 24, 2019
415f0ca
makefile conflict
medyagh Oct 24, 2019
187dfe2
getting rid of some of bin bash -c
medyagh Oct 24, 2019
ddabc9e
remove extra error word
medyagh Oct 24, 2019
0d8c894
fix unit test and remove more bin bash c
medyagh Oct 24, 2019
01573e4
removed more bin bash calls
medyagh Oct 25, 2019
69dba7c
Fix exec runner and remove some debug logging
medyagh Oct 25, 2019
291731c
change shellquote to args
medyagh Oct 25, 2019
592ea15
fix none docker test
medyagh Oct 25, 2019
792de2b
resolve code review
medyagh Oct 26, 2019
1b834df
fix unit test
medyagh Oct 26, 2019
e2bbf71
Merge branch 'master' into NewCmdRunner
medyagh Oct 27, 2019
29a015b
remove more bin bash c
medyagh Oct 28, 2019
cd9e413
resolve code review
medyagh Oct 29, 2019
773c525
fix test and remove extra code
medyagh Oct 29, 2019
77ccd46
resolve conflict
medyagh Oct 30, 2019
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
7 changes: 4 additions & 3 deletions pkg/drivers/none/none.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,11 @@ func stopKubelet(cr command.Runner) error {
cmd = exec.Command("sudo", "systemctl", "show", "-p", "SubState", "kubelet")
cmd.Stdout = &out
medyagh marked this conversation as resolved.
Show resolved Hide resolved
cmd.Stderr = &out
if rr, err := cr.RunCmd(cmd); err != nil {
rr, err := cr.RunCmd(cmd)
if err != nil {
glog.Errorf("temporary error: for %q : %v", rr.Command(), err)
}
if !strings.Contains(out.String(), "dead") && !strings.Contains(out.String(), "failed") {
if !strings.Contains(rr.Stdout.String(), "dead") && !strings.Contains(rr.Stdout.String(), "failed") {
return fmt.Errorf("unexpected kubelet state: %q", out)
}
return nil
Expand Down Expand Up @@ -260,7 +261,7 @@ func checkKubelet(cr command.Runner) error {
glog.Infof("checking for running kubelet ...")
c := exec.Command("systemctl", "is-active", "--quiet", "service", "kubelet")
if _, err := cr.RunCmd(c); err != nil {
return errors.Wrap(err, "checkKubelet")
return errors.Wrap(err, "check kubelet")
}
return nil
}
6 changes: 3 additions & 3 deletions pkg/minikube/bootstrapper/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,19 +347,19 @@ func configureCACerts(cr command.Runner, caCerts map[string]string) error {
_, err := cr.RunCmd(exec.Command("sudo", "test", "-f", certStorePath))
if err != nil {
if _, err := cr.RunCmd(exec.Command("sudo", "ln", "-s", caCertFile, certStorePath)); err != nil {
return errors.Wrapf(err, "error making symbol link for certificate %s", caCertFile)
return errors.Wrapf(err, "create symlink for %s", caCertFile)
}
}
if hasSSLBinary {
subjectHash, err := getSubjectHash(cr, caCertFile)
if err != nil {
return errors.Wrapf(err, "error calculating subject hash for certificate %s", caCertFile)
return errors.Wrapf(err, "calculate hash for cacert %s", caCertFile)
}
subjectHashLink := path.Join(SSLCertStoreDir, fmt.Sprintf("%s.0", subjectHash))
_, err = cr.RunCmd(exec.Command("sudo", "test", "-f", subjectHashLink))
if err != nil {
if _, err := cr.RunCmd(exec.Command("sudo", "ln", "-s", certStorePath, subjectHashLink)); err != nil {
return errors.Wrapf(err, "linking caCertFile %s.", caCertFile)
return errors.Wrapf(err, "linking caCertFile %s", caCertFile)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,8 +642,8 @@ func (k *Bootstrapper) UpdateCluster(cfg config.KubernetesConfig) error {
}
}

if _, err := k.c.RunCmd(exec.Command("/bin/bash", "-c", "set -x;sudo systemctl daemon-reload && sudo systemctl start kubelet")); err != nil {
return errors.Wrap(err, "starting kubelet.")
if _, err := k.c.RunCmd(exec.Command("/bin/bash", "-c", "sudo systemctl daemon-reload && sudo systemctl start kubelet")); err != nil {
return errors.Wrap(err, "starting kubelet")
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/minikube/command/command_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ type RunResult struct {

// Runner represents an interface to run commands.
type Runner interface {
// RunCmd is a new expermintal way to run commands, takes Cmd interface and returns run result.
// if succesfull will cause a clean up to get rid of older methods.
// RunCmd runs a cmd of exec.Cmd type. allowing user to set cmd.Stdin, cmd.Stdout,...
// not all implementors are guaranteed to handle all the properties of cmd.
RunCmd(cmd *exec.Cmd) (*RunResult, error)

// Copy is a convenience method that runs a command to copy a file
Expand Down
3 changes: 1 addition & 2 deletions pkg/minikube/command/exec_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package command

import (
"bytes"
"fmt"
"io"
"os"
"os/exec"
Expand Down Expand Up @@ -73,7 +72,7 @@ func (*ExecRunner) RunCmd(cmd *exec.Cmd) (*RunResult, error) {
rr.ExitCode = exitError.ExitCode()
}
glog.Infof("(ExecRunner) Non-zero exit: %v: %v (%s)\n%s", rr.Command(), err, elapsed, rr.Output())
err = errors.Wrapf(err, fmt.Sprintf("stderr: %s", rr.Stderr.String()))
err = errors.Wrapf(err, "command failed: %s\nstdout: %s\nstderr: %s", cmd, rr.Stdout.String(), rr.Stderr.String())
}
return rr, err
medyagh marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/minikube/cruntime/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (r *Containerd) Active() bool {

// Available returns an error if it is not possible to use this runtime on a host
func (r *Containerd) Available() error {
c := exec.Command("command", "-v", "containerd")
c := exec.Command("which", "containerd")
if _, err := r.Runner.RunCmd(c); err != nil {
return errors.Wrap(err, "check containerd availability.")
}
Expand Down Expand Up @@ -207,7 +207,7 @@ func (r *Containerd) Enable(disOthers bool) error {
// Otherwise, containerd will fail API requests with 'Unimplemented'
c := exec.Command("sudo", "systemctl", "restart", "containerd")
if _, err := r.Runner.RunCmd(c); err != nil {
return errors.Wrap(err, "enable containrd.")
return errors.Wrap(err, "restart containerd")
}
return nil
}
Expand All @@ -216,17 +216,17 @@ func (r *Containerd) Enable(disOthers bool) error {
func (r *Containerd) Disable() error {
c := exec.Command("sudo", "systemctl", "stop", "containerd")
if _, err := r.Runner.RunCmd(c); err != nil {
return errors.Wrapf(err, "disable containrd.")
return errors.Wrapf(err, "stop containerd")
}
return nil
}

// LoadImage loads an image into this runtime
func (r *Containerd) LoadImage(path string) error {
glog.Infof("Loading image: %s", path)
c := exec.Command("ctr", "-n=k8s.io", "images", "import", path)
c := exec.Command("sudo", "ctr", "-n=k8s.io", "images", "import", path)
if _, err := r.Runner.RunCmd(c); err != nil {
return errors.Wrapf(err, "disable containrd.")
return errors.Wrapf(err, "ctr images import")
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/minikube/cruntime/crio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("command", "-v", "crio")
c := exec.Command("which", "crio")
if _, err := r.Runner.RunCmd(c); err != nil {
return errors.Wrapf(err, "check crio available.")
}
Expand Down Expand Up @@ -124,7 +124,7 @@ func (r *CRIO) LoadImage(path string) error {
glog.Infof("Loading image: %s", path)
c := exec.Command("sudo", "podman", "load", "-i", path)
if _, err := r.Runner.RunCmd(c); err != nil {
return errors.Wrap(err, "LoadImage crio.")
return errors.Wrap(err, "crio load image")
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/minikube/cruntime/cruntime.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ func disableOthers(me Manager, cr CommandRunner) error {
func enableIPForwarding(cr CommandRunner) error {
c := exec.Command("sudo", "modprobe", "br_netfilter")
if _, err := cr.RunCmd(c); err != nil {
return errors.Wrap(err, "br_netfilter.")
return errors.Wrap(err, "br_netfilter")
}

c = exec.Command("sudo", "sh", "-c", "echo 1 > /proc/sys/net/ipv4/ip_forward")
if _, err := cr.RunCmd(c); err != nil {
return errors.Wrapf(err, "ip_forward.")
return errors.Wrapf(err, "ip_forward")
}
return nil
}