Commit 744efaa3 authored by Sharif Elgamal's avatar Sharif Elgamal

REFACTOR COMPLETE?

parent b6a429dc
......@@ -775,7 +775,7 @@ Thank you to the contributors whose work made v1.1 into something we could all b
* Add port name to service struct used in minikube service [#4011](https://github.com/kubernetes/minikube/pull/4011)
* Update Hyper-V daemons [#4030](https://github.com/kubernetes/minikube/pull/4030)
* Avoid surfacing "error: no objects passed to apply" non-error from addon-manager [#4076](https://github.com/kubernetes/minikube/pull/4076)
* Don't cache images when --vmdriver=none [#4059](https://github.com/kubernetes/minikube/pull/4059)
* Don't cache images when --Driver=none [#4059](https://github.com/kubernetes/minikube/pull/4059)
* Enable CONFIG_NF_CONNTRACK_ZONES [#3755](https://github.com/kubernetes/minikube/pull/3755)
* Fixed status checking with non-default apiserver-port. [#4058](https://github.com/kubernetes/minikube/pull/4058)
* Escape systemd special chars in docker-env [#3997](https://github.com/kubernetes/minikube/pull/3997)
......
......@@ -41,6 +41,7 @@ import (
"k8s.io/minikube/pkg/minikube/kubeconfig"
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/node"
"k8s.io/minikube/pkg/minikube/out"
)
......@@ -276,7 +277,7 @@ func profileDeletionErr(profileName string, additionalInfo string) error {
func uninstallKubernetes(api libmachine.API, profile string, kc pkg_config.KubernetesConfig, bsName string) error {
out.T(out.Resetting, "Uninstalling Kubernetes {{.kubernetes_version}} using {{.bootstrapper_name}} ...", out.V{"kubernetes_version": kc.KubernetesVersion, "bootstrapper_name": bsName})
clusterBootstrapper, err := getClusterBootstrapper(api, bsName)
clusterBootstrapper, err := node.Bootstrapper(api, bsName)
if err != nil {
return DeletionError{Err: fmt.Errorf("unable to get bootstrapper: %v", err), Errtype: Fatal}
}
......
......@@ -25,6 +25,7 @@ import (
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/logs"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/node"
)
const (
......@@ -66,7 +67,7 @@ var logsCmd = &cobra.Command{
if err != nil {
exit.WithError("command runner", err)
}
bs, err := getClusterBootstrapper(api, viper.GetString(cmdcfg.Bootstrapper))
bs, err := node.Bootstrapper(api, viper.GetString(cmdcfg.Bootstrapper))
if err != nil {
exit.WithError("Error getting cluster bootstrapper", err)
}
......
......@@ -50,7 +50,7 @@ var nodeAddCmd = &cobra.Command{
exit.WithError("Error adding node to cluster", err)
}
_, err = node.Start(mc, n, false)
_, err = node.Start(mc, n, false, nil)
if err != nil {
exit.WithError("Error starting node", err)
}
......
......@@ -61,7 +61,7 @@ var nodeStartCmd = &cobra.Command{
}
// Start it up baby
node.Start(cc, n, false)
node.Start(cc, n, false, nil)
},
}
......
......@@ -23,16 +23,12 @@ import (
"runtime"
"strings"
"github.com/docker/machine/libmachine"
"github.com/golang/glog"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"k8s.io/kubectl/pkg/util/templates"
configCmd "k8s.io/minikube/cmd/minikube/cmd/config"
"k8s.io/minikube/pkg/minikube/bootstrapper"
"k8s.io/minikube/pkg/minikube/bootstrapper/kubeadm"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/exit"
......@@ -267,22 +263,6 @@ func setupViper() {
setFlagsUsingViper()
}
// getClusterBootstrapper returns a new bootstrapper for the cluster
func getClusterBootstrapper(api libmachine.API, bootstrapperName string) (bootstrapper.Bootstrapper, error) {
var b bootstrapper.Bootstrapper
var err error
switch bootstrapperName {
case bootstrapper.Kubeadm:
b, err = kubeadm.NewBootstrapper(api)
if err != nil {
return nil, errors.Wrap(err, "getting a new kubeadm bootstrapper")
}
default:
return nil, fmt.Errorf("unknown bootstrapper: %s", bootstrapperName)
}
return b, nil
}
func addToPath(dir string) {
new := fmt.Sprintf("%s:%s", dir, os.Getenv("PATH"))
glog.Infof("Updating PATH: %s", dir)
......
This diff is collapsed.
......@@ -194,12 +194,12 @@ func (k *Bootstrapper) StartCluster(cfg config.MachineConfig) error {
// Allow older kubeadm versions to function with newer Docker releases.
// For kic on linux example error: "modprobe: FATAL: Module configs not found in directory /lib/modules/5.2.17-1rodete3-amd64"
if version.LT(semver.MustParse("1.13.0")) || driver.IsKIC(cfg.VMDriver) {
if version.LT(semver.MustParse("1.13.0")) || driver.IsKIC(cfg.Driver) {
glog.Infof("Older Kubernetes release detected (%s), disabling SystemVerification check.", version)
ignore = append(ignore, "SystemVerification")
}
if driver.IsKIC(cfg.VMDriver) { // to bypass this error: /proc/sys/net/bridge/bridge-nf-call-iptables does not exist
if driver.IsKIC(cfg.Driver) { // to bypass this error: /proc/sys/net/bridge/bridge-nf-call-iptables does not exist
ignore = append(ignore, "FileContent--proc-sys-net-bridge-bridge-nf-call-iptables")
}
......@@ -210,13 +210,13 @@ func (k *Bootstrapper) StartCluster(cfg config.MachineConfig) error {
return errors.Wrapf(err, "init failed. output: %q", rr.Output())
}
if driver.IsKIC(cfg.VMDriver) {
if driver.IsKIC(cfg.Driver) {
if err := k.applyKicOverlay(cfg); err != nil {
return errors.Wrap(err, "applying kic overlay network")
}
}
if !driver.IsKIC(cfg.VMDriver) { // TODO: skip for both after verifications https://github.com/kubernetes/minikube/issues/6239
if !driver.IsKIC(cfg.Driver) { // TODO: skip for both after verifications https://github.com/kubernetes/minikube/issues/6239
glog.Infof("Configuring cluster permissions ...")
elevate := func() error {
client, err := k.client(cp.IP, cp.Port)
......@@ -275,9 +275,9 @@ func (k *Bootstrapper) WaitForCluster(cfg config.MachineConfig, timeout time.Dur
ip := cp.IP
port := cp.Port
if driver.IsKIC(cfg.VMDriver) {
if driver.IsKIC(cfg.Driver) {
ip = kic.DefaultBindIPV4
port, err = oci.HostPortBinding(cfg.VMDriver, cfg.Name, port)
port, err = oci.HostPortBinding(cfg.Driver, cfg.Name, port)
if err != nil {
return errors.Wrapf(err, "get host-bind port %d for container %s", port, cfg.Name)
}
......@@ -343,9 +343,9 @@ func (k *Bootstrapper) restartCluster(cfg config.MachineConfig) error {
for _, n := range cfg.Nodes {
ip := n.IP
port := n.Port
if driver.IsKIC(cfg.VMDriver) {
if driver.IsKIC(cfg.Driver) {
ip = kic.DefaultBindIPV4
port, err = oci.HostPortBinding(cfg.VMDriver, cfg.Name, port)
port, err = oci.HostPortBinding(cfg.Driver, cfg.Name, port)
if err != nil {
return errors.Wrapf(err, "get host-bind port %d for container %s", port, cfg.Name)
}
......
......@@ -61,7 +61,7 @@ func RegisterMockDriver(t *testing.T) {
}
var defaultMachineConfig = config.MachineConfig{
VMDriver: driver.Mock,
Driver: driver.Mock,
MinikubeISO: constants.DefaultISOURL,
Downloader: MockDownloader{},
DockerEnv: []string{"MOCK_MAKE_IT_PROVISION=true"},
......@@ -262,7 +262,7 @@ func TestStartHostConfig(t *testing.T) {
provision.SetDetector(md)
config := config.MachineConfig{
VMDriver: driver.Mock,
Driver: driver.Mock,
DockerEnv: []string{"FOO=BAR"},
DockerOpt: []string{"param=value"},
Downloader: MockDownloader{},
......
......@@ -101,9 +101,9 @@ func fixHost(api libmachine.API, mc config.MachineConfig) (*host.Host, error) {
}
if s == state.Running {
out.T(out.Running, `Using the running {{.driver_name}} "{{.profile_name}}" VM ...`, out.V{"driver_name": mc.VMDriver, "profile_name": mc.Name})
out.T(out.Running, `Using the running {{.driver_name}} "{{.profile_name}}" VM ...`, out.V{"driver_name": mc.Driver, "profile_name": mc.Name})
} else {
out.T(out.Restarting, `Starting existing {{.driver_name}} VM for "{{.profile_name}}" ...`, out.V{"driver_name": mc.VMDriver, "profile_name": mc.Name})
out.T(out.Restarting, `Starting existing {{.driver_name}} VM for "{{.profile_name}}" ...`, out.V{"driver_name": mc.Driver, "profile_name": mc.Name})
if err := h.Driver.Start(); err != nil {
return h, errors.Wrap(err, "driver start")
}
......@@ -142,7 +142,7 @@ func fixHost(api libmachine.API, mc config.MachineConfig) (*host.Host, error) {
if err := h.ConfigureAuth(); err != nil {
return h, &retry.RetriableError{Err: errors.Wrap(err, "Error configuring auth on host")}
}
return h, ensureSyncedGuestClock(h, mc.VMDriver)
return h, ensureSyncedGuestClock(h, mc.Driver)
}
// ensureGuestClockSync ensures that the guest system clock is relatively in-sync
......@@ -198,8 +198,8 @@ func adjustGuestClock(h hostRunner, t time.Time) error {
// machineExists checks if virtual machine does not exist
// if the virtual machine exists, return true
func machineExists(vmDriver string, s state.State, err error) (bool, error) {
switch vmDriver {
func machineExists(Driver string, s state.State, err error) (bool, error) {
switch Driver {
case driver.HyperKit:
if s == state.Stopped || err.Error() == "connection is shut down" {
return false, ErrorMachineNotExist
......
......@@ -100,19 +100,19 @@ func logRemoteOsRelease(drv drivers.Driver) {
// showHostInfo shows host information
func showHostInfo(cfg config.MachineConfig) {
if driver.BareMetal(cfg.VMDriver) {
if driver.BareMetal(cfg.Driver) {
info, err := getHostInfo()
if err == nil {
out.T(out.StartingNone, "Running on localhost (CPUs={{.number_of_cpus}}, Memory={{.memory_size}}MB, Disk={{.disk_size}}MB) ...", out.V{"number_of_cpus": info.CPUs, "memory_size": info.Memory, "disk_size": info.DiskSize})
}
return
}
if driver.IsKIC(cfg.VMDriver) {
if driver.IsKIC(cfg.Driver) {
info, err := getHostInfo() // TODO medyagh: get docker-machine info for non linux
if err == nil {
out.T(out.StartingVM, "Creating Kubernetes in {{.driver_name}} container with (CPUs={{.number_of_cpus}}), Memory={{.memory_size}}MB ({{.host_memory_size}}MB available) ...", out.V{"driver_name": cfg.VMDriver, "number_of_cpus": cfg.CPUs, "number_of_host_cpus": info.CPUs, "memory_size": cfg.Memory, "host_memory_size": info.Memory})
out.T(out.StartingVM, "Creating Kubernetes in {{.driver_name}} container with (CPUs={{.number_of_cpus}}), Memory={{.memory_size}}MB ({{.host_memory_size}}MB available) ...", out.V{"driver_name": cfg.Driver, "number_of_cpus": cfg.CPUs, "number_of_host_cpus": info.CPUs, "memory_size": cfg.Memory, "host_memory_size": info.Memory})
}
return
}
out.T(out.StartingVM, "Creating {{.driver_name}} VM (CPUs={{.number_of_cpus}}, Memory={{.memory_size}}MB, Disk={{.disk_size}}MB) ...", out.V{"driver_name": cfg.VMDriver, "number_of_cpus": cfg.CPUs, "memory_size": cfg.Memory, "disk_size": cfg.DiskSize})
out.T(out.StartingVM, "Creating {{.driver_name}} VM (CPUs={{.number_of_cpus}}, Memory={{.memory_size}}MB, Disk={{.disk_size}}MB) ...", out.V{"driver_name": cfg.Driver, "number_of_cpus": cfg.CPUs, "memory_size": cfg.Memory, "disk_size": cfg.DiskSize})
}
......@@ -23,7 +23,7 @@ import (
// CacheISO downloads and caches ISO.
func CacheISO(cfg config.MachineConfig) error {
if driver.BareMetal(cfg.VMDriver) {
if driver.BareMetal(cfg.Driver) {
return nil
}
return cfg.Downloader.CacheMinikubeISOFromURL(cfg.MinikubeISO)
......
......@@ -97,22 +97,22 @@ func engineOptions(cfg config.MachineConfig) *engine.Options {
}
func createHost(api libmachine.API, cfg config.MachineConfig) (*host.Host, error) {
glog.Infof("createHost starting for %q (driver=%q)", cfg.Name, cfg.VMDriver)
glog.Infof("createHost starting for %q (driver=%q)", cfg.Name, cfg.Driver)
start := time.Now()
defer func() {
glog.Infof("createHost completed in %s", time.Since(start))
}()
if cfg.VMDriver == driver.VMwareFusion && viper.GetBool(config.ShowDriverDeprecationNotification) {
if cfg.Driver == driver.VMwareFusion && viper.GetBool(config.ShowDriverDeprecationNotification) {
out.WarningT(`The vmwarefusion driver is deprecated and support for it will be removed in a future release.
Please consider switching to the new vmware unified driver, which is intended to replace the vmwarefusion driver.
See https://minikube.sigs.k8s.io/docs/reference/drivers/vmware/ for more information.
To disable this message, run [minikube config set ShowDriverDeprecationNotification false]`)
}
showHostInfo(cfg)
def := registry.Driver(cfg.VMDriver)
def := registry.Driver(cfg.Driver)
if def.Empty() {
return nil, fmt.Errorf("unsupported/missing driver: %s", cfg.VMDriver)
return nil, fmt.Errorf("unsupported/missing driver: %s", cfg.Driver)
}
dd, err := def.Config(cfg)
if err != nil {
......@@ -123,7 +123,7 @@ func createHost(api libmachine.API, cfg config.MachineConfig) (*host.Host, error
return nil, errors.Wrap(err, "marshal")
}
h, err := api.NewHost(cfg.VMDriver, data)
h, err := api.NewHost(cfg.Driver, data)
if err != nil {
return nil, errors.Wrap(err, "new host")
}
......@@ -133,7 +133,7 @@ func createHost(api libmachine.API, cfg config.MachineConfig) (*host.Host, error
h.HostOptions.EngineOptions = engineOptions(cfg)
cstart := time.Now()
glog.Infof("libmachine.API.Create for %q (driver=%q)", cfg.Name, cfg.VMDriver)
glog.Infof("libmachine.API.Create for %q (driver=%q)", cfg.Name, cfg.Driver)
if err := api.Create(h); err != nil {
// Wait for all the logs to reach the client
time.Sleep(2 * time.Second)
......@@ -174,10 +174,10 @@ func postStartSetup(h *host.Host, mc config.MachineConfig) error {
return errors.Wrapf(err, "sudo mkdir (%s)", h.DriverName)
}
if driver.BareMetal(mc.VMDriver) {
if driver.BareMetal(mc.Driver) {
showLocalOsRelease()
}
if driver.IsVM(mc.VMDriver) {
if driver.IsVM(mc.Driver) {
logRemoteOsRelease(h.Driver)
}
return syncLocalAssets(r)
......
......@@ -5,7 +5,7 @@
"Memory": 2000,
"CPUs": 2,
"DiskSize": 20000,
"VMDriver": "hyperkit",
"Driver": "hyperkit",
"ContainerRuntime": "docker",
"HyperkitVpnKitSock": "",
"HyperkitVSockPorts": [],
......
......@@ -5,7 +5,7 @@
"Memory": 2000,
"CPUs": 2,
"DiskSize": 20000,
"VMDriver": "virtualbox",
"Driver": "virtualbox",
"ContainerRuntime": "docker",
"HyperkitVpnKitSock": "",
"HyperkitVSockPorts": [],
......
......@@ -5,7 +5,7 @@
"Memory": 2000,
"CPUs": 2,
"DiskSize": 20000,
"VMDriver": "hyperkit",
"Driver": "hyperkit",
"ContainerRuntime": "docker",
"HyperkitVpnKitSock": "",
"HyperkitVSockPorts": [],
......
......@@ -5,7 +5,7 @@
"Memory": 2000,
"CPUs": 2,
"DiskSize": 20000,
"VMDriver": "hyperkit",
"Driver": "hyperkit",
"ContainerRuntime": "docker",
"HyperkitVpnKitSock": "",
"HyperkitVSockPorts": [],
......
......@@ -5,7 +5,7 @@
"Memory": 2000,
"CPUs": 2,
"DiskSize": 20000,
"VMDriver": "hyperkit",
"Driver": "hyperkit",
"ContainerRuntime": "docker",
"HyperkitVpnKitSock": "",
"HyperkitVSockPorts": [],
......
......@@ -5,7 +5,7 @@
"Memory": 2000,
"CPUs": 2,
"DiskSize": 20000,
"VMDriver": "hyperkit",
"Driver": "hyperkit",
"ContainerRuntime": "docker",
"HyperkitVpnKitSock": "",
"HyperkitVSockPorts": [],
......
......@@ -5,7 +5,7 @@
"Memory": 2000,
"CPUs": 2,
"DiskSize": 20000,
"VMDriver": "hyperkit",
"Driver": "hyperkit",
"ContainerRuntime": "docker",
"HyperkitVpnKitSock": "",
"HyperkitVSockPorts": [],
......
......@@ -5,7 +5,7 @@
"Memory": 2000,
"CPUs": 2,
"DiskSize": 20000,
"VMDriver": "hyperkit",
"Driver": "hyperkit",
"ContainerRuntime": "docker",
"HyperkitVpnKitSock": "",
"HyperkitVSockPorts": [],
......
......@@ -5,7 +5,7 @@
"Memory": 2000,
"CPUs": 2,
"DiskSize": 20000,
"VMDriver": "hyperkit",
"Driver": "hyperkit",
"ContainerRuntime": "docker",
"HyperkitVpnKitSock": "",
"HyperkitVSockPorts": [],
......
......@@ -5,7 +5,7 @@
"Memory": 2000,
"CPUs": 2,
"DiskSize": 20000,
"VMDriver": "hyperkit",
"Driver": "hyperkit",
"ContainerRuntime": "docker",
"HyperkitVpnKitSock": "",
"HyperkitVSockPorts": [],
......
......@@ -5,7 +5,7 @@
"Memory": 2000,
"CPUs": 2,
"DiskSize": 20000,
"VMDriver": "hyperkit",
"Driver": "hyperkit",
"ContainerRuntime": "docker",
"HyperkitVpnKitSock": "",
"HyperkitVSockPorts": [],
......
......@@ -5,7 +5,7 @@
"Memory": 2000,
"CPUs": 2,
"DiskSize": 20000,
"VMDriver": "hyperkit",
"Driver": "hyperkit",
"ContainerRuntime": "docker",
"HyperkitVpnKitSock": "",
"HyperkitVSockPorts": [],
......
......@@ -5,7 +5,7 @@
"Memory": 2000,
"CPUs": 2,
"DiskSize": 20000,
"VMDriver": "hyperkit",
"Driver": "hyperkit",
"ContainerRuntime": "docker",
"HyperkitVpnKitSock": "",
"HyperkitVSockPorts": [],
......
......@@ -5,7 +5,7 @@
"Memory": 2000,
"CPUs": 2,
"DiskSize": 20000,
"VMDriver": "virtualbox",
"Driver": "virtualbox",
"ContainerRuntime": "docker",
"HyperkitVpnKitSock": "",
"HyperkitVSockPorts": [],
......
......@@ -124,17 +124,17 @@ func validateDriver(executable string, v semver.Version) (string, error) {
return path, err
}
ev := extractVMDriverVersion(string(output))
ev := extractDriverVersion(string(output))
if len(ev) == 0 {
return path, fmt.Errorf("%s: unable to extract version from %q", executable, output)
}
vmDriverVersion, err := semver.Make(ev)
DriverVersion, err := semver.Make(ev)
if err != nil {
return path, errors.Wrap(err, "can't parse driver version")
}
if vmDriverVersion.LT(v) {
return path, fmt.Errorf("%s is version %s, want %s", executable, vmDriverVersion, v)
if DriverVersion.LT(v) {
return path, fmt.Errorf("%s is version %s, want %s", executable, DriverVersion, v)
}
return path, nil
}
......@@ -164,12 +164,12 @@ func download(name string, destination string, v semver.Version) error {
return os.Chmod(destination, 0755)
}
// extractVMDriverVersion extracts the driver version.
// extractDriverVersion extracts the driver version.
// KVM and Hyperkit drivers support the 'version' command, that display the information as:
// version: vX.X.X
// commit: XXXX
// This method returns the version 'vX.X.X' or empty if the version isn't found.
func extractVMDriverVersion(s string) string {
func extractDriverVersion(s string) string {
versionRegex := regexp.MustCompile(`version:(.*)`)
matches := versionRegex.FindStringSubmatch(s)
......
......@@ -20,25 +20,25 @@ import (
"testing"
)
func TestExtractVMDriverVersion(t *testing.T) {
v := extractVMDriverVersion("")
func TestExtractDriverVersion(t *testing.T) {
v := extractDriverVersion("")
if len(v) != 0 {
t.Error("Expected empty string")
}
v = extractVMDriverVersion("random text")
v = extractDriverVersion("random text")
if len(v) != 0 {
t.Error("Expected empty string")
}
expectedVersion := "1.2.3"
v = extractVMDriverVersion("version: v1.2.3")
v = extractDriverVersion("version: v1.2.3")
if expectedVersion != v {
t.Errorf("Expected version: %s, got: %s", expectedVersion, v)
}
v = extractVMDriverVersion("version: 1.2.3")
v = extractDriverVersion("version: 1.2.3")
if expectedVersion != v {
t.Errorf("Expected version: %s, got: %s", expectedVersion, v)
}
......
......@@ -17,17 +17,39 @@ limitations under the License.
package node
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
"github.com/docker/machine/libmachine"
"github.com/docker/machine/libmachine/host"
"github.com/golang/glog"
"github.com/pkg/errors"
"github.com/spf13/viper"
cmdcfg "k8s.io/minikube/cmd/minikube/cmd/config"
"k8s.io/minikube/pkg/minikube/bootstrapper"
"k8s.io/minikube/pkg/minikube/bootstrapper/kubeadm"
"k8s.io/minikube/pkg/minikube/command"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/cruntime"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/kubeconfig"
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/logs"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/util/lock"
)
var (
DockerEnv []string
DockerOpt []string
DockerEnv []string
DockerOpt []string
ExtraOptions config.ExtraOptionSlice
AddonList []string
)
// configureRuntimes does what needs to happen to get a runtime going.
......@@ -60,3 +82,102 @@ func showVersionInfo(k8sVersion string, cr cruntime.Manager) {
out.T(out.Option, "env {{.docker_env}}", out.V{"docker_env": v})
}
}
// setupKubeAdm adds any requested files into the VM before Kubernetes is started
func setupKubeAdm(mAPI libmachine.API, cfg config.MachineConfig, node config.Node) bootstrapper.Bootstrapper {
bs, err := Bootstrapper(mAPI, viper.GetString(cmdcfg.Bootstrapper))
if err != nil {
exit.WithError("Failed to get bootstrapper", err)
}
for _, eo := range ExtraOptions {
out.T(out.Option, "{{.extra_option_component_name}}.{{.key}}={{.value}}", out.V{"extra_option_component_name": eo.Component, "key": eo.Key, "value": eo.Value})
}
// Loads cached images, generates config files, download binaries
if err := bs.UpdateCluster(cfg); err != nil {
exit.WithError("Failed to update cluster", err)
}
if err := bs.SetupCerts(cfg.KubernetesConfig, node); err != nil {
exit.WithError("Failed to setup certs", err)
}
return bs
}
func setupKubeconfig(h *host.Host, c *config.MachineConfig, n *config.Node, clusterName string) (*kubeconfig.Settings, error) {
addr, err := h.Driver.GetURL()
if err != nil {
exit.WithError("Failed to get driver URL", err)
}
if !driver.IsKIC(h.DriverName) {
addr = strings.Replace(addr, "tcp://", "https://", -1)
addr = strings.Replace(addr, ":2376", ":"+strconv.Itoa(n.Port), -1)
}
if c.KubernetesConfig.APIServerName != constants.APIServerName {
addr = strings.Replace(addr, n.IP, c.KubernetesConfig.APIServerName, -1)
}
kcs := &kubeconfig.Settings{
ClusterName: clusterName,
ClusterServerAddress: addr,
ClientCertificate: localpath.MakeMiniPath("client.crt"),
ClientKey: localpath.MakeMiniPath("client.key"),
CertificateAuthority: localpath.MakeMiniPath("ca.crt"),
KeepContext: viper.GetBool(keepContext),
EmbedCerts: viper.GetBool(embedCerts),
}
kcs.SetPath(kubeconfig.PathFromEnv())
if err := kubeconfig.Update(kcs); err != nil {
return kcs, err
}
return kcs, nil
}
// Bootstrapper returns a new bootstrapper for the node
func Bootstrapper(api libmachine.API, bootstrapperName string) (bootstrapper.Bootstrapper, error) {
var b bootstrapper.Bootstrapper
var err error
switch bootstrapperName {
case bootstrapper.Kubeadm:
b, err = kubeadm.NewBootstrapper(api)
if err != nil {
return nil, errors.Wrap(err, "getting a new kubeadm bootstrapper")
}
default:
return nil, fmt.Errorf("unknown bootstrapper: %s", bootstrapperName)
}
return b, nil
}
// bootstrapCluster starts Kubernetes using the chosen bootstrapper
func bootstrapCluster(bs bootstrapper.Bootstrapper, r cruntime.Manager, runner command.Runner, mc config.MachineConfig) {
out.T(out.Launch, "Launching Kubernetes ... ")
if err := bs.StartCluster(mc); err != nil {
exit.WithLogEntries("Error starting cluster", err, logs.FindProblems(r, bs, runner))
}
}
// configureMounts configures any requested filesystem mounts
func configureMounts() {
if !viper.GetBool(createMount) {
return
}
out.T(out.Mounting, "Creating mount {{.name}} ...", out.V{"name": viper.GetString(mountString)})
path := os.Args[0]
mountDebugVal := 0
if glog.V(8) {
mountDebugVal = 1
}
mountCmd := exec.Command(path, "mount", fmt.Sprintf("--v=%d", mountDebugVal), viper.GetString(mountString))
mountCmd.Env = append(os.Environ(), constants.IsMinikubeChildProcess+"=true")
if glog.V(8) {
mountCmd.Stdout = os.Stdout
mountCmd.Stderr = os.Stderr
}
if err := mountCmd.Start(); err != nil {
exit.WithError("Error starting mount", err)
}
if err := lock.WriteFile(filepath.Join(localpath.MiniPath(), constants.MountProcessFileName), []byte(strconv.Itoa(mountCmd.Process.Pid)), 0644); err != nil {
exit.WithError("Error writing mount pid", err)
}
}
......@@ -31,6 +31,11 @@ const (
waitUntilHealthy = "wait"
cacheImageConfigKey = "cache"
containerRuntime = "container-runtime"
embedCerts = "embed-certs"
keepContext = "keep-context"
mountString = "mount-string"
createMount = "mount"
waitTimeout = "wait-timeout"
)
// Add adds a new node config to an existing cluster.
......@@ -60,7 +65,7 @@ func Add(cc *config.MachineConfig, name string, controlPlane bool, worker bool,
return nil, err
}
_, err = Start(cc, &n, false)
_, err = Start(cc, &n, false, nil)
return &n, err
}
......
......@@ -17,6 +17,8 @@ limitations under the License.
package node
import (
"os"
"github.com/spf13/viper"
"golang.org/x/sync/errgroup"
"k8s.io/minikube/pkg/addons"
......@@ -24,11 +26,13 @@ import (
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/exit"