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

[WIP] Kubeadm bootstrapper #1825

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions cmd/minikube/cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"k8s.io/minikube/pkg/minikube/constants"
)

const Bootstrapper = "bootstrapper"

type setFn func(string, string) error

type Setting struct {
Expand Down Expand Up @@ -113,6 +115,10 @@ var settings = []Setting{
name: config.MachineProfile,
set: SetString,
},
{
name: Bootstrapper,
set: SetString, //TODO(r2d4): more validation here?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps validation function here that checks against a list of available bootstrappers

},
{
name: "dashboard",
set: SetBool,
Expand Down
66 changes: 1 addition & 65 deletions cmd/minikube/cmd/config/disable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,74 +16,10 @@ limitations under the License.

package config

import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"

"github.com/docker/machine/libmachine/drivers"

"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/sshutil"
"k8s.io/minikube/pkg/minikube/tests"
)
import "testing"

func TestDisableUnknownAddon(t *testing.T) {
if err := Set("InvalidAddon", "false"); err == nil {
t.Fatalf("Disable did not return error for unknown addon")
}
}

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

addonName := "dashboard"
expected := "false"
if err := Set(addonName, expected); err != nil {
//check that setting was changed in temp dir
conf, _ := ioutil.ReadFile(filepath.Join(tempDir, "config", "config.json"))
strConf := string(conf)
if !strings.Contains(strConf, addonName) {
t.Fatalf("Expected %s, in %s after running disable", addonName, strConf)
}
if !strings.Contains(strConf, expected) {
t.Fatalf("Expected %s, in %s after running disable", expected, strConf)
}
//check that nothing was transferred?
} else {
if err != nil {
t.Fatalf("Disable returned error for known addon")
}
}
}

func TestDeleteAddonSSH(t *testing.T) {
s, _ := tests.NewSSHServer()
port, err := s.Start()
if err != nil {
t.Fatalf("Error starting ssh server: %s", err)
}

d := &tests.MockDriver{
Port: port,
BaseDriver: drivers.BaseDriver{
IPAddress: "127.0.0.1",
SSHKeyPath: "",
},
}

dashboard := assets.Addons["dashboard"]
if err := deleteAddonSSH(dashboard, d); err != nil {
t.Fatalf("Unexpected error %s deleting addon", err)
}
// check command(s) were run
for _, addon := range dashboard.Assets {
expected, _ := ioutil.ReadFile(addon.GetAssetName())
if _, ok := s.Commands[sshutil.GetDeleteFileCommand(addon)]; !ok {
t.Fatalf("Error: Expected delete addon ssh command to be run: %s.", expected)
}
}
}
67 changes: 1 addition & 66 deletions cmd/minikube/cmd/config/enable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,75 +16,10 @@ limitations under the License.

package config

import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"

"github.com/docker/machine/libmachine/drivers"

"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/tests"
)
import "testing"

func TestEnableUnknownAddon(t *testing.T) {
if err := Set("InvalidAddon", "false"); err == nil {
t.Fatalf("Enable did not return error for unknown addon")
}
}

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

addonName := "dashboard"
expected := "true"
if err := Set(addonName, expected); err != nil {
//check that setting was changed in temp dir
conf, _ := ioutil.ReadFile(filepath.Join(tempDir, "config", "config.json"))
strConf := string(conf)
if !strings.Contains(strConf, addonName) {
t.Fatalf("Expected %s, in %s after running enable", addonName, strConf)
}
if !strings.Contains(strConf, expected) {
t.Fatalf("Expected %s, in %s after running enable", expected, strConf)
}
} else {
if err != nil {
t.Fatalf("Enable returned error for known addon")
}
}
}

func TestTransferAddonSSH(t *testing.T) {
s, _ := tests.NewSSHServer()
port, err := s.Start()
if err != nil {
t.Fatalf("Error starting ssh server: %s", err)
}

d := &tests.MockDriver{
Port: port,
BaseDriver: drivers.BaseDriver{
IPAddress: "127.0.0.1",
SSHKeyPath: "",
},
}

dashboard := assets.Addons["dashboard"]
if err := transferAddonSSH(dashboard, d); err != nil {
t.Fatalf("Unexpected error %s transferring addon", err)
}
// check contents
for _, addon := range dashboard.Assets {
expected, _ := ioutil.ReadFile(addon.GetAssetName())
transferred := s.Transfers.Bytes()
//test that custom addons are transferred properly
if !bytes.Contains(transferred, expected) {
t.Fatalf("Expected transfers to contain addon with content: %s. It was: %s", expected, transferred)
}
}
}
97 changes: 23 additions & 74 deletions cmd/minikube/cmd/config/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@ package config
import (
"fmt"
"os"
"path/filepath"
"strconv"

"github.com/docker/machine/libmachine/drivers"
"github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/bootstrapper"
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/sshutil"
"k8s.io/minikube/pkg/minikube/storageclass"
"k8s.io/minikube/pkg/util"
)

// Runs all the validation or callback functions and collects errors
Expand Down Expand Up @@ -82,7 +83,6 @@ func SetBool(m config.MinikubeConfig, name string, val string) error {
}

func EnableOrDisableAddon(name string, val string) error {

enable, err := strconv.ParseBool(val)
if err != nil {
errors.Wrapf(err, "error attempted to parse enabled/disable value addon %s", name)
Expand All @@ -102,61 +102,33 @@ func EnableOrDisableAddon(name string, val string) error {
return err
}
host, err := cluster.CheckIfApiExistsAndLoad(api)
if enable {
if err = transferAddon(addon, host.Driver); err != nil {
return errors.Wrapf(err, "Error transferring addon %s to VM", name)
}

// TODO(r2d4): This is probably not the best way to do this.
// Ideally, the addon information should be passed through
// bootstrapper.KubernetesConfig
// There shouldn't be any instances of getting a CommandRunner outside
// the bootstrapper
var b bootstrapper.CommandRunner
if host.DriverName == constants.DriverNone {
b = &bootstrapper.ExecRunner{}
} else {
if err = deleteAddon(addon, host.Driver); err != nil {
return errors.Wrapf(err, "Error deleting addon %s from VM", name)
client, err := sshutil.NewSSHClient(host.Driver)
if err != nil {
return errors.Wrap(err, "getting ssh client")
}
b = bootstrapper.NewSSHRunner(client)
}
return nil
}

func deleteAddonSSH(addon *assets.Addon, d drivers.Driver) error {
client, err := sshutil.NewSSHClient(d)
if err != nil {
return err
}
if err := sshutil.DeleteAddon(addon, client); err != nil {
return err
}
return nil
}

func deleteAddon(addon *assets.Addon, d drivers.Driver) error {
if d.DriverName() == "none" {
if err := deleteAddonLocal(addon, d); err != nil {
return err
m := util.MultiError{}
if enable {
for _, a := range addon.Assets {
m.Collect(b.TransferFile(a))
}
} else {
if err := deleteAddonSSH(addon, d); err != nil {
return err
for _, a := range addon.Assets {
m.Collect(b.DeleteFile(a))
}
}
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
}
if err := sshutil.TransferAddon(addon, client); err != nil {
return err
}
return nil
return m.ToError()
}

func EnableOrDisableDefaultStorageClass(name, val string) error {
Expand All @@ -174,26 +146,3 @@ 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
}
12 changes: 10 additions & 2 deletions cmd/minikube/cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import (
"log"
"os"

"github.com/golang/glog"
"github.com/spf13/cobra"
"github.com/spf13/viper"
cmdcfg "k8s.io/minikube/cmd/minikube/cmd/config"
cmdUtil "k8s.io/minikube/cmd/util"
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/machine"
)

Expand All @@ -43,7 +45,13 @@ var logsCmd = &cobra.Command{
os.Exit(1)
}
defer api.Close()
s, err := cluster.GetHostLogs(api, follow)

clusterBootstrapper, err := GetClusterBootstrapper(api, viper.GetString(cmdcfg.Bootstrapper))
if err != nil {
glog.Exitf("Error getting cluster bootstrapper: %s", err)
}

s, err := clusterBootstrapper.GetClusterLogs(follow)
if err != nil {
log.Println("Error getting machine logs:", err)
cmdUtil.MaybeReportErrorAndExit(err)
Expand Down
Loading