Only use sudo with the none driver when on linux
parent
ead11c65cd
commit
c3d0621d97
|
@ -292,7 +292,7 @@ func (d *Driver) Kill() error {
|
||||||
klog.Warningf("couldn't shutdown the container, will continue with kill anyways: %v", err)
|
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 {
|
if _, err := cr.RunCmd(oci.PrefixCmd(exec.Command(d.NodeConfig.OCIBinary, "kill", d.MachineName))); err != nil {
|
||||||
return errors.Wrapf(err, "killing %q", d.MachineName)
|
return errors.Wrapf(err, "killing %q", d.MachineName)
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ type Config struct {
|
||||||
|
|
||||||
// NewDriver returns a fully configured None driver
|
// NewDriver returns a fully configured None driver
|
||||||
func NewDriver(c Config) *Driver {
|
func NewDriver(c Config) *Driver {
|
||||||
runner := command.NewExecRunner()
|
runner := command.NewExecRunner(true)
|
||||||
runtime, err := cruntime.New(cruntime.Config{Type: c.ContainerRuntime, Runner: runner})
|
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 :(
|
// Libraries shouldn't panic, but there is no way for drivers to return error :(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -38,18 +38,23 @@ import (
|
||||||
//
|
//
|
||||||
// It implements the CommandRunner interface.
|
// It implements the CommandRunner interface.
|
||||||
type execRunner struct {
|
type execRunner struct {
|
||||||
|
sudo bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewExecRunner returns a kicRunner implementor of runner which runs cmds inside a container
|
// NewExecRunner returns a kicRunner implementor of runner which runs cmds inside a container
|
||||||
func NewExecRunner() Runner {
|
func NewExecRunner(sudo bool) Runner {
|
||||||
return &execRunner{}
|
return &execRunner{sudo: sudo}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunCmd implements the Command Runner interface to run a exec.Cmd object
|
// 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}
|
rr := &RunResult{Args: cmd.Args}
|
||||||
klog.Infof("Run: %v", rr.Command())
|
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
|
var outb, errb io.Writer
|
||||||
if cmd.Stdout == nil {
|
if cmd.Stdout == nil {
|
||||||
var so bytes.Buffer
|
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())
|
return errors.Wrapf(err, "error converting permissions %s to integer", f.GetPermissions())
|
||||||
}
|
}
|
||||||
|
|
||||||
switch runtime.GOOS {
|
if e.sudo {
|
||||||
case "linux":
|
|
||||||
// write to temp location ...
|
// write to temp location ...
|
||||||
tmpfile, err := ioutil.TempFile("", "minikube")
|
tmpfile, err := ioutil.TempFile("", "minikube")
|
||||||
if err != nil {
|
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"
|
// ... then fix file permission that should have been fine because of "cp -a"
|
||||||
err = os.Chmod(dst, os.FileMode(perms))
|
err = os.Chmod(dst, os.FileMode(perms))
|
||||||
return err
|
return err
|
||||||
|
|
||||||
default:
|
|
||||||
return writeFile(dst, f, os.FileMode(perms))
|
|
||||||
}
|
}
|
||||||
|
return writeFile(dst, f, os.FileMode(perms))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove removes a file
|
// Remove removes a file
|
||||||
func (e *execRunner) Remove(f assets.CopyableFile) error {
|
func (e *execRunner) Remove(f assets.CopyableFile) error {
|
||||||
dst := filepath.Join(f.GetTargetDir(), f.GetTargetName())
|
dst := filepath.Join(f.GetTargetDir(), f.GetTargetName())
|
||||||
klog.Infof("rm: %s", dst)
|
klog.Infof("rm: %s", dst)
|
||||||
|
if e.sudo {
|
||||||
if err := os.Remove(dst); err != nil {
|
if err := os.Remove(dst); err != nil {
|
||||||
if !os.IsPermission(err) {
|
if !os.IsPermission(err) {
|
||||||
return err
|
return err
|
||||||
|
@ -150,4 +152,6 @@ func (e *execRunner) Remove(f assets.CopyableFile) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
}
|
||||||
|
return os.Remove(dst)
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,7 +154,7 @@ func CommandRunner(h *host.Host) (command.Runner, error) {
|
||||||
return &command.FakeCommandRunner{}, nil
|
return &command.FakeCommandRunner{}, nil
|
||||||
}
|
}
|
||||||
if driver.BareMetal(h.Driver.DriverName()) {
|
if driver.BareMetal(h.Driver.DriverName()) {
|
||||||
return command.NewExecRunner(), nil
|
return command.NewExecRunner(true), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return command.NewSSHRunner(h.Driver), nil
|
return command.NewSSHRunner(h.Driver), nil
|
||||||
|
|
|
@ -147,7 +147,7 @@ func copyHostCerts(authOptions auth.Options) error {
|
||||||
authOptions.ClientKeyPath: path.Join(authOptions.StorePath, "key.pem"),
|
authOptions.ClientKeyPath: path.Join(authOptions.StorePath, "key.pem"),
|
||||||
}
|
}
|
||||||
|
|
||||||
execRunner := command.NewExecRunner()
|
execRunner := command.NewExecRunner(false)
|
||||||
for src, dst := range hostCerts {
|
for src, dst := range hostCerts {
|
||||||
f, err := assets.NewFileAsset(src, path.Dir(dst), filepath.Base(dst), "0777")
|
f, err := assets.NewFileAsset(src, path.Dir(dst), filepath.Base(dst), "0777")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue