Reorganize the minikube drivers
- Add registry to register all supported drivers in different platforms. - Add DriverDef to define driver's metadata. - All driver support logic moved to pkg/minikube/drivers, removed all driver name switches scattered in different packages.pull/2600/head
parent
ab9f3b234d
commit
0fa64b3bd8
|
|
@ -129,7 +129,7 @@ func runStart(cmd *cobra.Command, args []string) {
|
|||
validateK8sVersion(k8sVersion)
|
||||
}
|
||||
|
||||
config := cluster.MachineConfig{
|
||||
config := cfg.MachineConfig{
|
||||
MinikubeISO: viper.GetString(isoURL),
|
||||
Memory: viper.GetInt(memory),
|
||||
CPUs: viper.GetInt(cpus),
|
||||
|
|
@ -198,7 +198,7 @@ func runStart(cmd *cobra.Command, args []string) {
|
|||
}
|
||||
}
|
||||
|
||||
kubernetesConfig := bootstrapper.KubernetesConfig{
|
||||
kubernetesConfig := cfg.KubernetesConfig{
|
||||
KubernetesVersion: selectedKubernetesVersion,
|
||||
NodeIP: ip,
|
||||
NodeName: cfg.GetMachineName(),
|
||||
|
|
@ -220,7 +220,7 @@ func runStart(cmd *cobra.Command, args []string) {
|
|||
}
|
||||
|
||||
// Write profile cluster configuration to file
|
||||
clusterConfig := cluster.Config{
|
||||
clusterConfig := cfg.Config{
|
||||
MachineConfig: config,
|
||||
KubernetesConfig: kubernetesConfig,
|
||||
}
|
||||
|
|
@ -405,7 +405,7 @@ func init() {
|
|||
|
||||
// saveConfig saves profile cluster configuration in
|
||||
// $MINIKUBE_HOME/profiles/<profilename>/config.json
|
||||
func saveConfig(clusterConfig cluster.Config) error {
|
||||
func saveConfig(clusterConfig cfg.Config) error {
|
||||
data, err := json.MarshalIndent(clusterConfig, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -453,8 +453,8 @@ func saveConfigToFile(data []byte, file string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func loadConfigFromFile(profile string) (cluster.Config, error) {
|
||||
var cc cluster.Config
|
||||
func loadConfigFromFile(profile string) (cfg.Config, error) {
|
||||
var cc cfg.Config
|
||||
|
||||
profileConfigFile := constants.GetProfileFile(profile)
|
||||
|
||||
|
|
|
|||
|
|
@ -18,40 +18,21 @@ package bootstrapper
|
|||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
|
||||
"k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
"k8s.io/minikube/pkg/util"
|
||||
)
|
||||
|
||||
// Bootstrapper contains all the methods needed to bootstrap a kubernetes cluster
|
||||
type Bootstrapper interface {
|
||||
StartCluster(KubernetesConfig) error
|
||||
UpdateCluster(KubernetesConfig) error
|
||||
RestartCluster(KubernetesConfig) error
|
||||
StartCluster(config.KubernetesConfig) error
|
||||
UpdateCluster(config.KubernetesConfig) error
|
||||
RestartCluster(config.KubernetesConfig) error
|
||||
GetClusterLogsTo(follow bool, out io.Writer) error
|
||||
SetupCerts(cfg KubernetesConfig) error
|
||||
SetupCerts(cfg config.KubernetesConfig) error
|
||||
GetClusterStatus() (string, error)
|
||||
}
|
||||
|
||||
// KubernetesConfig contains the parameters used to configure the VM Kubernetes.
|
||||
type KubernetesConfig struct {
|
||||
KubernetesVersion string
|
||||
NodeIP string
|
||||
NodeName string
|
||||
APIServerName string
|
||||
APIServerNames []string
|
||||
APIServerIPs []net.IP
|
||||
DNSDomain string
|
||||
ContainerRuntime string
|
||||
NetworkPlugin string
|
||||
FeatureGates string
|
||||
ServiceCIDR string
|
||||
ExtraOptions util.ExtraOptionSlice
|
||||
|
||||
ShouldLoadCachedImages bool
|
||||
}
|
||||
|
||||
const (
|
||||
BootstrapperTypeLocalkube = "localkube"
|
||||
BootstrapperTypeKubeadm = "kubeadm"
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import (
|
|||
"k8s.io/client-go/tools/clientcmd/api"
|
||||
"k8s.io/client-go/tools/clientcmd/api/latest"
|
||||
"k8s.io/minikube/pkg/minikube/assets"
|
||||
"k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
"k8s.io/minikube/pkg/util"
|
||||
"k8s.io/minikube/pkg/util/kubeconfig"
|
||||
|
|
@ -41,7 +42,7 @@ var (
|
|||
)
|
||||
|
||||
// SetupCerts gets the generated credentials required to talk to the APIServer.
|
||||
func SetupCerts(cmd CommandRunner, k8s KubernetesConfig) error {
|
||||
func SetupCerts(cmd CommandRunner, k8s config.KubernetesConfig) error {
|
||||
localPath := constants.GetMinipath()
|
||||
glog.Infof("Setting up certificates for IP: %s\n", k8s.NodeIP)
|
||||
|
||||
|
|
@ -92,7 +93,7 @@ func SetupCerts(cmd CommandRunner, k8s KubernetesConfig) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func generateCerts(k8s KubernetesConfig) error {
|
||||
func generateCerts(k8s config.KubernetesConfig) error {
|
||||
serviceIP, err := util.GetServiceClusterIP(k8s.ServiceCIDR)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "getting service cluster ip")
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import (
|
|||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
"k8s.io/minikube/pkg/minikube/tests"
|
||||
"k8s.io/minikube/pkg/util"
|
||||
|
|
@ -31,7 +32,7 @@ func TestSetupCerts(t *testing.T) {
|
|||
defer os.RemoveAll(tempDir)
|
||||
|
||||
f := NewFakeCommandRunner()
|
||||
k8s := KubernetesConfig{
|
||||
k8s := config.KubernetesConfig{
|
||||
APIServerName: constants.APIServerName,
|
||||
DNSDomain: constants.ClusterDNSDomain,
|
||||
ServiceCIDR: util.DefaultServiceCIDR,
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ func (k *KubeadmBootstrapper) GetClusterLogsTo(follow bool, out io.Writer) error
|
|||
return nil
|
||||
}
|
||||
|
||||
func (k *KubeadmBootstrapper) StartCluster(k8s bootstrapper.KubernetesConfig) error {
|
||||
func (k *KubeadmBootstrapper) StartCluster(k8s config.KubernetesConfig) error {
|
||||
// We use --ignore-preflight-errors=DirAvailable since we have our own custom addons
|
||||
// that we also stick in /etc/kubernetes/manifests
|
||||
// We use --ignore-preflight-errors=Swap since minikube.iso allocates a swap partition.
|
||||
|
|
@ -158,7 +158,7 @@ func addAddons(files *[]assets.CopyableFile) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (k *KubeadmBootstrapper) RestartCluster(k8s bootstrapper.KubernetesConfig) error {
|
||||
func (k *KubeadmBootstrapper) RestartCluster(k8s config.KubernetesConfig) error {
|
||||
opts := struct {
|
||||
KubeadmConfigFile string
|
||||
}{
|
||||
|
|
@ -181,7 +181,7 @@ func (k *KubeadmBootstrapper) RestartCluster(k8s bootstrapper.KubernetesConfig)
|
|||
return nil
|
||||
}
|
||||
|
||||
func (k *KubeadmBootstrapper) SetupCerts(k8s bootstrapper.KubernetesConfig) error {
|
||||
func (k *KubeadmBootstrapper) SetupCerts(k8s config.KubernetesConfig) error {
|
||||
return bootstrapper.SetupCerts(k.c, k8s)
|
||||
}
|
||||
|
||||
|
|
@ -214,7 +214,7 @@ func SetContainerRuntime(cfg map[string]string, runtime string) map[string]strin
|
|||
|
||||
// NewKubeletConfig generates a new systemd unit containing a configured kubelet
|
||||
// based on the options present in the KubernetesConfig.
|
||||
func NewKubeletConfig(k8s bootstrapper.KubernetesConfig) (string, error) {
|
||||
func NewKubeletConfig(k8s config.KubernetesConfig) (string, error) {
|
||||
version, err := ParseKubernetesVersion(k8s.KubernetesVersion)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "parsing kubernetes version")
|
||||
|
|
@ -244,7 +244,7 @@ func NewKubeletConfig(k8s bootstrapper.KubernetesConfig) (string, error) {
|
|||
return b.String(), nil
|
||||
}
|
||||
|
||||
func (k *KubeadmBootstrapper) UpdateCluster(cfg bootstrapper.KubernetesConfig) error {
|
||||
func (k *KubeadmBootstrapper) UpdateCluster(cfg config.KubernetesConfig) error {
|
||||
if cfg.ShouldLoadCachedImages {
|
||||
// Make best effort to load any cached images
|
||||
go machine.LoadImages(k.c, constants.GetKubeadmCachedImages(cfg.KubernetesVersion), constants.ImageCacheDir)
|
||||
|
|
@ -309,7 +309,7 @@ sudo systemctl start kubelet
|
|||
return nil
|
||||
}
|
||||
|
||||
func generateConfig(k8s bootstrapper.KubernetesConfig) (string, error) {
|
||||
func generateConfig(k8s config.KubernetesConfig) (string, error) {
|
||||
version, err := ParseKubernetesVersion(k8s.KubernetesVersion)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "parsing kubernetes version")
|
||||
|
|
|
|||
|
|
@ -19,20 +19,20 @@ package kubeadm
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/minikube/pkg/minikube/bootstrapper"
|
||||
"k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/util"
|
||||
)
|
||||
|
||||
func TestGenerateConfig(t *testing.T) {
|
||||
tests := []struct {
|
||||
description string
|
||||
cfg bootstrapper.KubernetesConfig
|
||||
cfg config.KubernetesConfig
|
||||
expectedCfg string
|
||||
shouldErr bool
|
||||
}{
|
||||
{
|
||||
description: "no extra args",
|
||||
cfg: bootstrapper.KubernetesConfig{
|
||||
cfg: config.KubernetesConfig{
|
||||
NodeIP: "192.168.1.100",
|
||||
KubernetesVersion: "v1.8.0",
|
||||
NodeName: "minikube",
|
||||
|
|
@ -53,7 +53,7 @@ nodeName: minikube
|
|||
},
|
||||
{
|
||||
description: "extra args all components",
|
||||
cfg: bootstrapper.KubernetesConfig{
|
||||
cfg: config.KubernetesConfig{
|
||||
NodeIP: "192.168.1.101",
|
||||
KubernetesVersion: "v1.8.0-alpha.0",
|
||||
NodeName: "extra-args-minikube",
|
||||
|
|
@ -97,7 +97,7 @@ schedulerExtraArgs:
|
|||
},
|
||||
{
|
||||
description: "two extra args for one component",
|
||||
cfg: bootstrapper.KubernetesConfig{
|
||||
cfg: config.KubernetesConfig{
|
||||
NodeIP: "192.168.1.101",
|
||||
KubernetesVersion: "v1.8.0-alpha.0",
|
||||
NodeName: "extra-args-minikube",
|
||||
|
|
@ -133,7 +133,7 @@ apiServerExtraArgs:
|
|||
},
|
||||
{
|
||||
description: "enable feature gates",
|
||||
cfg: bootstrapper.KubernetesConfig{
|
||||
cfg: config.KubernetesConfig{
|
||||
NodeIP: "192.168.1.101",
|
||||
KubernetesVersion: "v1.8.0-alpha.0",
|
||||
NodeName: "extra-args-minikube",
|
||||
|
|
@ -161,7 +161,7 @@ schedulerExtraArgs:
|
|||
},
|
||||
{
|
||||
description: "enable feature gates and extra config",
|
||||
cfg: bootstrapper.KubernetesConfig{
|
||||
cfg: config.KubernetesConfig{
|
||||
NodeIP: "192.168.1.101",
|
||||
KubernetesVersion: "v1.8.0-alpha.0",
|
||||
NodeName: "extra-args-minikube",
|
||||
|
|
@ -198,7 +198,7 @@ schedulerExtraArgs:
|
|||
{
|
||||
// Unknown components should fail silently
|
||||
description: "unknown component",
|
||||
cfg: bootstrapper.KubernetesConfig{
|
||||
cfg: config.KubernetesConfig{
|
||||
NodeIP: "192.168.1.101",
|
||||
KubernetesVersion: "v1.8.0-alpha.0",
|
||||
NodeName: "extra-args-minikube",
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import (
|
|||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/strategicpatch"
|
||||
"k8s.io/minikube/pkg/minikube/bootstrapper"
|
||||
"k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/service"
|
||||
"k8s.io/minikube/pkg/util"
|
||||
)
|
||||
|
|
@ -146,7 +146,7 @@ users:
|
|||
`
|
||||
)
|
||||
|
||||
func restartKubeProxy(k8s bootstrapper.KubernetesConfig) error {
|
||||
func restartKubeProxy(k8s config.KubernetesConfig) error {
|
||||
client, err := util.GetClient()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "getting k8s client")
|
||||
|
|
|
|||
|
|
@ -21,10 +21,9 @@ import (
|
|||
gflag "flag"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"text/template"
|
||||
|
||||
"k8s.io/minikube/pkg/minikube/bootstrapper"
|
||||
"k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
)
|
||||
|
||||
|
|
@ -67,7 +66,7 @@ else
|
|||
fi
|
||||
`
|
||||
|
||||
func GetStartCommand(kubernetesConfig bootstrapper.KubernetesConfig) (string, error) {
|
||||
func GetStartCommand(kubernetesConfig config.KubernetesConfig) (string, error) {
|
||||
localkubeStartCommand, err := GenLocalkubeStartCmd(kubernetesConfig)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
@ -95,7 +94,7 @@ func GetStartCommand(kubernetesConfig bootstrapper.KubernetesConfig) (string, er
|
|||
return buf.String(), nil
|
||||
}
|
||||
|
||||
func GetStartCommandNoSystemd(kubernetesConfig bootstrapper.KubernetesConfig, localkubeStartCmd string) (string, error) {
|
||||
func GetStartCommandNoSystemd(kubernetesConfig config.KubernetesConfig, localkubeStartCmd string) (string, error) {
|
||||
t := template.Must(template.New("startCommand").Parse(startCommandNoSystemdTemplate))
|
||||
buf := bytes.Buffer{}
|
||||
data := struct {
|
||||
|
|
@ -115,7 +114,7 @@ func GetStartCommandNoSystemd(kubernetesConfig bootstrapper.KubernetesConfig, lo
|
|||
return buf.String(), nil
|
||||
}
|
||||
|
||||
func GetStartCommandSystemd(kubernetesConfig bootstrapper.KubernetesConfig, localkubeStartCmd string) (string, error) {
|
||||
func GetStartCommandSystemd(kubernetesConfig config.KubernetesConfig, localkubeStartCmd string) (string, error) {
|
||||
t, err := template.New("localkubeConfig").Parse(localkubeSystemdTmpl)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
@ -133,7 +132,7 @@ func GetStartCommandSystemd(kubernetesConfig bootstrapper.KubernetesConfig, loca
|
|||
constants.LocalkubeServicePath), nil
|
||||
}
|
||||
|
||||
func GenLocalkubeStartCmd(kubernetesConfig bootstrapper.KubernetesConfig) (string, error) {
|
||||
func GenLocalkubeStartCmd(kubernetesConfig config.KubernetesConfig) (string, error) {
|
||||
flagVals := make([]string, len(constants.LogFlags))
|
||||
for _, logFlag := range constants.LogFlags {
|
||||
if logVal := gflag.Lookup(logFlag); logVal != nil && logVal.Value.String() != logVal.DefValue {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"k8s.io/minikube/pkg/minikube/bootstrapper"
|
||||
"k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/util"
|
||||
)
|
||||
|
||||
|
|
@ -32,7 +32,7 @@ func TestGetStartCommandCustomValues(t *testing.T) {
|
|||
"vmodule": "cluster*=5",
|
||||
}
|
||||
flagMapToSetFlags(flagMap)
|
||||
startCommand, err := GetStartCommand(bootstrapper.KubernetesConfig{})
|
||||
startCommand, err := GetStartCommand(config.KubernetesConfig{})
|
||||
if err != nil {
|
||||
t.Fatalf("Error generating start command: %s", err)
|
||||
}
|
||||
|
|
@ -47,7 +47,7 @@ func TestGetStartCommandCustomValues(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetStartCommandExtraOptions(t *testing.T) {
|
||||
k := bootstrapper.KubernetesConfig{
|
||||
k := config.KubernetesConfig{
|
||||
ExtraOptions: util.ExtraOptionSlice{
|
||||
util.ExtraOption{Component: "a", Key: "b", Value: "c"},
|
||||
util.ExtraOption{Component: "d", Key: "e.f", Value: "g"},
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ func (lk *LocalkubeBootstrapper) GetClusterStatus() (string, error) {
|
|||
}
|
||||
|
||||
// StartCluster starts a k8s cluster on the specified Host.
|
||||
func (lk *LocalkubeBootstrapper) StartCluster(kubernetesConfig bootstrapper.KubernetesConfig) error {
|
||||
func (lk *LocalkubeBootstrapper) StartCluster(kubernetesConfig config.KubernetesConfig) error {
|
||||
startCommand, err := GetStartCommand(kubernetesConfig)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Error generating start command: %s", err)
|
||||
|
|
@ -110,11 +110,11 @@ func (lk *LocalkubeBootstrapper) StartCluster(kubernetesConfig bootstrapper.Kube
|
|||
return nil
|
||||
}
|
||||
|
||||
func (lk *LocalkubeBootstrapper) RestartCluster(kubernetesConfig bootstrapper.KubernetesConfig) error {
|
||||
func (lk *LocalkubeBootstrapper) RestartCluster(kubernetesConfig config.KubernetesConfig) error {
|
||||
return lk.StartCluster(kubernetesConfig)
|
||||
}
|
||||
|
||||
func (lk *LocalkubeBootstrapper) UpdateCluster(config bootstrapper.KubernetesConfig) error {
|
||||
func (lk *LocalkubeBootstrapper) UpdateCluster(config config.KubernetesConfig) error {
|
||||
if config.ShouldLoadCachedImages {
|
||||
// Make best effort to load any cached images
|
||||
go machine.LoadImages(lk.cmd, constants.LocalkubeCachedImages, constants.ImageCacheDir)
|
||||
|
|
@ -155,6 +155,6 @@ func (lk *LocalkubeBootstrapper) UpdateCluster(config bootstrapper.KubernetesCon
|
|||
return nil
|
||||
}
|
||||
|
||||
func (lk *LocalkubeBootstrapper) SetupCerts(k8s bootstrapper.KubernetesConfig) error {
|
||||
func (lk *LocalkubeBootstrapper) SetupCerts(k8s config.KubernetesConfig) error {
|
||||
return bootstrapper.SetupCerts(lk.cmd, k8s)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,14 +32,14 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
|
||||
"k8s.io/minikube/pkg/minikube/assets"
|
||||
"k8s.io/minikube/pkg/minikube/bootstrapper"
|
||||
"k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
"k8s.io/minikube/pkg/util"
|
||||
)
|
||||
|
||||
// localkubeCacher is a struct with methods designed for caching localkube
|
||||
type localkubeCacher struct {
|
||||
k8sConf bootstrapper.KubernetesConfig
|
||||
k8sConf config.KubernetesConfig
|
||||
}
|
||||
|
||||
func (l *localkubeCacher) getLocalkubeCacheFilepath() string {
|
||||
|
|
@ -51,7 +51,7 @@ func (l *localkubeCacher) getLocalkubeSha256CacheFilepath() string {
|
|||
return l.getLocalkubeCacheFilepath() + ".sha256"
|
||||
}
|
||||
|
||||
func localkubeURIWasSpecified(config bootstrapper.KubernetesConfig) bool {
|
||||
func localkubeURIWasSpecified(config config.KubernetesConfig) bool {
|
||||
// see if flag is different than default -> it was passed by user
|
||||
return config.KubernetesVersion != constants.DefaultKubernetesVersion
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,11 +21,12 @@ import (
|
|||
"testing"
|
||||
|
||||
"k8s.io/minikube/pkg/minikube/bootstrapper"
|
||||
"k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
)
|
||||
|
||||
func TestStartCluster(t *testing.T) {
|
||||
expectedStartCmd, err := GetStartCommand(bootstrapper.KubernetesConfig{})
|
||||
expectedStartCmd, err := GetStartCommand(config.KubernetesConfig{})
|
||||
if err != nil {
|
||||
t.Fatalf("generating start command: %s", err)
|
||||
}
|
||||
|
|
@ -50,7 +51,7 @@ func TestStartCluster(t *testing.T) {
|
|||
f := bootstrapper.NewFakeCommandRunner()
|
||||
f.SetCommandToOutput(map[string]string{test.startCmd: "ok"})
|
||||
l := LocalkubeBootstrapper{f}
|
||||
err := l.StartCluster(bootstrapper.KubernetesConfig{})
|
||||
err := l.StartCluster(config.KubernetesConfig{})
|
||||
if err != nil && test.startCmd == expectedStartCmd {
|
||||
t.Errorf("Error starting cluster: %s", err)
|
||||
}
|
||||
|
|
@ -59,7 +60,7 @@ func TestStartCluster(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUpdateCluster(t *testing.T) {
|
||||
defaultCfg := bootstrapper.KubernetesConfig{
|
||||
defaultCfg := config.KubernetesConfig{
|
||||
KubernetesVersion: constants.DefaultKubernetesVersion,
|
||||
}
|
||||
defaultAddons := []string{
|
||||
|
|
@ -73,7 +74,7 @@ func TestUpdateCluster(t *testing.T) {
|
|||
}
|
||||
cases := []struct {
|
||||
description string
|
||||
k8s bootstrapper.KubernetesConfig
|
||||
k8s config.KubernetesConfig
|
||||
expectedFiles []string
|
||||
shouldErr bool
|
||||
}{
|
||||
|
|
@ -89,7 +90,7 @@ func TestUpdateCluster(t *testing.T) {
|
|||
},
|
||||
{
|
||||
description: "no localkube version",
|
||||
k8s: bootstrapper.KubernetesConfig{},
|
||||
k8s: config.KubernetesConfig{},
|
||||
shouldErr: true,
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import (
|
|||
"regexp"
|
||||
"time"
|
||||
|
||||
"github.com/docker/machine/drivers/virtualbox"
|
||||
"github.com/docker/machine/libmachine"
|
||||
"github.com/docker/machine/libmachine/engine"
|
||||
"github.com/docker/machine/libmachine/host"
|
||||
|
|
@ -41,9 +40,9 @@ import (
|
|||
|
||||
cfg "k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
pkgutil "k8s.io/minikube/pkg/util"
|
||||
|
||||
"k8s.io/minikube/pkg/minikube/registry"
|
||||
"k8s.io/minikube/pkg/util"
|
||||
pkgutil "k8s.io/minikube/pkg/util"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -55,14 +54,13 @@ const (
|
|||
//see: https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/util/logs/logs.go#L32-L34
|
||||
func init() {
|
||||
flag.Set("logtostderr", "false")
|
||||
|
||||
// Setting the default client to native gives much better performance.
|
||||
ssh.SetDefaultClient(ssh.Native)
|
||||
|
||||
registry.Register("virtualbox", createVirtualboxHost)
|
||||
}
|
||||
|
||||
// StartHost starts a host VM.
|
||||
func StartHost(api libmachine.API, config MachineConfig) (*host.Host, error) {
|
||||
func StartHost(api libmachine.API, config cfg.MachineConfig) (*host.Host, error) {
|
||||
exists, err := api.Exists(cfg.GetMachineName())
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "Error checking if host exists: %s", cfg.GetMachineName())
|
||||
|
|
@ -171,7 +169,7 @@ func GetHostDriverIP(api libmachine.API) (net.IP, error) {
|
|||
return ip, nil
|
||||
}
|
||||
|
||||
func engineOptions(config MachineConfig) *engine.Options {
|
||||
func engineOptions(config cfg.MachineConfig) *engine.Options {
|
||||
o := engine.Options{
|
||||
Env: config.DockerEnv,
|
||||
InsecureRegistry: append([]string{pkgutil.DefaultServiceCIDR}, config.InsecureRegistry...),
|
||||
|
|
@ -181,20 +179,7 @@ func engineOptions(config MachineConfig) *engine.Options {
|
|||
return &o
|
||||
}
|
||||
|
||||
func createVirtualboxHost(config MachineConfig) RawDriver {
|
||||
d := virtualbox.NewDriver(cfg.GetMachineName(), constants.GetMinipath())
|
||||
d.Boot2DockerURL = config.Downloader.GetISOFileURI(config.MinikubeISO)
|
||||
d.Memory = config.Memory
|
||||
d.CPU = config.CPUs
|
||||
d.DiskSize = int(config.DiskSize)
|
||||
d.HostOnlyCIDR = config.HostOnlyCIDR
|
||||
d.NoShare = config.DisableDriverMounts
|
||||
d.NatNicType = defaultVirtualboxNicType
|
||||
d.HostOnlyNicType = defaultVirtualboxNicType
|
||||
return d
|
||||
}
|
||||
|
||||
func preCreateHost(config *MachineConfig) error {
|
||||
func preCreateHost(config *cfg.MachineConfig) error {
|
||||
switch config.VMDriver {
|
||||
case "kvm":
|
||||
if viper.GetBool(cfg.ShowDriverDeprecationNotification) {
|
||||
|
|
@ -215,15 +200,15 @@ To disable this message, run [minikube config set WantShowDriverDeprecationNotif
|
|||
return nil
|
||||
}
|
||||
|
||||
func createHost(api libmachine.API, config MachineConfig) (*host.Host, error) {
|
||||
func createHost(api libmachine.API, config cfg.MachineConfig) (*host.Host, error) {
|
||||
err := preCreateHost(&config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
driverFunc, err := registry.Driver(config.VMDriver)
|
||||
def, err := registry.Driver(config.VMDriver)
|
||||
if err != nil {
|
||||
if err == ErrDriverNotFound {
|
||||
if err == registry.ErrDriverNotFound {
|
||||
glog.Exitf("Unsupported driver: %s\n", config.VMDriver)
|
||||
} else {
|
||||
glog.Exit(err.Error())
|
||||
|
|
@ -236,7 +221,7 @@ func createHost(api libmachine.API, config MachineConfig) (*host.Host, error) {
|
|||
}
|
||||
}
|
||||
|
||||
driver := driverFunc(config)
|
||||
driver := def.ConfigCreator(config)
|
||||
|
||||
data, err := json.Marshal(driver)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -18,90 +18,8 @@ package cluster
|
|||
|
||||
import (
|
||||
"os/exec"
|
||||
|
||||
"github.com/docker/machine/drivers/vmwarefusion"
|
||||
"github.com/docker/machine/libmachine/drivers"
|
||||
"github.com/pborman/uuid"
|
||||
"k8s.io/minikube/pkg/drivers/hyperkit"
|
||||
cfg "k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
)
|
||||
|
||||
func init() {
|
||||
registry.Register("vmwarefusion", createVMwareFusionHost)
|
||||
registry.Register("hyperkit", createHyperkitHost)
|
||||
registry.Register("xhyve", createXhyveHost)
|
||||
}
|
||||
|
||||
func createVMwareFusionHost(config MachineConfig) RawDriver {
|
||||
d := vmwarefusion.NewDriver(cfg.GetMachineName(), constants.GetMinipath()).(*vmwarefusion.Driver)
|
||||
d.Boot2DockerURL = config.Downloader.GetISOFileURI(config.MinikubeISO)
|
||||
d.Memory = config.Memory
|
||||
d.CPU = config.CPUs
|
||||
d.DiskSize = config.DiskSize
|
||||
|
||||
// TODO(philips): push these defaults upstream to fixup this driver
|
||||
d.SSHPort = 22
|
||||
d.ISO = d.ResolveStorePath("boot2docker.iso")
|
||||
return d
|
||||
}
|
||||
|
||||
type xhyveDriver struct {
|
||||
*drivers.BaseDriver
|
||||
Boot2DockerURL string
|
||||
BootCmd string
|
||||
CPU int
|
||||
CaCertPath string
|
||||
DiskSize int64
|
||||
MacAddr string
|
||||
Memory int
|
||||
PrivateKeyPath string
|
||||
UUID string
|
||||
NFSShare bool
|
||||
DiskNumber int
|
||||
Virtio9p bool
|
||||
Virtio9pFolder string
|
||||
QCow2 bool
|
||||
RawDisk bool
|
||||
}
|
||||
|
||||
func createHyperkitHost(config MachineConfig) RawDriver {
|
||||
return &hyperkit.Driver{
|
||||
BaseDriver: &drivers.BaseDriver{
|
||||
MachineName: cfg.GetMachineName(),
|
||||
StorePath: constants.GetMinipath(),
|
||||
SSHUser: "docker",
|
||||
},
|
||||
Boot2DockerURL: config.Downloader.GetISOFileURI(config.MinikubeISO),
|
||||
DiskSize: config.DiskSize,
|
||||
Memory: config.Memory,
|
||||
CPU: config.CPUs,
|
||||
NFSShares: config.NFSShare,
|
||||
NFSSharesRoot: config.NFSSharesRoot,
|
||||
UUID: uuid.NewUUID().String(),
|
||||
Cmdline: "loglevel=3 user=docker console=ttyS0 console=tty0 noembed nomodeset norestore waitusb=10 systemd.legacy_systemd_cgroup_controller=yes base host=" + cfg.GetMachineName(),
|
||||
}
|
||||
}
|
||||
|
||||
func createXhyveHost(config MachineConfig) RawDriver {
|
||||
useVirtio9p := !config.DisableDriverMounts
|
||||
return &xhyveDriver{
|
||||
BaseDriver: &drivers.BaseDriver{
|
||||
MachineName: cfg.GetMachineName(),
|
||||
StorePath: constants.GetMinipath(),
|
||||
},
|
||||
Memory: config.Memory,
|
||||
CPU: config.CPUs,
|
||||
Boot2DockerURL: config.Downloader.GetISOFileURI(config.MinikubeISO),
|
||||
BootCmd: "loglevel=3 user=docker console=ttyS0 console=tty0 noembed nomodeset norestore waitusb=10 systemd.legacy_systemd_cgroup_controller=yes base host=" + cfg.GetMachineName(),
|
||||
DiskSize: int64(config.DiskSize),
|
||||
Virtio9p: useVirtio9p,
|
||||
Virtio9pFolder: "/Users",
|
||||
QCow2: false,
|
||||
RawDisk: config.XhyveDiskDriver == "virtio-blk",
|
||||
}
|
||||
}
|
||||
|
||||
func detectVBoxManageCmd() string {
|
||||
cmd := "VBoxManage"
|
||||
if path, err := exec.LookPath(cmd); err == nil {
|
||||
|
|
|
|||
|
|
@ -17,77 +17,9 @@ limitations under the License.
|
|||
package cluster
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/docker/machine/libmachine/drivers"
|
||||
"k8s.io/minikube/pkg/drivers/none"
|
||||
cfg "k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
)
|
||||
|
||||
func init() {
|
||||
registry.Register("kvm", createKVMHost)
|
||||
registry.Register("kvm2", createKVM2Host)
|
||||
registry.Register("none", createNoneHost)
|
||||
}
|
||||
|
||||
type kvmDriver struct {
|
||||
*drivers.BaseDriver
|
||||
|
||||
Memory int
|
||||
DiskSize int
|
||||
CPU int
|
||||
Network string
|
||||
PrivateNetwork string
|
||||
ISO string
|
||||
Boot2DockerURL string
|
||||
DiskPath string
|
||||
CacheMode string
|
||||
IOMode string
|
||||
}
|
||||
|
||||
func createKVMHost(config MachineConfig) RawDriver {
|
||||
return &kvmDriver{
|
||||
BaseDriver: &drivers.BaseDriver{
|
||||
MachineName: cfg.GetMachineName(),
|
||||
StorePath: constants.GetMinipath(),
|
||||
SSHUser: "docker",
|
||||
},
|
||||
Memory: config.Memory,
|
||||
CPU: config.CPUs,
|
||||
Network: config.KvmNetwork,
|
||||
PrivateNetwork: "docker-machines",
|
||||
Boot2DockerURL: config.Downloader.GetISOFileURI(config.MinikubeISO),
|
||||
DiskSize: config.DiskSize,
|
||||
DiskPath: filepath.Join(constants.GetMinipath(), "machines", cfg.GetMachineName(), fmt.Sprintf("%s.rawdisk", cfg.GetMachineName())),
|
||||
ISO: filepath.Join(constants.GetMinipath(), "machines", cfg.GetMachineName(), "boot2docker.iso"),
|
||||
CacheMode: "default",
|
||||
IOMode: "threads",
|
||||
}
|
||||
}
|
||||
|
||||
func createKVM2Host(config MachineConfig) RawDriver {
|
||||
return &kvmDriver{
|
||||
BaseDriver: &drivers.BaseDriver{
|
||||
MachineName: cfg.GetMachineName(),
|
||||
StorePath: constants.GetMinipath(),
|
||||
SSHUser: "docker",
|
||||
},
|
||||
Memory: config.Memory,
|
||||
CPU: config.CPUs,
|
||||
Network: config.KvmNetwork,
|
||||
PrivateNetwork: "minikube-net",
|
||||
Boot2DockerURL: config.Downloader.GetISOFileURI(config.MinikubeISO),
|
||||
DiskSize: config.DiskSize,
|
||||
DiskPath: filepath.Join(constants.GetMinipath(), "machines", cfg.GetMachineName(), fmt.Sprintf("%s.rawdisk", cfg.GetMachineName())),
|
||||
ISO: filepath.Join(constants.GetMinipath(), "machines", cfg.GetMachineName(), "boot2docker.iso"),
|
||||
CacheMode: "default",
|
||||
IOMode: "threads",
|
||||
}
|
||||
}
|
||||
|
||||
func detectVBoxManageCmd() string {
|
||||
cmd := "VBoxManage"
|
||||
if path, err := exec.LookPath(cmd); err == nil {
|
||||
|
|
@ -95,12 +27,3 @@ func detectVBoxManageCmd() string {
|
|||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
func createNoneHost(config MachineConfig) RawDriver {
|
||||
return &none.Driver{
|
||||
BaseDriver: &drivers.BaseDriver{
|
||||
MachineName: cfg.GetMachineName(),
|
||||
StorePath: constants.GetMinipath(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import (
|
|||
"github.com/docker/machine/libmachine/state"
|
||||
"k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
"k8s.io/minikube/pkg/minikube/registry"
|
||||
"k8s.io/minikube/pkg/minikube/tests"
|
||||
)
|
||||
|
||||
|
|
@ -35,7 +36,7 @@ type MockDownloader struct{}
|
|||
func (d MockDownloader) GetISOFileURI(isoURL string) string { return "" }
|
||||
func (d MockDownloader) CacheMinikubeISOFromURL(isoURL string) error { return nil }
|
||||
|
||||
var defaultMachineConfig = MachineConfig{
|
||||
var defaultMachineConfig = config.MachineConfig{
|
||||
VMDriver: constants.DefaultVMDriver,
|
||||
MinikubeISO: constants.DefaultIsoUrl,
|
||||
Downloader: MockDownloader{},
|
||||
|
|
@ -67,15 +68,15 @@ func TestCreateHost(t *testing.T) {
|
|||
}
|
||||
|
||||
found := false
|
||||
for _, driver := range ListDrivers() {
|
||||
if h.DriverName == driver {
|
||||
for _, def := range registry.ListDrivers() {
|
||||
if h.DriverName == def.Name {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
t.Fatalf("Wrong driver name: %v. Should be among %v", h.DriverName, ListDrivers())
|
||||
t.Fatalf("Wrong driver name: %v. It should be among drivers %v", h.DriverName, registry.ListDrivers())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -179,7 +180,7 @@ func TestStartHostConfig(t *testing.T) {
|
|||
md := &tests.MockDetector{Provisioner: &tests.MockProvisioner{}}
|
||||
provision.SetDetector(md)
|
||||
|
||||
config := MachineConfig{
|
||||
config := config.MachineConfig{
|
||||
VMDriver: constants.DefaultVMDriver,
|
||||
DockerEnv: []string{"FOO=BAR"},
|
||||
DockerOpt: []string{"param=value"},
|
||||
|
|
|
|||
|
|
@ -22,29 +22,11 @@ import (
|
|||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/docker/machine/drivers/hyperv"
|
||||
"github.com/golang/glog"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/sys/windows/registry"
|
||||
cfg "k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
)
|
||||
|
||||
func init() {
|
||||
registry.Register("hyperkit", createHypervHost)
|
||||
}
|
||||
|
||||
func createHypervHost(config MachineConfig) RawDriver {
|
||||
d := hyperv.NewDriver(cfg.GetMachineName(), constants.GetMinipath())
|
||||
d.Boot2DockerURL = config.Downloader.GetISOFileURI(config.MinikubeISO)
|
||||
d.VSwitch = config.HypervVirtualSwitch
|
||||
d.MemSize = config.Memory
|
||||
d.CPU = config.CPUs
|
||||
d.DiskSize = int(config.DiskSize)
|
||||
d.SSHUser = "docker"
|
||||
return d
|
||||
}
|
||||
|
||||
func detectVBoxManageCmd() string {
|
||||
cmd := "VBoxManage"
|
||||
if p := os.Getenv("VBOX_INSTALL_PATH"); p != "" {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
// +build !darwin
|
||||
|
||||
/*
|
||||
Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||
|
||||
|
|
@ -18,16 +16,13 @@ limitations under the License.
|
|||
|
||||
package cluster
|
||||
|
||||
import "github.com/docker/machine/libmachine/drivers"
|
||||
|
||||
func createVMwareFusionHost(config MachineConfig) drivers.Driver {
|
||||
panic("vmwarefusion not supported")
|
||||
}
|
||||
|
||||
func createXhyveHost(config MachineConfig) drivers.Driver {
|
||||
panic("xhyve not supported")
|
||||
}
|
||||
|
||||
func createHyperkitHost(config MachineConfig) drivers.Driver {
|
||||
panic("hyperkit not supported")
|
||||
}
|
||||
import (
|
||||
_ "k8s.io/minikube/pkg/minikube/drivers/hyperkit"
|
||||
_ "k8s.io/minikube/pkg/minikube/drivers/hyperv"
|
||||
_ "k8s.io/minikube/pkg/minikube/drivers/kvm"
|
||||
_ "k8s.io/minikube/pkg/minikube/drivers/kvm2"
|
||||
_ "k8s.io/minikube/pkg/minikube/drivers/none"
|
||||
_ "k8s.io/minikube/pkg/minikube/drivers/virtualbox"
|
||||
_ "k8s.io/minikube/pkg/minikube/drivers/vmwarefusion"
|
||||
_ "k8s.io/minikube/pkg/minikube/drivers/xhyve"
|
||||
)
|
||||
|
|
@ -1,112 +0,0 @@
|
|||
/*
|
||||
Copyright 2018 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package cluster
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrDriverNameExist is the error returned when trying to register a driver
|
||||
// which already exists in registry
|
||||
ErrDriverNameExist = errors.New("registry: duplicated driver name")
|
||||
|
||||
// ErrDriverNotFound is the error returned when driver of a given name does
|
||||
// not exist in registry
|
||||
ErrDriverNotFound = errors.New("registry: driver not found")
|
||||
)
|
||||
|
||||
// DriverFunc creates a Driver from MachineConfig
|
||||
type DriverFunc func(MachineConfig) RawDriver
|
||||
|
||||
// RawDriver is the configuration of a driver that you can marshal into json bytes
|
||||
// and pass to libmachine's NewHost method
|
||||
type RawDriver interface{}
|
||||
|
||||
// Registry contains all the supported driver types on the host
|
||||
type Registry interface {
|
||||
// Register a driver in registry
|
||||
Register(name string, f DriverFunc) error
|
||||
|
||||
// Driver returns the registered driver from a given name
|
||||
Driver(name string) (DriverFunc, error)
|
||||
|
||||
DriverLister
|
||||
}
|
||||
|
||||
// DriverLister lists the name of the supported drivers
|
||||
type DriverLister interface {
|
||||
// List lists all the driver types
|
||||
List() []string
|
||||
}
|
||||
|
||||
type driverRegistry struct {
|
||||
drivers map[string]DriverFunc
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
func createRegistry() *driverRegistry {
|
||||
return &driverRegistry{
|
||||
drivers: make(map[string]DriverFunc),
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
registry = createRegistry()
|
||||
)
|
||||
|
||||
func ListDrivers() []string {
|
||||
return registry.List()
|
||||
}
|
||||
|
||||
func (r *driverRegistry) Register(name string, f DriverFunc) error {
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
|
||||
if _, ok := r.drivers[name]; ok {
|
||||
return ErrDriverNameExist
|
||||
}
|
||||
|
||||
r.drivers[name] = f
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *driverRegistry) List() []string {
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
|
||||
result := make([]string, 0, len(r.drivers))
|
||||
|
||||
for name := range r.drivers {
|
||||
result = append(result, name)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (r *driverRegistry) Driver(name string) (DriverFunc, error) {
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
|
||||
if driver, ok := r.drivers[name]; ok {
|
||||
return driver, nil
|
||||
}
|
||||
|
||||
return nil, ErrDriverNotFound
|
||||
}
|
||||
|
|
@ -14,13 +14,20 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package cluster
|
||||
package config
|
||||
|
||||
import (
|
||||
"k8s.io/minikube/pkg/minikube/bootstrapper"
|
||||
"net"
|
||||
|
||||
"k8s.io/minikube/pkg/util"
|
||||
)
|
||||
|
||||
// Config contains machine and k8s config
|
||||
type Config struct {
|
||||
MachineConfig MachineConfig
|
||||
KubernetesConfig KubernetesConfig
|
||||
}
|
||||
|
||||
// MachineConfig contains the parameters used to start a cluster.
|
||||
type MachineConfig struct {
|
||||
MinikubeISO string
|
||||
|
|
@ -43,8 +50,20 @@ type MachineConfig struct {
|
|||
UUID string // Only used by hyperkit to restore the mac address
|
||||
}
|
||||
|
||||
// Config contains machine and k8s config
|
||||
type Config struct {
|
||||
MachineConfig MachineConfig
|
||||
KubernetesConfig bootstrapper.KubernetesConfig
|
||||
// KubernetesConfig contains the parameters used to configure the VM Kubernetes.
|
||||
type KubernetesConfig struct {
|
||||
KubernetesVersion string
|
||||
NodeIP string
|
||||
NodeName string
|
||||
APIServerName string
|
||||
APIServerNames []string
|
||||
APIServerIPs []net.IP
|
||||
DNSDomain string
|
||||
ContainerRuntime string
|
||||
NetworkPlugin string
|
||||
FeatureGates string
|
||||
ServiceCIDR string
|
||||
ExtraOptions util.ExtraOptionSlice
|
||||
|
||||
ShouldLoadCachedImages bool
|
||||
}
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
// +build !linux
|
||||
|
||||
/*
|
||||
Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||
Copyright 2018 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
@ -16,18 +14,4 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package cluster
|
||||
|
||||
import "github.com/docker/machine/libmachine/drivers"
|
||||
|
||||
func createKVMHost(config MachineConfig) drivers.Driver {
|
||||
panic("kvm not supported")
|
||||
}
|
||||
|
||||
func createKVM2Host(config MachineConfig) drivers.Driver {
|
||||
panic("kvm2 not supported")
|
||||
}
|
||||
|
||||
func createNoneHost(config MachineConfig) drivers.Driver {
|
||||
panic("no-vm not supported")
|
||||
}
|
||||
package hyperkit
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
// +build darwin
|
||||
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package hyperkit
|
||||
|
||||
import (
|
||||
"github.com/docker/machine/libmachine/drivers"
|
||||
"github.com/pborman/uuid"
|
||||
"k8s.io/minikube/pkg/drivers/hyperkit"
|
||||
cfg "k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
"k8s.io/minikube/pkg/minikube/registry"
|
||||
)
|
||||
|
||||
func init() {
|
||||
registry.Register(registry.DriverDef{
|
||||
Name: "hyperkit",
|
||||
Builtin: false,
|
||||
ConfigCreator: createHyperkitHost,
|
||||
})
|
||||
}
|
||||
|
||||
func createHyperkitHost(config cfg.MachineConfig) interface{} {
|
||||
return &hyperkit.Driver{
|
||||
BaseDriver: &drivers.BaseDriver{
|
||||
MachineName: cfg.GetMachineName(),
|
||||
StorePath: constants.GetMinipath(),
|
||||
SSHUser: "docker",
|
||||
},
|
||||
Boot2DockerURL: config.Downloader.GetISOFileURI(config.MinikubeISO),
|
||||
DiskSize: config.DiskSize,
|
||||
Memory: config.Memory,
|
||||
CPU: config.CPUs,
|
||||
NFSShares: config.NFSShare,
|
||||
NFSSharesRoot: config.NFSSharesRoot,
|
||||
UUID: uuid.NewUUID().String(),
|
||||
Cmdline: "loglevel=3 user=docker console=ttyS0 console=tty0 noembed nomodeset norestore waitusb=10 systemd.legacy_systemd_cgroup_controller=yes base host=" + cfg.GetMachineName(),
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
Copyright 2018 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package hyperv
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
// +build windows
|
||||
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package hyperv
|
||||
|
||||
import (
|
||||
"github.com/docker/machine/drivers/hyperv"
|
||||
"github.com/docker/machine/libmachine/drivers"
|
||||
cfg "k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
"k8s.io/minikube/pkg/minikube/registry"
|
||||
)
|
||||
|
||||
func init() {
|
||||
registry.Register(registry.DriverDef{
|
||||
Name: "hyperv",
|
||||
Builtin: true,
|
||||
ConfigCreator: createHypervHost,
|
||||
DriverCreator: func() drivers.Driver {
|
||||
return hyperv.NewDriver("", "")
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func createHypervHost(config cfg.MachineConfig) interface{} {
|
||||
d := hyperv.NewDriver(cfg.GetMachineName(), constants.GetMinipath())
|
||||
|
||||
d.Boot2DockerURL = config.Downloader.GetISOFileURI(config.MinikubeISO)
|
||||
d.VSwitch = config.HypervVirtualSwitch
|
||||
d.MemSize = config.Memory
|
||||
d.CPU = config.CPUs
|
||||
d.DiskSize = int(config.DiskSize)
|
||||
d.SSHUser = "docker"
|
||||
|
||||
return d
|
||||
}
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
// +build !windows
|
||||
|
||||
/*
|
||||
Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||
Copyright 2018 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
@ -16,10 +14,6 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package cluster
|
||||
package kvm
|
||||
|
||||
import "github.com/docker/machine/libmachine/drivers"
|
||||
|
||||
func createHypervHost(config MachineConfig) drivers.Driver {
|
||||
panic("hyperv not supported")
|
||||
}
|
||||
// doc...
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
// +build linux
|
||||
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package kvm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/docker/machine/libmachine/drivers"
|
||||
cfg "k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
"k8s.io/minikube/pkg/minikube/registry"
|
||||
)
|
||||
|
||||
func init() {
|
||||
registry.Register(registry.DriverDef{
|
||||
Name: "kvm",
|
||||
Builtin: false,
|
||||
ConfigCreator: createKVMHost,
|
||||
})
|
||||
}
|
||||
|
||||
// Delete this once the following PR is merged:
|
||||
// https://github.com/dhiltgen/docker-machine-kvm/pull/68
|
||||
type kvmDriver struct {
|
||||
*drivers.BaseDriver
|
||||
|
||||
Memory int
|
||||
DiskSize int
|
||||
CPU int
|
||||
Network string
|
||||
PrivateNetwork string
|
||||
ISO string
|
||||
Boot2DockerURL string
|
||||
DiskPath string
|
||||
CacheMode string
|
||||
IOMode string
|
||||
}
|
||||
|
||||
func createKVMHost(config cfg.MachineConfig) interface{} {
|
||||
return &kvmDriver{
|
||||
BaseDriver: &drivers.BaseDriver{
|
||||
MachineName: cfg.GetMachineName(),
|
||||
StorePath: constants.GetMinipath(),
|
||||
SSHUser: "docker",
|
||||
},
|
||||
Memory: config.Memory,
|
||||
CPU: config.CPUs,
|
||||
Network: config.KvmNetwork,
|
||||
PrivateNetwork: "docker-machines",
|
||||
Boot2DockerURL: config.Downloader.GetISOFileURI(config.MinikubeISO),
|
||||
DiskSize: config.DiskSize,
|
||||
DiskPath: filepath.Join(constants.GetMinipath(), "machines", cfg.GetMachineName(), fmt.Sprintf("%s.rawdisk", cfg.GetMachineName())),
|
||||
ISO: filepath.Join(constants.GetMinipath(), "machines", cfg.GetMachineName(), "boot2docker.iso"),
|
||||
CacheMode: "default",
|
||||
IOMode: "threads",
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
Copyright 2018 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package kvm2
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
// +build linux
|
||||
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package kvm2
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/docker/machine/libmachine/drivers"
|
||||
cfg "k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
"k8s.io/minikube/pkg/minikube/registry"
|
||||
)
|
||||
|
||||
func init() {
|
||||
registry.Register(registry.DriverDef{
|
||||
Name: "kvm2",
|
||||
Builtin: false,
|
||||
ConfigCreator: createKVM2Host,
|
||||
})
|
||||
}
|
||||
|
||||
// Delete this once the following PR is merged:
|
||||
// https://github.com/dhiltgen/docker-machine-kvm/pull/68
|
||||
type kvmDriver struct {
|
||||
*drivers.BaseDriver
|
||||
|
||||
Memory int
|
||||
DiskSize int
|
||||
CPU int
|
||||
Network string
|
||||
PrivateNetwork string
|
||||
ISO string
|
||||
Boot2DockerURL string
|
||||
DiskPath string
|
||||
CacheMode string
|
||||
IOMode string
|
||||
}
|
||||
|
||||
func createKVM2Host(config cfg.MachineConfig) interface{} {
|
||||
return &kvmDriver{
|
||||
BaseDriver: &drivers.BaseDriver{
|
||||
MachineName: cfg.GetMachineName(),
|
||||
StorePath: constants.GetMinipath(),
|
||||
SSHUser: "docker",
|
||||
},
|
||||
Memory: config.Memory,
|
||||
CPU: config.CPUs,
|
||||
Network: config.KvmNetwork,
|
||||
PrivateNetwork: "minikube-net",
|
||||
Boot2DockerURL: config.Downloader.GetISOFileURI(config.MinikubeISO),
|
||||
DiskSize: config.DiskSize,
|
||||
DiskPath: filepath.Join(constants.GetMinipath(), "machines", cfg.GetMachineName(), fmt.Sprintf("%s.rawdisk", cfg.GetMachineName())),
|
||||
ISO: filepath.Join(constants.GetMinipath(), "machines", cfg.GetMachineName(), "boot2docker.iso"),
|
||||
CacheMode: "default",
|
||||
IOMode: "threads",
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
Copyright 2018 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package none
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
// +build linux
|
||||
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package none
|
||||
|
||||
import (
|
||||
"github.com/docker/machine/libmachine/drivers"
|
||||
"k8s.io/minikube/pkg/drivers/none"
|
||||
cfg "k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
"k8s.io/minikube/pkg/minikube/registry"
|
||||
)
|
||||
|
||||
func init() {
|
||||
registry.Register(registry.DriverDef{
|
||||
Name: "none",
|
||||
Builtin: true,
|
||||
ConfigCreator: createNoneHost,
|
||||
DriverCreator: func() drivers.Driver {
|
||||
return none.NewDriver("", "")
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func createNoneHost(config cfg.MachineConfig) interface{} {
|
||||
return &none.Driver{
|
||||
BaseDriver: &drivers.BaseDriver{
|
||||
MachineName: cfg.GetMachineName(),
|
||||
StorePath: constants.GetMinipath(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
Copyright 2018 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package virtualbox
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
Copyright 2018 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package virtualbox
|
||||
|
||||
import (
|
||||
"github.com/docker/machine/drivers/virtualbox"
|
||||
"github.com/docker/machine/libmachine/drivers"
|
||||
cfg "k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
"k8s.io/minikube/pkg/minikube/registry"
|
||||
)
|
||||
|
||||
const defaultVirtualboxNicType = "virtio"
|
||||
|
||||
func init() {
|
||||
registry.Register(registry.DriverDef{
|
||||
Name: "virtualbox",
|
||||
Builtin: true,
|
||||
ConfigCreator: createVirtualboxHost,
|
||||
DriverCreator: func() drivers.Driver {
|
||||
return virtualbox.NewDriver("", "")
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func createVirtualboxHost(config cfg.MachineConfig) interface{} {
|
||||
d := virtualbox.NewDriver(cfg.GetMachineName(), constants.GetMinipath())
|
||||
|
||||
d.Boot2DockerURL = config.Downloader.GetISOFileURI(config.MinikubeISO)
|
||||
d.Memory = config.Memory
|
||||
d.CPU = config.CPUs
|
||||
d.DiskSize = int(config.DiskSize)
|
||||
d.HostOnlyCIDR = config.HostOnlyCIDR
|
||||
d.NoShare = config.DisableDriverMounts
|
||||
d.NatNicType = defaultVirtualboxNicType
|
||||
d.HostOnlyNicType = defaultVirtualboxNicType
|
||||
|
||||
return d
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
Copyright 2018 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package vmwarefusion
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
// +build darwin
|
||||
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package vmwarefusion
|
||||
|
||||
import (
|
||||
"github.com/docker/machine/drivers/vmwarefusion"
|
||||
"github.com/docker/machine/libmachine/drivers"
|
||||
cfg "k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
"k8s.io/minikube/pkg/minikube/registry"
|
||||
)
|
||||
|
||||
func init() {
|
||||
registry.Register(registry.DriverDef{
|
||||
Name: "vmwarefusion",
|
||||
Builtin: true,
|
||||
ConfigCreator: createVMwareFusionHost,
|
||||
DriverCreator: func() drivers.Driver {
|
||||
return vmwarefusion.NewDriver("", "")
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func createVMwareFusionHost(config cfg.MachineConfig) interface{} {
|
||||
d := vmwarefusion.NewDriver(cfg.GetMachineName(), constants.GetMinipath()).(*vmwarefusion.Driver)
|
||||
d.Boot2DockerURL = config.Downloader.GetISOFileURI(config.MinikubeISO)
|
||||
d.Memory = config.Memory
|
||||
d.CPU = config.CPUs
|
||||
d.DiskSize = config.DiskSize
|
||||
|
||||
// TODO(philips): push these defaults upstream to fixup this driver
|
||||
d.SSHPort = 22
|
||||
d.ISO = d.ResolveStorePath("boot2docker.iso")
|
||||
return d
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
Copyright 2018 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package xhyve
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
// +build darwin
|
||||
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package xhyve
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/docker/machine/libmachine/drivers"
|
||||
cfg "k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
"k8s.io/minikube/pkg/minikube/registry"
|
||||
)
|
||||
|
||||
const errMsg = `
|
||||
The Xhyve driver is not included in minikube yet. Please follow the directions at
|
||||
https://github.com/kubernetes/minikube/blob/master/DRIVERS.md#xhyve-driver
|
||||
`
|
||||
|
||||
func init() {
|
||||
registry.Register(registry.DriverDef{
|
||||
Name: "xhyve",
|
||||
Builtin: false,
|
||||
ConfigCreator: createXhyveHost,
|
||||
DriverCreator: func() drivers.Driver {
|
||||
fmt.Fprintln(os.Stderr, errMsg)
|
||||
os.Exit(1)
|
||||
return nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
type xhyveDriver struct {
|
||||
*drivers.BaseDriver
|
||||
|
||||
Boot2DockerURL string
|
||||
BootCmd string
|
||||
CPU int
|
||||
CaCertPath string
|
||||
DiskSize int64
|
||||
MacAddr string
|
||||
Memory int
|
||||
PrivateKeyPath string
|
||||
UUID string
|
||||
NFSShare bool
|
||||
DiskNumber int
|
||||
Virtio9p bool
|
||||
Virtio9pFolder string
|
||||
QCow2 bool
|
||||
RawDisk bool
|
||||
}
|
||||
|
||||
func createXhyveHost(config cfg.MachineConfig) interface{} {
|
||||
useVirtio9p := !config.DisableDriverMounts
|
||||
return &xhyveDriver{
|
||||
BaseDriver: &drivers.BaseDriver{
|
||||
MachineName: cfg.GetMachineName(),
|
||||
StorePath: constants.GetMinipath(),
|
||||
},
|
||||
Memory: config.Memory,
|
||||
CPU: config.CPUs,
|
||||
Boot2DockerURL: config.Downloader.GetISOFileURI(config.MinikubeISO),
|
||||
BootCmd: "loglevel=3 user=docker console=ttyS0 console=tty0 noembed nomodeset norestore waitusb=10 systemd.legacy_systemd_cgroup_controller=yes base host=" + cfg.GetMachineName(),
|
||||
DiskSize: int64(config.DiskSize),
|
||||
Virtio9p: useVirtio9p,
|
||||
Virtio9pFolder: "/Users",
|
||||
QCow2: false,
|
||||
RawDisk: config.XhyveDiskDriver == "virtio-blk",
|
||||
}
|
||||
}
|
||||
|
|
@ -27,15 +27,16 @@ import (
|
|||
|
||||
"k8s.io/minikube/pkg/minikube/bootstrapper"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
"k8s.io/minikube/pkg/minikube/registry"
|
||||
"k8s.io/minikube/pkg/minikube/sshutil"
|
||||
"k8s.io/minikube/pkg/provision"
|
||||
|
||||
"github.com/docker/machine/drivers/virtualbox"
|
||||
"github.com/docker/machine/libmachine"
|
||||
"github.com/docker/machine/libmachine/auth"
|
||||
"github.com/docker/machine/libmachine/cert"
|
||||
"github.com/docker/machine/libmachine/check"
|
||||
"github.com/docker/machine/libmachine/drivers"
|
||||
"github.com/docker/machine/libmachine/drivers/plugin"
|
||||
"github.com/docker/machine/libmachine/drivers/plugin/localbinary"
|
||||
"github.com/docker/machine/libmachine/engine"
|
||||
"github.com/docker/machine/libmachine/host"
|
||||
|
|
@ -45,11 +46,10 @@ import (
|
|||
"github.com/docker/machine/libmachine/state"
|
||||
"github.com/docker/machine/libmachine/swarm"
|
||||
"github.com/docker/machine/libmachine/version"
|
||||
"github.com/golang/glog"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type driverGetter func([]byte) (drivers.Driver, error)
|
||||
|
||||
func NewRPCClient(storePath, certsDir string) libmachine.API {
|
||||
c := libmachine.NewClient(storePath, certsDir)
|
||||
c.SSHClientType = ssh.Native
|
||||
|
|
@ -69,29 +69,6 @@ func NewAPIClient() (libmachine.API, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
func getDriver(driverName string, rawDriver []byte) (drivers.Driver, error) {
|
||||
driverGetter, ok := driverMap[driverName]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("Unknown driver %s for platform.", driverName)
|
||||
}
|
||||
driver, err := driverGetter(rawDriver)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "Error getting driver for %s", driverName)
|
||||
}
|
||||
|
||||
return driver, nil
|
||||
}
|
||||
|
||||
func getVirtualboxDriver(rawDriver []byte) (drivers.Driver, error) {
|
||||
var driver drivers.Driver
|
||||
driver = virtualbox.NewDriver("", "")
|
||||
err := json.Unmarshal(rawDriver, driver)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "Error unmarshalling virtualbox driver %s", string(rawDriver))
|
||||
}
|
||||
return driver, nil
|
||||
}
|
||||
|
||||
// LocalClient is a non-RPC implementation
|
||||
// of the libmachine API
|
||||
type LocalClient struct {
|
||||
|
|
@ -102,15 +79,21 @@ type LocalClient struct {
|
|||
}
|
||||
|
||||
func (api *LocalClient) NewHost(driverName string, rawDriver []byte) (*host.Host, error) {
|
||||
// If not should get Driver, use legacy
|
||||
if _, ok := driverMap[driverName]; !ok {
|
||||
var def registry.DriverDef
|
||||
var err error
|
||||
if def, err = registry.Driver(driverName); err != nil {
|
||||
return nil, err
|
||||
} else if !def.Builtin || def.DriverCreator == nil {
|
||||
return api.legacyClient.NewHost(driverName, rawDriver)
|
||||
}
|
||||
|
||||
driver, err := getDriver(driverName, rawDriver)
|
||||
driver := def.DriverCreator()
|
||||
|
||||
err = json.Unmarshal(rawDriver, driver)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Error getting driver")
|
||||
return nil, errors.Wrapf(err, "Error getting driver %s", string(rawDriver))
|
||||
}
|
||||
|
||||
return &host.Host{
|
||||
ConfigVersion: version.ConfigVersion,
|
||||
Name: driver.GetMachineName(),
|
||||
|
|
@ -141,17 +124,22 @@ func (api *LocalClient) Load(name string) (*host.Host, error) {
|
|||
return nil, errors.Wrap(err, "Error loading host from store")
|
||||
}
|
||||
|
||||
// If not should get Driver, use legacy
|
||||
if _, ok := driverMap[h.DriverName]; !ok {
|
||||
var def registry.DriverDef
|
||||
if def, err = registry.Driver(h.DriverName); err != nil {
|
||||
return nil, err
|
||||
} else if !def.Builtin || def.DriverCreator == nil {
|
||||
return api.legacyClient.Load(name)
|
||||
}
|
||||
|
||||
h.Driver, err = getDriver(h.DriverName, h.RawDriver)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Error loading driver from host")
|
||||
}
|
||||
h.Driver = def.DriverCreator()
|
||||
return h, json.Unmarshal(h.RawDriver, h.Driver)
|
||||
}
|
||||
|
||||
return h, nil
|
||||
func (api *LocalClient) Close() error {
|
||||
if api.legacyClient != nil {
|
||||
return api.legacyClient.Close()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetCommandRunner(h *host.Host) (bootstrapper.CommandRunner, error) {
|
||||
|
|
@ -166,16 +154,10 @@ func GetCommandRunner(h *host.Host) (bootstrapper.CommandRunner, error) {
|
|||
return &bootstrapper.ExecRunner{}, nil
|
||||
}
|
||||
|
||||
func (api *LocalClient) Close() error {
|
||||
if api.legacyClient != nil {
|
||||
return api.legacyClient.Close()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (api *LocalClient) Create(h *host.Host) error {
|
||||
|
||||
if _, ok := driverMap[h.Driver.DriverName()]; !ok {
|
||||
if def, err := registry.Driver(h.DriverName); err != nil {
|
||||
return err
|
||||
} else if !def.Builtin || def.DriverCreator == nil {
|
||||
return api.legacyClient.Create(h)
|
||||
}
|
||||
|
||||
|
|
@ -276,3 +258,12 @@ func (cg *CertGenerator) ValidateCertificate(addr string, authOptions *auth.Opti
|
|||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func registerDriver(driverName string) {
|
||||
def, err := registry.Driver(driverName)
|
||||
if err != nil {
|
||||
glog.Exitf("Unsupported driver: %s\n", driverName)
|
||||
}
|
||||
|
||||
plugin.RegisterDriver(def.DriverCreator())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package machine
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/docker/machine/drivers/virtualbox"
|
||||
"github.com/docker/machine/drivers/vmwarefusion"
|
||||
"github.com/docker/machine/libmachine/drivers"
|
||||
"github.com/docker/machine/libmachine/drivers/plugin"
|
||||
"github.com/golang/glog"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var driverMap = map[string]driverGetter{
|
||||
"vmwarefusion": getVMWareFusionDriver,
|
||||
"virtualbox": getVirtualboxDriver,
|
||||
}
|
||||
|
||||
func getVMWareFusionDriver(rawDriver []byte) (drivers.Driver, error) {
|
||||
var driver drivers.Driver
|
||||
driver = &vmwarefusion.Driver{}
|
||||
if err := json.Unmarshal(rawDriver, &driver); err != nil {
|
||||
return nil, errors.Wrap(err, "Error unmarshalling vmwarefusion driver")
|
||||
}
|
||||
return driver, nil
|
||||
}
|
||||
|
||||
// Xhyve driver not implemented yet for non-RPC access
|
||||
func getXhyveDriver(rawDriver []byte) (drivers.Driver, error) {
|
||||
return nil, errors.New(`
|
||||
The Xhyve driver is not included in minikube yet. Please follow the directions at
|
||||
https://github.com/kubernetes/minikube/blob/master/DRIVERS.md#xhyve-driver
|
||||
`)
|
||||
}
|
||||
|
||||
// StartDriver starts the desired machine driver if necessary.
|
||||
func registerDriver(driverName string) {
|
||||
switch driverName {
|
||||
case "virtualbox":
|
||||
plugin.RegisterDriver(virtualbox.NewDriver("", ""))
|
||||
case "vmwarefusion":
|
||||
plugin.RegisterDriver(vmwarefusion.NewDriver("", ""))
|
||||
default:
|
||||
glog.Exitf("Unsupported driver: %s\n", driverName)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package machine
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/docker/machine/drivers/virtualbox"
|
||||
"github.com/docker/machine/libmachine/drivers"
|
||||
"github.com/docker/machine/libmachine/drivers/plugin"
|
||||
"github.com/golang/glog"
|
||||
"github.com/pkg/errors"
|
||||
"k8s.io/minikube/pkg/drivers/none"
|
||||
)
|
||||
|
||||
var driverMap = map[string]driverGetter{
|
||||
"virtualbox": getVirtualboxDriver,
|
||||
"none": getNoneDriver,
|
||||
}
|
||||
|
||||
func getNoneDriver(rawDriver []byte) (drivers.Driver, error) {
|
||||
var driver drivers.Driver
|
||||
driver = &none.Driver{}
|
||||
if err := json.Unmarshal(rawDriver, &driver); err != nil {
|
||||
return nil, errors.Wrap(err, "Error unmarshalling none driver")
|
||||
}
|
||||
return driver, nil
|
||||
}
|
||||
|
||||
// StartDriver starts the desired machine driver if necessary.
|
||||
func registerDriver(driverName string) {
|
||||
switch driverName {
|
||||
case "virtualbox":
|
||||
plugin.RegisterDriver(virtualbox.NewDriver("", ""))
|
||||
case "none":
|
||||
plugin.RegisterDriver(none.NewDriver("", ""))
|
||||
default:
|
||||
glog.Exitf("Unsupported driver: %s\n", driverName)
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,7 @@ package machine
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
|
|
@ -25,11 +26,9 @@ import (
|
|||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/machine/drivers/virtualbox"
|
||||
"github.com/docker/machine/libmachine/drivers"
|
||||
|
||||
"github.com/docker/machine/libmachine/drivers/plugin/localbinary"
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
_ "k8s.io/minikube/pkg/minikube/drivers/virtualbox"
|
||||
)
|
||||
|
||||
const vboxConfig = `
|
||||
|
|
@ -63,54 +62,6 @@ const vboxConfig = `
|
|||
}
|
||||
`
|
||||
|
||||
func TestGetDriver(t *testing.T) {
|
||||
var tests = []struct {
|
||||
description string
|
||||
driver string
|
||||
rawDriver []byte
|
||||
expected drivers.Driver
|
||||
err bool
|
||||
}{
|
||||
{
|
||||
description: "vbox correct",
|
||||
driver: "virtualbox",
|
||||
rawDriver: []byte(vboxConfig),
|
||||
expected: virtualbox.NewDriver("", ""),
|
||||
},
|
||||
{
|
||||
description: "unknown driver",
|
||||
driver: "unknown",
|
||||
rawDriver: []byte("?"),
|
||||
expected: nil,
|
||||
err: true,
|
||||
},
|
||||
{
|
||||
description: "vbox bad",
|
||||
driver: "virtualbox",
|
||||
rawDriver: []byte("?"),
|
||||
expected: nil,
|
||||
err: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
test := test
|
||||
t.Run(test.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
driver, err := getDriver(test.driver, test.rawDriver)
|
||||
if err != nil && !test.err {
|
||||
t.Errorf("Unexpected error: %s", err)
|
||||
}
|
||||
if err == nil && test.err {
|
||||
t.Errorf("No error returned, but expected err")
|
||||
}
|
||||
if driver != nil && test.expected.DriverName() != driver.DriverName() {
|
||||
t.Errorf("Driver names did not match, actual: %s, expected: %s", driver.DriverName(), test.expected.DriverName())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLocalClientNewHost(t *testing.T) {
|
||||
c, err := NewAPIClient()
|
||||
if err != nil {
|
||||
|
|
@ -182,9 +133,9 @@ func TestRunNotDriver(t *testing.T) {
|
|||
func TestRunDriver(t *testing.T) {
|
||||
// This test is a bit complicated. It verifies that when the root command is
|
||||
// called with the proper environment variables, we setup the libmachine driver.
|
||||
|
||||
tempDir := makeTempDir()
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
os.Setenv(localbinary.PluginEnvKey, localbinary.PluginEnvVal)
|
||||
os.Setenv(localbinary.PluginEnvDriverName, "virtualbox")
|
||||
|
||||
|
|
@ -207,6 +158,8 @@ func TestRunDriver(t *testing.T) {
|
|||
}
|
||||
os.Stdout = old
|
||||
|
||||
fmt.Println(string(addr))
|
||||
|
||||
// Now that we got the port, make sure we can connect.
|
||||
if _, err := net.Dial("tcp", string(addr)); err != nil {
|
||||
t.Fatal("Driver not listening.")
|
||||
|
|
|
|||
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package machine
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/docker/machine/drivers/hyperv"
|
||||
"github.com/docker/machine/drivers/virtualbox"
|
||||
"github.com/docker/machine/libmachine/drivers"
|
||||
"github.com/docker/machine/libmachine/drivers/plugin"
|
||||
"github.com/golang/glog"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var driverMap = map[string]driverGetter{
|
||||
"hyperv": getHyperVDriver,
|
||||
"virtualbox": getVirtualboxDriver,
|
||||
}
|
||||
|
||||
func getHyperVDriver(rawDriver []byte) (drivers.Driver, error) {
|
||||
var driver drivers.Driver
|
||||
driver = &hyperv.Driver{}
|
||||
if err := json.Unmarshal(rawDriver, &driver); err != nil {
|
||||
return nil, errors.Wrap(err, "Error unmarshalling hyperv driver")
|
||||
}
|
||||
return driver, nil
|
||||
}
|
||||
|
||||
// StartDriver starts the desired machine driver if necessary.
|
||||
func registerDriver(driverName string) {
|
||||
switch driverName {
|
||||
case "virtualbox":
|
||||
plugin.RegisterDriver(virtualbox.NewDriver("", ""))
|
||||
case "hyperv":
|
||||
plugin.RegisterDriver(hyperv.NewDriver("", ""))
|
||||
default:
|
||||
glog.Exitf("Unsupported driver: %s\n", driverName)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
// +build !linux,!windows,!darwin
|
||||
|
||||
/*
|
||||
Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||
Copyright 2018 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
@ -16,12 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package machine
|
||||
// This package contains the registry to enable a docker machine driver to be used
|
||||
// in minikube.
|
||||
|
||||
import "github.com/golang/glog"
|
||||
|
||||
var driverMap = map[string]driverGetter{}
|
||||
|
||||
func registerDriver(driverName string) {
|
||||
glog.Errorf("Unsupported platform")
|
||||
}
|
||||
package registry
|
||||
|
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
Copyright 2018 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package registry
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/docker/machine/libmachine/drivers"
|
||||
"github.com/pkg/errors"
|
||||
"k8s.io/minikube/pkg/minikube/config"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrDriverNameExist is the error returned when trying to register a driver
|
||||
// which already exists in registry
|
||||
ErrDriverNameExist = errors.New("registry: duplicated driver name")
|
||||
|
||||
// ErrDriverNotFound is the error returned when driver of a given name does
|
||||
// not exist in registry
|
||||
ErrDriverNotFound = errors.New("registry: driver not found")
|
||||
)
|
||||
|
||||
// Registry contains all the supported driver definitions on the host
|
||||
type Registry interface {
|
||||
// Register a driver in registry
|
||||
Register(driver DriverDef) error
|
||||
|
||||
// Driver returns the registered driver from a given name
|
||||
Driver(name string) (DriverDef, error)
|
||||
|
||||
// List
|
||||
List() []DriverDef
|
||||
}
|
||||
|
||||
// ConfigFactory is a function that creates a driver config from MachineConfig
|
||||
type ConfigFactory func(config.MachineConfig) interface{}
|
||||
|
||||
// DriverFactory is a function that load a byte stream and create a driver
|
||||
type DriverFactory func() drivers.Driver
|
||||
|
||||
// DriverDef defines a machine driver metadata. It tells minikube how to initialize
|
||||
// and load drivers.
|
||||
type DriverDef struct {
|
||||
// Name of the machine driver. It has to be unique.
|
||||
Name string
|
||||
|
||||
// BuiltIn indicates if the driver is builtin minikube binary, or the driver is
|
||||
// triggerred through RPC.
|
||||
Builtin bool
|
||||
|
||||
// ConfigCreator generate a raw driver object by minikube's machine config.
|
||||
ConfigCreator ConfigFactory
|
||||
|
||||
// DriverCreator is the factory method that creates a machine driver instance.
|
||||
DriverCreator DriverFactory
|
||||
}
|
||||
|
||||
func (d DriverDef) String() string {
|
||||
return fmt.Sprintf("{name: %s, builtin: %t}", d.Name, d.Builtin)
|
||||
}
|
||||
|
||||
type driverRegistry struct {
|
||||
drivers map[string]DriverDef
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
func createRegistry() *driverRegistry {
|
||||
return &driverRegistry{
|
||||
drivers: make(map[string]DriverDef),
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
registry = createRegistry()
|
||||
)
|
||||
|
||||
func ListDrivers() []DriverDef {
|
||||
return registry.List()
|
||||
}
|
||||
|
||||
func Register(driver DriverDef) error {
|
||||
return registry.Register(driver)
|
||||
}
|
||||
|
||||
func Driver(name string) (DriverDef, error) {
|
||||
return registry.Driver(name)
|
||||
}
|
||||
|
||||
func (r *driverRegistry) Register(def DriverDef) error {
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
|
||||
if _, ok := r.drivers[def.Name]; ok {
|
||||
return ErrDriverNameExist
|
||||
}
|
||||
|
||||
r.drivers[def.Name] = def
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *driverRegistry) List() []DriverDef {
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
|
||||
result := make([]DriverDef, 0, len(r.drivers))
|
||||
|
||||
for _, def := range r.drivers {
|
||||
result = append(result, def)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (r *driverRegistry) Driver(name string) (DriverDef, error) {
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
|
||||
if driver, ok := r.drivers[name]; ok {
|
||||
return driver, nil
|
||||
}
|
||||
|
||||
return DriverDef{}, ErrDriverNotFound
|
||||
}
|
||||
|
|
@ -14,31 +14,43 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package cluster
|
||||
package registry
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"k8s.io/minikube/pkg/minikube/config"
|
||||
)
|
||||
|
||||
func TestRegistry(t *testing.T) {
|
||||
dummy := func(_ MachineConfig) RawDriver {
|
||||
return nil
|
||||
foo := DriverDef{
|
||||
Name: "foo",
|
||||
Builtin: true,
|
||||
ConfigCreator: func(_ config.MachineConfig) interface{} {
|
||||
return nil
|
||||
},
|
||||
}
|
||||
bar := DriverDef{
|
||||
Name: "bar",
|
||||
Builtin: true,
|
||||
ConfigCreator: func(_ config.MachineConfig) interface{} {
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
registry := createRegistry()
|
||||
|
||||
err := registry.Register("foo", dummy)
|
||||
err := registry.Register(foo)
|
||||
if err != nil {
|
||||
t.Fatal("expect nil")
|
||||
}
|
||||
|
||||
err = registry.Register("foo", dummy)
|
||||
err = registry.Register(foo)
|
||||
if err != ErrDriverNameExist {
|
||||
t.Fatal("expect ErrDriverNameExist")
|
||||
}
|
||||
|
||||
err = registry.Register("bar", dummy)
|
||||
err = registry.Register(bar)
|
||||
if err != nil {
|
||||
t.Fatal("expect nil")
|
||||
}
|
||||
|
|
@ -48,8 +60,7 @@ func TestRegistry(t *testing.T) {
|
|||
t.Fatalf("expect len(list) to be %d; got %d", 2, len(list))
|
||||
}
|
||||
|
||||
sort.Strings(list)
|
||||
if list[0] != "bar" || list[1] != "foo" {
|
||||
if !(list[0].Name == "bar" && list[1].Name == "foo" || list[0].Name == "foo" && list[1].Name == "bar") {
|
||||
t.Fatalf("expect registry.List return %s; got %s", []string{"bar", "foo"}, list)
|
||||
}
|
||||
|
||||
|
|
@ -57,7 +68,7 @@ func TestRegistry(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal("expect nil")
|
||||
}
|
||||
if driver == nil {
|
||||
if driver.Name != "foo" {
|
||||
t.Fatal("expect registry.Driver(foo) returns registered driver")
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue