Skip to content

Commit

Permalink
Added none driver
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-prindle committed Apr 18, 2017
1 parent cf20e54 commit 9453860
Show file tree
Hide file tree
Showing 17 changed files with 470 additions and 45 deletions.
6 changes: 3 additions & 3 deletions cmd/minikube/cmd/config/disable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestDisableUnknownAddon(t *testing.T) {
}
}

func TestDisableValidAddonNoVM(t *testing.T) {
func TestDisableValidAddonLocal(t *testing.T) {
tempDir := tests.MakeTempDir()
defer os.RemoveAll(tempDir)

Expand All @@ -60,7 +60,7 @@ func TestDisableValidAddonNoVM(t *testing.T) {
}
}

func TestDeleteAddonViaDriver(t *testing.T) {
func TestDeleteAddonSSH(t *testing.T) {
s, _ := tests.NewSSHServer()
port, err := s.Start()
if err != nil {
Expand All @@ -76,7 +76,7 @@ func TestDeleteAddonViaDriver(t *testing.T) {
}

dashboard := assets.Addons["dashboard"]
if err := deleteAddonViaDriver(dashboard, d); err != nil {
if err := deleteAddonSSH(dashboard, d); err != nil {
t.Fatalf("Unexpected error %s deleting addon", err)
}
// check command(s) were run
Expand Down
6 changes: 3 additions & 3 deletions cmd/minikube/cmd/config/enable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestEnableUnknownAddon(t *testing.T) {
}
}

func TestEnableValidAddonNoVM(t *testing.T) {
func TestEnableValidAddonLocal(t *testing.T) {
tempDir := tests.MakeTempDir()
defer os.RemoveAll(tempDir)

Expand All @@ -59,7 +59,7 @@ func TestEnableValidAddonNoVM(t *testing.T) {
}
}

func TestTransferAddonViaDriver(t *testing.T) {
func TestTransferAddonSSH(t *testing.T) {
s, _ := tests.NewSSHServer()
port, err := s.Start()
if err != nil {
Expand All @@ -75,7 +75,7 @@ func TestTransferAddonViaDriver(t *testing.T) {
}

dashboard := assets.Addons["dashboard"]
if err := transferAddonViaDriver(dashboard, d); err != nil {
if err := transferAddonSSH(dashboard, d); err != nil {
t.Fatalf("Unexpected error %s transferring addon", err)
}
// check contents
Expand Down
55 changes: 51 additions & 4 deletions cmd/minikube/cmd/config/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package config
import (
"fmt"
"os"
"path/filepath"
"strconv"

"github.com/docker/machine/libmachine/drivers"
Expand Down Expand Up @@ -110,18 +111,18 @@ func EnableOrDisableAddon(name string, val string) error {
}
host, err := cluster.CheckIfApiExistsAndLoad(api)
if enable {
if err = transferAddonViaDriver(addon, host.Driver); err != nil {
if err = transferAddon(addon, host.Driver); err != nil {
return errors.Wrapf(err, "Error transferring addon %s to VM", name)
}
} else {
if err = deleteAddonViaDriver(addon, host.Driver); err != nil {
if err = deleteAddon(addon, host.Driver); err != nil {
return errors.Wrapf(err, "Error deleting addon %s from VM", name)
}
}
return nil
}

func deleteAddonViaDriver(addon *assets.Addon, d drivers.Driver) error {
func deleteAddonSSH(addon *assets.Addon, d drivers.Driver) error {
client, err := sshutil.NewSSHClient(d)
if err != nil {
return err
Expand All @@ -132,7 +133,30 @@ func deleteAddonViaDriver(addon *assets.Addon, d drivers.Driver) error {
return nil
}

func transferAddonViaDriver(addon *assets.Addon, d drivers.Driver) error {
func deleteAddon(addon *assets.Addon, d drivers.Driver) error {
if d.DriverName() == "none" {
if err := deleteAddonLocal(addon, d); err != nil {
return err
}
} else {
if err := deleteAddonSSH(addon, d); err != nil {
return err
}
}
return nil
}

func deleteAddonLocal(addon *assets.Addon, d drivers.Driver) error {
var err error
for _, f := range addon.Assets {
if err = os.Remove(filepath.Join(f.GetTargetDir(), f.GetTargetName())); err != nil {
return err
}
}
return err
}

func transferAddonSSH(addon *assets.Addon, d drivers.Driver) error {
client, err := sshutil.NewSSHClient(d)
if err != nil {
return err
Expand All @@ -158,3 +182,26 @@ func EnableOrDisableDefaultStorageClass(name, val string) error {
}
return EnableOrDisableAddon(name, val)
}

func transferAddon(addon *assets.Addon, d drivers.Driver) error {
if d.DriverName() == "none" {
if err := transferAddonLocal(addon, d); err != nil {
return err
}
} else {
if err := transferAddonSSH(addon, d); err != nil {
return err
}
}
return nil
}

func transferAddonLocal(addon *assets.Addon, d drivers.Driver) error {
var err error
for _, f := range addon.Assets {
if err = assets.CopyFileLocal(f); err != nil {
return err
}
}
return err
}
9 changes: 9 additions & 0 deletions cmd/minikube/cmd/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ var sshCmd = &cobra.Command{
os.Exit(1)
}
defer api.Close()
host, err := cluster.CheckIfApiExistsAndLoad(api)
if err != nil {
fmt.Fprintf(os.Stderr, "Error getting host: %s\n", err)
os.Exit(1)
}
if host.Driver.DriverName() == "none" {
fmt.Println(`'none' driver does not support 'minikube ssh' command`)
os.Exit(0)
}
err = cluster.CreateSSHShell(api, args)
if err != nil {
glog.Errorln(errors.Wrap(err, "Error attempting to ssh/run-ssh-command"))
Expand Down
33 changes: 29 additions & 4 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package cmd
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
Expand All @@ -30,6 +31,8 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

"path"

cmdUtil "k8s.io/minikube/cmd/util"
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/constants"
Expand Down Expand Up @@ -139,7 +142,7 @@ func runStart(cmd *cobra.Command, args []string) {
ExtraOptions: extraOptions,
}

fmt.Println("SSH-ing files into VM...")
fmt.Println("Moving files into cluster...")
if err := cluster.UpdateCluster(host, host.Driver, kubernetesConfig); err != nil {
glog.Errorln("Error updating cluster: ", err)
cmdUtil.MaybeReportErrorAndExit(err)
Expand All @@ -152,9 +155,16 @@ func runStart(cmd *cobra.Command, args []string) {
}

fmt.Println("Starting cluster components...")
if err := cluster.StartCluster(host, kubernetesConfig); err != nil {
glog.Errorln("Error starting cluster: ", err)
cmdUtil.MaybeReportErrorAndExit(err)
if host.DriverName == "none" {
if err := cluster.StartClusterLocal(host, kubernetesConfig); err != nil {
glog.Errorln("Error starting cluster: ", err)
cmdUtil.MaybeReportErrorAndExit(err)
}
} else {
if err := cluster.StartClusterSSH(host, kubernetesConfig); err != nil {
glog.Errorln("Error starting cluster: ", err)
cmdUtil.MaybeReportErrorAndExit(err)
}
}

fmt.Println("Connecting to cluster...")
Expand All @@ -172,6 +182,9 @@ func runStart(cmd *cobra.Command, args []string) {
var kubeConfigFile string
if kubeConfigEnv == "" {
kubeConfigFile = constants.KubeconfigPath
if config.VMDriver == "none" {
kubeConfigFile = path.Join(os.Getenv(constants.MinikubeHome), ".kube", "config")
}
} else {
kubeConfigFile = filepath.SplitList(kubeConfigEnv)[0]
}
Expand All @@ -196,6 +209,18 @@ func runStart(cmd *cobra.Command, args []string) {
} else {
fmt.Println("Kubectl is now configured to use the cluster.")
}

if config.VMDriver == "none" {
username := os.Getenv("SUDO_USER")
fmt.Println("username: ", username)
command := fmt.Sprintf("/bin/chown -R %s %s; /bin/chown -R %s %s", username, constants.GetMinipath(),
username, path.Join(os.Getenv(constants.MinikubeHome), ".kube"))
_, err := exec.Command("bash", "-c", command).Output()
if err != nil {
glog.Errorln("Error modifying priveleges for none driver: ", err)
cmdUtil.MaybeReportErrorAndExit(err)
}
}
}

func calculateDiskSizeInMB(humanReadableDiskSize string) int {
Expand Down
13 changes: 8 additions & 5 deletions cmd/minikube/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,22 @@ var statusCmd = &cobra.Command{
os.Exit(1)
}
defer api.Close()

ms, err := cluster.GetHostStatus(api)
if err != nil {
glog.Errorln("Error getting machine status:", err)
cmdUtil.MaybeReportErrorAndExit(err)
}

ls := "N/A"
if ms == state.Running.String() {
if ms == state.Running.String() || ms == constants.NoneVMStatus {
ls, err = cluster.GetLocalkubeStatus(api)
if err != nil {
glog.Errorln("Error localkube status:", err)
cmdUtil.MaybeReportErrorAndExit(err)
}
}
if err != nil {
glog.Errorln("Error getting machine status:", err)
cmdUtil.MaybeReportErrorAndExit(err)
}

status := Status{ms, ls}

tmpl, err := template.New("status").Parse(statusFormat)
Expand Down
55 changes: 55 additions & 0 deletions pkg/minikube/assets/vm_assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ package assets

import (
"bytes"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"

"github.com/pkg/errors"
)
Expand Down Expand Up @@ -135,3 +140,53 @@ func (m *MemoryAsset) GetLength() int {
func (m *MemoryAsset) Read(p []byte) (int, error) {
return m.reader.Read(p)
}

func CopyFileLocal(f CopyableFile) error {
os.MkdirAll(f.GetTargetDir(), os.ModePerm)
targetPath := filepath.Join(f.GetTargetDir(), f.GetTargetName())
os.Remove(targetPath)
target, err := os.Create(targetPath)
defer target.Close()

perms, err := strconv.Atoi(f.GetPermissions())
if err != nil {
return errors.Wrap(err, "Error converting permissions to integer")
}
target.Chmod(os.FileMode(perms))
if err != nil {
return errors.Wrap(err, "Error changing file permissions")
}

username := os.Getenv("SUDO_USER")
fmt.Println("username: ", username)
command := fmt.Sprintf("/bin/chown %s %s", username, targetPath)
fmt.Println(command)
args := strings.Split(command, " ")
binary := args[0]
args = append(args[:0], args[1:]...)
cmd := exec.Command(binary, args...)
if err := cmd.Start(); err != nil {
return err
}

// command = fmt.Sprintf("getent passwd %s | cut -d: -f6", username)
// out, err := exec.Command("bash", "-c", command).Output()
// if err != nil {
// return err
// }
// fmt.Println(out)
// homeDir := string(out)

// command = fmt.Sprintf("mv %s %s", targetPath, homeDir)
// out, err = exec.Command("bash", "-c", command).Output()
// if err != nil {
// return err
// }
// fmt.Println(string(out))

_, err = io.Copy(target, f)
if err != nil {
return errors.Wrap(err, "Error copying file to target location")
}
return nil
}
Loading

0 comments on commit 9453860

Please sign in to comment.