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 all commits
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
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
# Bump these on release - and please check ISO_VERSION for correctness.
VERSION_MAJOR ?= 1
VERSION_MINOR ?= 5
VERSION_BUILD ?= 0
VERSION_BUILD ?= 1
RAW_VERSION=$(VERSION_MAJOR).$(VERSION_MINOR).${VERSION_BUILD}
VERSION ?= v$(RAW_VERSION)

# Default to .0 for higher cache hit rates, as build increments typically don't require new ISO versions
ISO_VERSION ?= v$(VERSION_MAJOR).$(VERSION_MINOR).0
ISO_VERSION ?= v$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_BUILD)
# Dashes are valid in semver, but not Linux packaging. Use ~ to delimit alpha/beta
DEB_VERSION ?= $(subst -,~,$(RAW_VERSION))
RPM_VERSION ?= $(DEB_VERSION)
Expand Down Expand Up @@ -572,4 +572,4 @@ site: site/themes/docsy/assets/vendor/bootstrap/package.js out/hugo/hugo

.PHONY: out/mkcmp
out/mkcmp:
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o $@ cmd/performance/main.go
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o $@ cmd/performance/main.go
12 changes: 7 additions & 5 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -1024,27 +1024,29 @@ Suggested workarounds:
defer conn.Close()
}

if err := r.Run("nslookup kubernetes.io"); err != nil {
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})
}

