Merge pull request #9922 from afbjorklund/sudo-linux

Only use sudo with the none driver when on linux
pull/9924/head
Thomas Strömberg 2020-12-10 14:47:45 -08:00 committed by GitHub
commit 5d3cc59902
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 21 deletions

View File

@ -292,7 +292,7 @@ func (d *Driver) Kill() error {
klog.Warningf("couldn't shutdown the container, will continue with kill anyways: %v", err)
}
cr := command.NewExecRunner() // using exec runner for interacting with dameon.
cr := command.NewExecRunner(false) // using exec runner for interacting with dameon.
if _, err := cr.RunCmd(oci.PrefixCmd(exec.Command(d.NodeConfig.OCIBinary, "kill", d.MachineName))); err != nil {
return errors.Wrapf(err, "killing %q", d.MachineName)
}

View File

@ -61,7 +61,7 @@ type Config struct {
// NewDriver returns a fully configured None driver
func NewDriver(c Config) *Driver {
runner := command.NewExecRunner()
runner := command.NewExecRunner(true)
runtime, err := cruntime.New(cruntime.Config{Type: c.ContainerRuntime, Runner: runner})
// Libraries shouldn't panic, but there is no way for drivers to return error :(
if err != nil {

View File

@ -38,18 +38,23 @@ import (
//
// It implements the CommandRunner interface.
type execRunner struct {
sudo bool
}
// NewExecRunner returns a kicRunner implementor of runner which runs cmds inside a container
func NewExecRunner() Runner {
return &execRunner{}
func NewExecRunner(sudo bool) Runner {
return &execRunner{sudo: sudo}
}
// RunCmd implements the Command Runner interface to run a exec.Cmd object
func (*execRunner) RunCmd(cmd *exec.Cmd) (*RunResult, error) {
func (e *execRunner) RunCmd(cmd *exec.Cmd) (*RunResult, error) {
rr := &RunResult{Args: cmd.Args}
klog.Infof("Run: %v", rr.Command())
if e.sudo && runtime.GOOS != "linux" {
return nil, fmt.Errorf("sudo not supported on %s", runtime.GOOS)
}
var outb, errb io.Writer
if cmd.Stdout == nil {
var so bytes.Buffer
@ -107,8 +112,7 @@ func (e *execRunner) Copy(f assets.CopyableFile) error {
return errors.Wrapf(err, "error converting permissions %s to integer", f.GetPermissions())
}
switch runtime.GOOS {
case "linux":
if e.sudo {
// write to temp location ...
tmpfile, err := ioutil.TempFile("", "minikube")
if err != nil {
@ -129,17 +133,15 @@ func (e *execRunner) Copy(f assets.CopyableFile) error {
// ... then fix file permission that should have been fine because of "cp -a"
err = os.Chmod(dst, os.FileMode(perms))
return err
default:
return writeFile(dst, f, os.FileMode(perms))
}
return writeFile(dst, f, os.FileMode(perms))
}
// Remove removes a file
func (e *execRunner) Remove(f assets.CopyableFile) error {
dst := filepath.Join(f.GetTargetDir(), f.GetTargetName())
klog.Infof("rm: %s", dst)
if e.sudo {
if err := os.Remove(dst); err != nil {
if !os.IsPermission(err) {
return err
@ -150,4 +152,6 @@ func (e *execRunner) Remove(f assets.CopyableFile) error {
}
}
return nil
}
return os.Remove(dst)
}

View File

@ -154,7 +154,7 @@ func CommandRunner(h *host.Host) (command.Runner, error) {
return &command.FakeCommandRunner{}, nil
}
if driver.BareMetal(h.Driver.DriverName()) {
return command.NewExecRunner(), nil
return command.NewExecRunner(true), nil
}
return command.NewSSHRunner(h.Driver), nil

View File

@ -147,7 +147,7 @@ func copyHostCerts(authOptions auth.Options) error {
authOptions.ClientKeyPath: path.Join(authOptions.StorePath, "key.pem"),
}
execRunner := command.NewExecRunner()
execRunner := command.NewExecRunner(false)
for src, dst := range hostCerts {
f, err := assets.NewFileAsset(src, path.Dir(dst), filepath.Base(dst), "0777")
if err != nil {