// Try both UDP and ICMP to assert basic external connectivity
if err := r.Run("nslookup k8s.io 8.8.8.8 || nslookup k8s.io 1.1.1.1 || ping -c1 8.8.8.8"); err != nil {
if _, err := r.RunCmd(exec.Command("/bin/bash", "-c", "nslookup k8s.io 8.8.8.8 || nslookup k8s.io 1.1.1.1 || ping -c1 8.8.8.8")); err != nil {
out.WarningT("VM is unable to directly connect to the internet: {{.error}}", out.V{"error": err})
}

// Try an HTTPS connection to the
proxy := os.Getenv("HTTPS_PROXY")
opts := "-sS"
opts := []string{"-sS"}
if proxy != "" && !strings.HasPrefix(proxy, "localhost") && !strings.HasPrefix(proxy, "127.0") {
opts = fmt.Sprintf("-x %s %s", proxy, opts)
opts = append([]string{"-x", proxy}, opts...)
}

repo := viper.GetString(imageRepository)
if repo == "" {
repo = images.DefaultImageRepo
}
if err := r.Run(fmt.Sprintf("curl %s https://%s/", opts, repo)); err != nil {

opts = append(opts, fmt.Sprintf("https://%s/", repo))
if _, err := r.RunCmd(exec.Command("curl", opts...)); err != nil {
out.WarningT("VM is unable to connect to the selected image repository: {{.error}}", out.V{"error": err})
}
return ip
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ require (
github.com/juju/testing v0.0.0-20190723135506-ce30eb24acd2 // indirect
github.com/juju/utils v0.0.0-20180820210520-bf9cc5bdd62d // indirect
github.com/juju/version v0.0.0-20180108022336-b64dbd566305 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/libvirt/libvirt-go v3.4.0+incompatible
github.com/machine-drivers/docker-machine-driver-vmware v0.1.1
github.com/mattn/go-isatty v0.0.8
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ github.com/juju/version v0.0.0-20180108022336-b64dbd566305 h1:lQxPJ1URr2fjsKnJRt
github.com/juju/version v0.0.0-20180108022336-b64dbd566305/go.mod h1:kE8gK5X0CImdr7qpSKl3xB2PmpySSmfj7zVbkZFs81U=
github.com/kardianos/osext v0.0.0-20150410034420-8fef92e41e22/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
github.com/karrick/godirwalk v1.7.5/go.mod h1:2c9FRhkDxdIbgkOnCEvnSWs71Bhugbl46shStcFDJ34=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
Expand Down
44 changes: 25 additions & 19 deletions pkg/drivers/none/none.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ limitations under the License.
package none

import (
"bytes"
"fmt"
"os/exec"
"strings"
"time"

Expand Down Expand Up @@ -168,8 +168,8 @@ func (d *Driver) Remove() error {
return errors.Wrap(err, "kill")
}
glog.Infof("Removing: %s", cleanupPaths)
cmd := fmt.Sprintf("sudo rm -rf %s", strings.Join(cleanupPaths, " "))
if err := d.exec.Run(cmd); err != nil {
args := append([]string{"rm", "-rf"}, cleanupPaths...)
if _, err := d.exec.RunCmd(exec.Command("sudo", args...)); err != nil {
glog.Errorf("cleanup incomplete: %v", err)
}
return nil
Expand Down Expand Up @@ -217,22 +217,20 @@ func (d *Driver) RunSSHCommandFromDriver() error {
}

// stopKubelet idempotently stops the kubelet
func stopKubelet(exec command.Runner) error {
func stopKubelet(cr command.Runner) error {
glog.Infof("stopping kubelet.service ...")
stop := func() error {
cmdStop := "sudo systemctl stop kubelet.service"
cmdCheck := "sudo systemctl show -p SubState kubelet"
err := exec.Run(cmdStop)
if err != nil {
glog.Errorf("temporary error for %q : %v", cmdStop, err)
cmd := exec.Command("sudo", "systemctl", "stop", "kubelet.service")
if rr, err := cr.RunCmd(cmd); err != nil {
glog.Errorf("temporary error for %q : %v", rr.Command(), err)
}
var out bytes.Buffer
errStatus := exec.CombinedOutputTo(cmdCheck, &out)
if errStatus != nil {
glog.Errorf("temporary error: for %q : %v", cmdCheck, errStatus)
cmd = exec.Command("sudo", "systemctl", "show", "-p", "SubState", "kubelet")
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") {
return fmt.Errorf("unexpected kubelet state: %q", out)
if !strings.Contains(rr.Stdout.String(), "dead") && !strings.Contains(rr.Stdout.String(), "failed") {
return fmt.Errorf("unexpected kubelet state: %q", rr.Stdout.String())
}
return nil
}
Expand All @@ -245,13 +243,21 @@ func stopKubelet(exec command.Runner) error {
}

// restartKubelet restarts the kubelet
func restartKubelet(exec command.Runner) error {
func restartKubelet(cr command.Runner) error {
glog.Infof("restarting kubelet.service ...")
return exec.Run("sudo systemctl restart kubelet.service")
c := exec.Command("sudo", "systemctl", "restart", "kubelet.service")
if _, err := cr.RunCmd(c); err != nil {
return err
}
return nil
}

// checkKubelet returns an error if the kubelet is not running.
func checkKubelet(exec command.Runner) error {
func checkKubelet(cr command.Runner) error {
glog.Infof("checking for running kubelet ...")
return exec.Run("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, "check kubelet")
}
return nil
}
36 changes: 19 additions & 17 deletions pkg/minikube/bootstrapper/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"io/ioutil"
"net"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
Expand Down Expand Up @@ -141,7 +142,7 @@ func SetupCerts(cmd command.Runner, k8s config.KubernetesConfig) error {

// configure CA certificates
if err := configureCACerts(cmd, caCerts); err != nil {
return errors.Wrapf(err, "error configuring CA certificates during provisioning %v", err)
return errors.Wrapf(err, "Configuring CA certs")
}
return nil
}
Expand Down Expand Up @@ -318,21 +319,21 @@ func collectCACerts() (map[string]string, error) {
}

// getSubjectHash calculates Certificate Subject Hash for creating certificate symlinks
func getSubjectHash(cmd command.Runner, filePath string) (string, error) {
out, err := cmd.CombinedOutput(fmt.Sprintf("openssl x509 -hash -noout -in '%s'", filePath))
func getSubjectHash(cr command.Runner, filePath string) (string, error) {
rr, err := cr.RunCmd(exec.Command("openssl", "x509", "-hash", "-noout", "-in", filePath))
if err != nil {
return "", err
return "", errors.Wrapf(err, rr.Command())
}

stringHash := strings.TrimSpace(out)
stringHash := strings.TrimSpace(rr.Stdout.String())
return stringHash, nil
}

// configureCACerts looks up and installs all uploaded PEM certificates in /usr/share/ca-certificates to system-wide certificate store (/etc/ssl/certs).
// OpenSSL binary required in minikube ISO
func configureCACerts(cmd command.Runner, caCerts map[string]string) error {
func configureCACerts(cr command.Runner, caCerts map[string]string) error {
hasSSLBinary := true
if err := cmd.Run("which openssl"); err != nil {
_, err := cr.RunCmd(exec.Command("openssl", "version"))
if err != nil {
hasSSLBinary = false
}

Expand All @@ -343,24 +344,25 @@ func configureCACerts(cmd command.Runner, caCerts map[string]string) error {
for _, caCertFile := range caCerts {
dstFilename := path.Base(caCertFile)
certStorePath := path.Join(SSLCertStoreDir, dstFilename)
if err := cmd.Run(fmt.Sprintf("sudo test -f '%s'", certStorePath)); err != nil {
if err := cmd.Run(fmt.Sprintf("sudo ln -s '%s' '%s'", caCertFile, certStorePath)); err != nil {
return errors.Wrapf(err, "error making symbol link for certificate %s", caCertFile)
_, 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, "create symlink for %s", caCertFile)
}
}
if hasSSLBinary {
subjectHash, err := getSubjectHash(cmd, caCertFile)
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))
if err := cmd.Run(fmt.Sprintf("sudo test -f '%s'", subjectHashLink)); err != nil {
if err := cmd.Run(fmt.Sprintf("sudo ln -s '%s' '%s'", certStorePath, subjectHashLink)); err != nil {
return errors.Wrapf(err, "error making subject hash symbol link for certificate %s", caCertFile)
_, 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 nil
}
6 changes: 3 additions & 3 deletions pkg/minikube/bootstrapper/certs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ func TestSetupCerts(t *testing.T) {
certStorePath := path.Join(SSLCertStoreDir, dst)
certNameHash := "abcdef"
remoteCertHashLink := path.Join(SSLCertStoreDir, fmt.Sprintf("%s.0", certNameHash))
cmdMap[fmt.Sprintf("sudo ln -s '%s' '%s'", certFile, certStorePath)] = "1"
cmdMap[fmt.Sprintf("openssl x509 -hash -noout -in '%s'", certFile)] = certNameHash
cmdMap[fmt.Sprintf("sudo ln -s '%s' '%s'", certStorePath, remoteCertHashLink)] = "1"
cmdMap[fmt.Sprintf("sudo ln -s %s %s", certFile, certStorePath)] = "1"
cmdMap[fmt.Sprintf("openssl x509 -hash -noout -in %s", certFile)] = certNameHash
cmdMap[fmt.Sprintf("sudo ln -s %s %s", certStorePath, remoteCertHashLink)] = "1"
}
f := command.NewFakeCommandRunner()
f.SetCommandToOutput(cmdMap)
Expand Down
Loading