Refactor config.Config to prepare for multinode (#5889)

* Refactor config.Config to prepare for multinode

* merge conflict
pull/5901/head
Sharif Elgamal 2019-11-11 17:52:15 -08:00 committed by GitHub
parent fb5430fd97
commit c03aee8322
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 185 additions and 190 deletions

View File

@ -82,7 +82,7 @@ var ProfileCmd = &cobra.Command{
out.ErrT(out.Sad, `Error loading profile config: {{.error}}`, out.V{"error": err}) out.ErrT(out.Sad, `Error loading profile config: {{.error}}`, out.V{"error": err})
} }
if err == nil { if err == nil {
if cc.MachineConfig.KeepContext { if cc.KeepContext {
out.SuccessT("Skipped switching kubectl context for {{.profile_name}} because --keep-context was set.", out.V{"profile_name": profile}) out.SuccessT("Skipped switching kubectl context for {{.profile_name}} because --keep-context was set.", out.V{"profile_name": profile})
out.SuccessT("To connect to this cluster, use: kubectl --context={{.profile_name}}", out.V{"profile_name": profile}) out.SuccessT("To connect to this cluster, use: kubectl --context={{.profile_name}}", out.V{"profile_name": profile})
} else { } else {

View File

@ -68,7 +68,7 @@ var printProfilesTable = func() {
exit.UsageT("No minikube profile was found. You can create one using `minikube start`.") exit.UsageT("No minikube profile was found. You can create one using `minikube start`.")
} }
for _, p := range validProfiles { for _, p := range validProfiles {
validData = append(validData, []string{p.Name, p.Config.MachineConfig.VMDriver, p.Config.KubernetesConfig.NodeIP, strconv.Itoa(p.Config.KubernetesConfig.NodePort), p.Config.KubernetesConfig.KubernetesVersion}) validData = append(validData, []string{p.Name, p.Config[0].VMDriver, p.Config[0].KubernetesConfig.NodeIP, strconv.Itoa(p.Config[0].KubernetesConfig.NodePort), p.Config[0].KubernetesConfig.KubernetesVersion})
} }
table.AppendBulk(validData) table.AppendBulk(validData)

View File

@ -142,7 +142,7 @@ func EnableOrDisableAddon(name string, val string) error {
exit.WithCodeT(exit.Data, "Unable to load config: {{.error}}", out.V{"error": err}) exit.WithCodeT(exit.Data, "Unable to load config: {{.error}}", out.V{"error": err})
} }
host, err := cluster.CheckIfHostExistsAndLoad(api, cfg.MachineConfig.Name) host, err := cluster.CheckIfHostExistsAndLoad(api, cfg.Name)
if err != nil { if err != nil {
return errors.Wrap(err, "getting host") return errors.Wrap(err, "getting host")
} }

View File

@ -74,10 +74,10 @@ var dashboardCmd = &cobra.Command{
exit.WithError("Error getting client", err) exit.WithError("Error getting client", err)
} }
if _, err = api.Load(cc.MachineConfig.Name); err != nil { if _, err = api.Load(cc.Name); err != nil {
switch err := errors.Cause(err).(type) { switch err := errors.Cause(err).(type) {
case mcnerror.ErrHostDoesNotExist: case mcnerror.ErrHostDoesNotExist:
exit.WithCodeT(exit.Unavailable, "{{.name}} cluster does not exist", out.V{"name": cc.MachineConfig.Name}) exit.WithCodeT(exit.Unavailable, "{{.name}} cluster does not exist", out.V{"name": cc.Name})
default: default:
exit.WithError("Error getting cluster", err) exit.WithError("Error getting cluster", err)
} }
@ -119,7 +119,7 @@ var dashboardCmd = &cobra.Command{
} }
out.ErrT(out.Launch, "Launching proxy ...") out.ErrT(out.Launch, "Launching proxy ...")
p, hostPort, err := kubectlProxy(kubectl, cc.MachineConfig.Name) p, hostPort, err := kubectlProxy(kubectl, cc.Name)
if err != nil { if err != nil {
exit.WithError("kubectl proxy", err) exit.WithError("kubectl proxy", err)
} }

View File

@ -194,7 +194,7 @@ func deleteProfile(profile *pkg_config.Profile) error {
return DeletionError{Err: delErr, Errtype: MissingProfile} return DeletionError{Err: delErr, Errtype: MissingProfile}
} }
if err == nil && driver.BareMetal(cc.MachineConfig.VMDriver) { if err == nil && driver.BareMetal(cc.VMDriver) {
if err := uninstallKubernetes(api, cc.KubernetesConfig, viper.GetString(cmdcfg.Bootstrapper)); err != nil { if err := uninstallKubernetes(api, cc.KubernetesConfig, viper.GetString(cmdcfg.Bootstrapper)); err != nil {
deletionError, ok := err.(DeletionError) deletionError, ok := err.(DeletionError)
if ok { if ok {

View File

@ -344,14 +344,14 @@ var dockerEnvCmd = &cobra.Command{
if err != nil { if err != nil {
exit.WithError("Error getting config", err) exit.WithError("Error getting config", err)
} }
host, err := cluster.CheckIfHostExistsAndLoad(api, cc.MachineConfig.Name) host, err := cluster.CheckIfHostExistsAndLoad(api, cc.Name)
if err != nil { if err != nil {
exit.WithError("Error getting host", err) exit.WithError("Error getting host", err)
} }
if host.Driver.DriverName() == driver.None { if host.Driver.DriverName() == driver.None {
exit.UsageT(`'none' driver does not support 'minikube docker-env' command`) exit.UsageT(`'none' driver does not support 'minikube docker-env' command`)
} }
hostSt, err := cluster.GetHostStatus(api, cc.MachineConfig.Name) hostSt, err := cluster.GetHostStatus(api, cc.Name)
if err != nil { if err != nil {
exit.WithError("Error getting host status", err) exit.WithError("Error getting host status", err)
} }

View File

@ -42,11 +42,11 @@ var ipCmd = &cobra.Command{
if err != nil { if err != nil {
exit.WithError("Error getting config", err) exit.WithError("Error getting config", err)
} }
host, err := api.Load(cc.MachineConfig.Name) host, err := api.Load(cc.Name)
if err != nil { if err != nil {
switch err := errors.Cause(err).(type) { switch err := errors.Cause(err).(type) {
case mcnerror.ErrHostDoesNotExist: case mcnerror.ErrHostDoesNotExist:
exit.WithCodeT(exit.NoInput, `"{{.profile_name}}" host does not exist, unable to show an IP`, out.V{"profile_name": cc.MachineConfig.Name}) exit.WithCodeT(exit.NoInput, `"{{.profile_name}}" host does not exist, unable to show an IP`, out.V{"profile_name": cc.Name})
default: default:
exit.WithError("Error getting host", err) exit.WithError("Error getting host", err)
} }

View File

@ -58,7 +58,7 @@ var logsCmd = &cobra.Command{
} }
defer api.Close() defer api.Close()
h, err := api.Load(cfg.MachineConfig.Name) h, err := api.Load(cfg.Name)
if err != nil { if err != nil {
exit.WithError("api load", err) exit.WithError("api load", err)
} }

View File

@ -106,7 +106,7 @@ var mountCmd = &cobra.Command{
if err != nil { if err != nil {
exit.WithError("Error getting config", err) exit.WithError("Error getting config", err)
} }
host, err := api.Load(cc.MachineConfig.Name) host, err := api.Load(cc.Name)
if err != nil { if err != nil {
exit.WithError("Error loading api", err) exit.WithError("Error loading api", err)

View File

@ -36,6 +36,6 @@ var sshKeyCmd = &cobra.Command{
if err != nil { if err != nil {
exit.WithError("Getting machine config failed", err) exit.WithError("Getting machine config failed", err)
} }
out.Ln(filepath.Join(localpath.MiniPath(), "machines", cc.MachineConfig.Name, "id_rsa")) out.Ln(filepath.Join(localpath.MiniPath(), "machines", cc.Name, "id_rsa"))
}, },
} }

View File

@ -46,7 +46,7 @@ var sshCmd = &cobra.Command{
if err != nil { if err != nil {
exit.WithError("Error getting config", err) exit.WithError("Error getting config", err)
} }
host, err := cluster.CheckIfHostExistsAndLoad(api, cc.MachineConfig.Name) host, err := cluster.CheckIfHostExistsAndLoad(api, cc.Name)
if err != nil { if err != nil {
exit.WithError("Error getting host", err) exit.WithError("Error getting host", err)
} }

View File

@ -311,7 +311,7 @@ func runStart(cmd *cobra.Command, args []string) {
} }
if !driver.BareMetal(driverName) { if !driver.BareMetal(driverName) {
if err := cluster.CacheISO(config.MachineConfig); err != nil { if err := cluster.CacheISO(config); err != nil {
exit.WithError("Failed to cache ISO", err) exit.WithError("Failed to cache ISO", err)
} }
} }
@ -342,7 +342,7 @@ func runStart(cmd *cobra.Command, args []string) {
waitCacheImages(&cacheGroup) waitCacheImages(&cacheGroup)
// Must be written before bootstrap, otherwise health checks may flake due to stale IP // Must be written before bootstrap, otherwise health checks may flake due to stale IP
kubeconfig, err := setupKubeconfig(host, &config) kubeconfig, err := setupKubeconfig(host, &config, config.Name)
if err != nil { if err != nil {
exit.WithError("Failed to setup kubeconfig", err) exit.WithError("Failed to setup kubeconfig", err)
} }
@ -366,7 +366,7 @@ func runStart(cmd *cobra.Command, args []string) {
prepareNone() prepareNone()
} }
waitCluster(bs, config) waitCluster(bs, config)
if err := showKubectlInfo(kubeconfig, k8sVersion, config.MachineConfig.Name); err != nil { if err := showKubectlInfo(kubeconfig, k8sVersion, config.Name); err != nil {
glog.Errorf("kubectl info: %v", err) glog.Errorf("kubectl info: %v", err)
} }
} }
@ -389,7 +389,7 @@ func enableAddons() {
} }
} }
func waitCluster(bs bootstrapper.Bootstrapper, config cfg.Config) { func waitCluster(bs bootstrapper.Bootstrapper, config cfg.MachineConfig) {
var podsToWaitFor []string var podsToWaitFor []string
if !viper.GetBool(waitUntilHealthy) { if !viper.GetBool(waitUntilHealthy) {
@ -427,7 +427,7 @@ func displayEnviron(env []string) {
} }
} }
func setupKubeconfig(h *host.Host, c *cfg.Config) (*kubeconfig.Settings, error) { func setupKubeconfig(h *host.Host, c *cfg.MachineConfig, clusterName string) (*kubeconfig.Settings, error) {
addr, err := h.Driver.GetURL() addr, err := h.Driver.GetURL()
if err != nil { if err != nil {
exit.WithError("Failed to get driver URL", err) exit.WithError("Failed to get driver URL", err)
@ -439,7 +439,7 @@ func setupKubeconfig(h *host.Host, c *cfg.Config) (*kubeconfig.Settings, error)
} }
kcs := &kubeconfig.Settings{ kcs := &kubeconfig.Settings{
ClusterName: c.MachineConfig.Name, ClusterName: clusterName,
ClusterServerAddress: addr, ClusterServerAddress: addr,
ClientCertificate: localpath.MakeMiniPath("client.crt"), ClientCertificate: localpath.MakeMiniPath("client.crt"),
ClientKey: localpath.MakeMiniPath("client.key"), ClientKey: localpath.MakeMiniPath("client.key"),
@ -472,12 +472,12 @@ func handleDownloadOnly(cacheGroup *errgroup.Group, k8sVersion string) {
} }
func startMachine(config *cfg.Config) (runner command.Runner, preExists bool, machineAPI libmachine.API, host *host.Host) { func startMachine(config *cfg.MachineConfig) (runner command.Runner, preExists bool, machineAPI libmachine.API, host *host.Host) {
m, err := machine.NewAPIClient() m, err := machine.NewAPIClient()
if err != nil { if err != nil {
exit.WithError("Failed to get machine client", err) exit.WithError("Failed to get machine client", err)
} }
host, preExists = startHost(m, config.MachineConfig) host, preExists = startHost(m, *config)
runner, err = machine.CommandRunner(host) runner, err = machine.CommandRunner(host)
if err != nil { if err != nil {
exit.WithError("Failed to get command runner", err) exit.WithError("Failed to get command runner", err)
@ -553,8 +553,7 @@ func showKubectlInfo(kcs *kubeconfig.Settings, k8sVersion string, machineName st
return nil return nil
} }
// selectDriver returns which driver to choose based on flags, existing configs, and hypervisor detection func selectDriver(existing *cfg.MachineConfig) string {
func selectDriver(existing *cfg.Config) string {
name := viper.GetString("vm-driver") name := viper.GetString("vm-driver")
glog.Infof("selectDriver: flag=%q, old=%v", name, existing) glog.Infof("selectDriver: flag=%q, old=%v", name, existing)
options := driver.Choices() options := driver.Choices()
@ -567,8 +566,8 @@ func selectDriver(existing *cfg.Config) string {
// By default, the driver is whatever we used last time // By default, the driver is whatever we used last time
if existing != nil { if existing != nil {
pick, alts := driver.Choose(existing.MachineConfig.VMDriver, options) pick, alts := driver.Choose(existing.VMDriver, options)
out.T(out.Sparkle, `Selecting '{{.driver}}' driver from existing profile (alternates: {{.alternates}})`, out.V{"driver": existing.MachineConfig.VMDriver, "alternates": alts}) out.T(out.Sparkle, `Selecting '{{.driver}}' driver from existing profile (alternates: {{.alternates}})`, out.V{"driver": existing.VMDriver, "alternates": alts})
return pick.Name return pick.Name
} }
@ -585,7 +584,7 @@ func selectDriver(existing *cfg.Config) string {
} }
// validateDriver validates that the selected driver appears sane, exits if not // validateDriver validates that the selected driver appears sane, exits if not
func validateDriver(name string, existing *cfg.Config) { func validateDriver(name string, existing *cfg.MachineConfig) {
glog.Infof("validating driver %q against %+v", name, existing) glog.Infof("validating driver %q against %+v", name, existing)
if !driver.Supported(name) { if !driver.Supported(name) {
exit.WithCodeT(exit.Unavailable, "The driver '{{.driver}}' is not supported on {{.os}}", out.V{"driver": name, "os": runtime.GOOS}) exit.WithCodeT(exit.Unavailable, "The driver '{{.driver}}' is not supported on {{.os}}", out.V{"driver": name, "os": runtime.GOOS})
@ -605,7 +604,7 @@ func validateDriver(name string, existing *cfg.Config) {
out.ErrLn("") out.ErrLn("")
if !st.Installed && !viper.GetBool(force) { if !st.Installed && !viper.GetBool(force) {
if existing != nil && name == existing.MachineConfig.VMDriver { if existing != nil && name == existing.VMDriver {
exit.WithCodeT(exit.Unavailable, "{{.driver}} does not appear to be installed, but is specified by an existing profile. Please run 'minikube delete' or install {{.driver}}", out.V{"driver": name}) exit.WithCodeT(exit.Unavailable, "{{.driver}} does not appear to be installed, but is specified by an existing profile. Please run 'minikube delete' or install {{.driver}}", out.V{"driver": name})
} }
exit.WithCodeT(exit.Unavailable, "{{.driver}} does not appear to be installed", out.V{"driver": name}) exit.WithCodeT(exit.Unavailable, "{{.driver}} does not appear to be installed", out.V{"driver": name})
@ -845,10 +844,10 @@ func waitCacheImages(g *errgroup.Group) {
} }
// generateCfgFromFlags generates cfg.Config based on flags and supplied arguments // generateCfgFromFlags generates cfg.Config based on flags and supplied arguments
func generateCfgFromFlags(cmd *cobra.Command, k8sVersion string, drvName string) (cfg.Config, error) { func generateCfgFromFlags(cmd *cobra.Command, k8sVersion string, drvName string) (cfg.MachineConfig, error) {
r, err := cruntime.New(cruntime.Config{Type: viper.GetString(containerRuntime)}) r, err := cruntime.New(cruntime.Config{Type: viper.GetString(containerRuntime)})
if err != nil { if err != nil {
return cfg.Config{}, err return cfg.MachineConfig{}, err
} }
// Pick good default values for --network-plugin and --enable-default-cni based on runtime. // Pick good default values for --network-plugin and --enable-default-cni based on runtime.
@ -889,38 +888,36 @@ func generateCfgFromFlags(cmd *cobra.Command, k8sVersion string, drvName string)
out.T(out.SuccessType, "Using image repository {{.name}}", out.V{"name": repository}) out.T(out.SuccessType, "Using image repository {{.name}}", out.V{"name": repository})
} }
cfg := cfg.Config{ cfg := cfg.MachineConfig{
MachineConfig: cfg.MachineConfig{ Name: viper.GetString(cfg.MachineProfile),
Name: viper.GetString(cfg.MachineProfile), KeepContext: viper.GetBool(keepContext),
KeepContext: viper.GetBool(keepContext), EmbedCerts: viper.GetBool(embedCerts),
EmbedCerts: viper.GetBool(embedCerts), MinikubeISO: viper.GetString(isoURL),
MinikubeISO: viper.GetString(isoURL), Memory: pkgutil.CalculateSizeInMB(viper.GetString(memory)),
Memory: pkgutil.CalculateSizeInMB(viper.GetString(memory)), CPUs: viper.GetInt(cpus),
CPUs: viper.GetInt(cpus), DiskSize: pkgutil.CalculateSizeInMB(viper.GetString(humanReadableDiskSize)),
DiskSize: pkgutil.CalculateSizeInMB(viper.GetString(humanReadableDiskSize)), VMDriver: drvName,
VMDriver: drvName, ContainerRuntime: viper.GetString(containerRuntime),
ContainerRuntime: viper.GetString(containerRuntime), HyperkitVpnKitSock: viper.GetString(vpnkitSock),
HyperkitVpnKitSock: viper.GetString(vpnkitSock), HyperkitVSockPorts: viper.GetStringSlice(vsockPorts),
HyperkitVSockPorts: viper.GetStringSlice(vsockPorts), NFSShare: viper.GetStringSlice(nfsShare),
NFSShare: viper.GetStringSlice(nfsShare), NFSSharesRoot: viper.GetString(nfsSharesRoot),
NFSSharesRoot: viper.GetString(nfsSharesRoot), DockerEnv: dockerEnv,
DockerEnv: dockerEnv, DockerOpt: dockerOpt,
DockerOpt: dockerOpt, InsecureRegistry: insecureRegistry,
InsecureRegistry: insecureRegistry, RegistryMirror: registryMirror,
RegistryMirror: registryMirror, HostOnlyCIDR: viper.GetString(hostOnlyCIDR),
HostOnlyCIDR: viper.GetString(hostOnlyCIDR), HypervVirtualSwitch: viper.GetString(hypervVirtualSwitch),
HypervVirtualSwitch: viper.GetString(hypervVirtualSwitch), KVMNetwork: viper.GetString(kvmNetwork),
KVMNetwork: viper.GetString(kvmNetwork), KVMQemuURI: viper.GetString(kvmQemuURI),
KVMQemuURI: viper.GetString(kvmQemuURI), KVMGPU: viper.GetBool(kvmGPU),
KVMGPU: viper.GetBool(kvmGPU), KVMHidden: viper.GetBool(kvmHidden),
KVMHidden: viper.GetBool(kvmHidden), Downloader: pkgutil.DefaultDownloader{},
Downloader: pkgutil.DefaultDownloader{}, DisableDriverMounts: viper.GetBool(disableDriverMounts),
DisableDriverMounts: viper.GetBool(disableDriverMounts), UUID: viper.GetString(uuid),
UUID: viper.GetString(uuid), NoVTXCheck: viper.GetBool(noVTXCheck),
NoVTXCheck: viper.GetBool(noVTXCheck), DNSProxy: viper.GetBool(dnsProxy),
DNSProxy: viper.GetBool(dnsProxy), HostDNSResolver: viper.GetBool(hostDNSResolver),
HostDNSResolver: viper.GetBool(hostDNSResolver),
},
KubernetesConfig: cfg.KubernetesConfig{ KubernetesConfig: cfg.KubernetesConfig{
KubernetesVersion: k8sVersion, KubernetesVersion: k8sVersion,
NodePort: viper.GetInt(apiServerPort), NodePort: viper.GetInt(apiServerPort),
@ -1112,7 +1109,7 @@ func tryRegistry(r command.Runner) {
} }
// getKubernetesVersion ensures that the requested version is reasonable // getKubernetesVersion ensures that the requested version is reasonable
func getKubernetesVersion(old *cfg.Config) (string, bool) { func getKubernetesVersion(old *cfg.MachineConfig) (string, bool) {
rawVersion := viper.GetString(kubernetesVersion) rawVersion := viper.GetString(kubernetesVersion)
isUpgrade := false isUpgrade := false
if rawVersion == "" { if rawVersion == "" {
@ -1151,8 +1148,8 @@ func getKubernetesVersion(old *cfg.Config) (string, bool) {
if nvs.LT(ovs) { if nvs.LT(ovs) {
nv = version.VersionPrefix + ovs.String() nv = version.VersionPrefix + ovs.String()
profileArg := "" profileArg := ""
if old.MachineConfig.Name != constants.DefaultMachineName { if old.Name != constants.DefaultMachineName {
profileArg = fmt.Sprintf("-p %s", old.MachineConfig.Name) profileArg = fmt.Sprintf("-p %s", old.Name)
} }
exit.WithCodeT(exit.Config, `Error: You have selected Kubernetes v{{.new}}, but the existing cluster for your profile is running Kubernetes v{{.old}}. Non-destructive downgrades are not supported, but you can proceed by performing one of the following options: exit.WithCodeT(exit.Config, `Error: You have selected Kubernetes v{{.new}}, but the existing cluster for your profile is running Kubernetes v{{.old}}. Non-destructive downgrades are not supported, but you can proceed by performing one of the following options:
@ -1260,6 +1257,6 @@ func configureMounts() {
} }
// saveConfig saves profile cluster configuration in $MINIKUBE_HOME/profiles/<profilename>/config.json // saveConfig saves profile cluster configuration in $MINIKUBE_HOME/profiles/<profilename>/config.json
func saveConfig(clusterCfg *cfg.Config) error { func saveConfig(clusterCfg *cfg.MachineConfig) error {
return cfg.CreateProfile(viper.GetString(cfg.MachineProfile), clusterCfg) return cfg.CreateProfile(viper.GetString(cfg.MachineProfile), clusterCfg)
} }

View File

@ -71,7 +71,7 @@ func TestGenerateCfgFromFlagsHTTPProxyHandling(t *testing.T) {
t.Fatalf("Got unexpected error %v during config generation", err) t.Fatalf("Got unexpected error %v during config generation", err)
} }
// ignored proxy should not be in config // ignored proxy should not be in config
for _, v := range config.MachineConfig.DockerEnv { for _, v := range config.DockerEnv {
if v == test.proxy && test.proxyIgnored { if v == test.proxy && test.proxyIgnored {
t.Fatalf("Value %v not expected in dockerEnv but occurred", v) t.Fatalf("Value %v not expected in dockerEnv but occurred", v)
} }

View File

@ -80,7 +80,7 @@ var tunnelCmd = &cobra.Command{
if err != nil { if err != nil {
exit.WithError("Error getting config", err) exit.WithError("Error getting config", err)
} }
done, err := manager.StartTunnel(ctx, cc.MachineConfig.Name, api, config.DefaultLoader, clientset.CoreV1()) done, err := manager.StartTunnel(ctx, cc.Name, api, config.DefaultLoader, clientset.CoreV1())
if err != nil { if err != nil {
exit.WithError("error starting tunnel", err) exit.WithError("error starting tunnel", err)
} }

View File

@ -124,14 +124,14 @@ func encode(w io.Writer, m MinikubeConfig) error {
} }
// Load loads the kubernetes and machine config for the current machine // Load loads the kubernetes and machine config for the current machine
func Load() (*Config, error) { func Load() (*MachineConfig, error) {
machine := viper.GetString(MachineProfile) machine := viper.GetString(MachineProfile)
return DefaultLoader.LoadConfigFromFile(machine) return DefaultLoader.LoadConfigFromFile(machine)
} }
// Loader loads the kubernetes and machine config based on the machine profile name // Loader loads the kubernetes and machine config based on the machine profile name
type Loader interface { type Loader interface {
LoadConfigFromFile(profile string, miniHome ...string) (*Config, error) LoadConfigFromFile(profile string, miniHome ...string) (*MachineConfig, error)
} }
type simpleConfigLoader struct{} type simpleConfigLoader struct{}
@ -139,8 +139,8 @@ type simpleConfigLoader struct{}
// DefaultLoader is the default config loader // DefaultLoader is the default config loader
var DefaultLoader Loader = &simpleConfigLoader{} var DefaultLoader Loader = &simpleConfigLoader{}
func (c *simpleConfigLoader) LoadConfigFromFile(profileName string, miniHome ...string) (*Config, error) { func (c *simpleConfigLoader) LoadConfigFromFile(profileName string, miniHome ...string) (*MachineConfig, error) {
var cc Config var cc MachineConfig
// Move to profile package // Move to profile package
path := profileFilePath(profileName, miniHome...) path := profileFilePath(profileName, miniHome...)

View File

@ -35,10 +35,17 @@ func (p *Profile) IsValid() bool {
if p.Config == nil { if p.Config == nil {
return false return false
} }
if p.Config.MachineConfig.VMDriver == "" { if len(p.Config) == 0 {
return false return false
} }
if p.Config.KubernetesConfig.KubernetesVersion == "" { // This will become a loop for multinode
if p.Config[0] == nil {
return false
}
if p.Config[0].VMDriver == "" {
return false
}
if p.Config[0].KubernetesConfig.KubernetesVersion == "" {
return false return false
} }
return true return true
@ -68,12 +75,12 @@ func ProfileExists(name string, miniHome ...string) bool {
// CreateEmptyProfile creates an empty profile stores in $MINIKUBE_HOME/profiles/<profilename>/config.json // CreateEmptyProfile creates an empty profile stores in $MINIKUBE_HOME/profiles/<profilename>/config.json
func CreateEmptyProfile(name string, miniHome ...string) error { func CreateEmptyProfile(name string, miniHome ...string) error {
cfg := &Config{} cfg := &MachineConfig{}
return CreateProfile(name, cfg, miniHome...) return CreateProfile(name, cfg, miniHome...)
} }
// CreateProfile creates an profile out of the cfg and stores in $MINIKUBE_HOME/profiles/<profilename>/config.json // CreateProfile creates an profile out of the cfg and stores in $MINIKUBE_HOME/profiles/<profilename>/config.json
func CreateProfile(name string, cfg *Config, miniHome ...string) error { func CreateProfile(name string, cfg *MachineConfig, miniHome ...string) error {
data, err := json.MarshalIndent(cfg, "", " ") data, err := json.MarshalIndent(cfg, "", " ")
if err != nil { if err != nil {
return err return err
@ -153,7 +160,7 @@ func LoadProfile(name string, miniHome ...string) (*Profile, error) {
cfg, err := DefaultLoader.LoadConfigFromFile(name, miniHome...) cfg, err := DefaultLoader.LoadConfigFromFile(name, miniHome...)
p := &Profile{ p := &Profile{
Name: name, Name: name,
Config: cfg, Config: []*MachineConfig{cfg},
} }
return p, err return p, err
} }

View File

@ -54,8 +54,8 @@ func TestListProfiles(t *testing.T) {
if val[tt.index].Name != tt.expectName { if val[tt.index].Name != tt.expectName {
t.Errorf("expected %s got %v", tt.expectName, val[tt.index].Name) t.Errorf("expected %s got %v", tt.expectName, val[tt.index].Name)
} }
if val[tt.index].Config.MachineConfig.VMDriver != tt.vmDriver { if val[tt.index].Config[0].VMDriver != tt.vmDriver {
t.Errorf("expected %s got %v", tt.vmDriver, val[tt.index].Config.MachineConfig.VMDriver) t.Errorf("expected %s got %v", tt.vmDriver, val[tt.index].Config[0].VMDriver)
} }
} }
@ -164,15 +164,15 @@ func TestCreateProfile(t *testing.T) {
var testCases = []struct { var testCases = []struct {
name string name string
cfg *Config cfg *MachineConfig
expectErr bool expectErr bool
}{ }{
{"p_empty_config", &Config{}, false}, {"p_empty_config", &MachineConfig{}, false},
{"p_partial_config", &Config{KubernetesConfig: KubernetesConfig{ {"p_partial_config", &MachineConfig{KubernetesConfig: KubernetesConfig{
ShouldLoadCachedImages: false}}, false},
{"p_partial_config2", &Config{MachineConfig: MachineConfig{
KeepContext: false}, KubernetesConfig: KubernetesConfig{
ShouldLoadCachedImages: false}}, false}, ShouldLoadCachedImages: false}}, false},
{"p_partial_config2", &MachineConfig{
KeepContext: false, KubernetesConfig: KubernetesConfig{
ShouldLoadCachedImages: false}}, false},
} }
for _, tc := range testCases { for _, tc := range testCases {
n := tc.name // capturing loop variable n := tc.name // capturing loop variable

View File

@ -1,33 +1,32 @@
{ {
"MachineConfig": { "Name": "p1",
"KeepContext": false, "KeepContext": false,
"MinikubeISO": "https://storage.googleapis.com/minikube/iso/minikube-v1.2.0.iso", "MinikubeISO": "https://storage.googleapis.com/minikube/iso/minikube-v1.2.0.iso",
"Memory": 2000, "Memory": 2000,
"CPUs": 2, "CPUs": 2,
"DiskSize": 20000, "DiskSize": 20000,
"VMDriver": "hyperkit", "VMDriver": "hyperkit",
"ContainerRuntime": "docker", "ContainerRuntime": "docker",
"HyperkitVpnKitSock": "", "HyperkitVpnKitSock": "",
"HyperkitVSockPorts": [], "HyperkitVSockPorts": [],
"XhyveDiskDriver": "ahci-hd", "XhyveDiskDriver": "ahci-hd",
"DockerEnv": null, "DockerEnv": null,
"InsecureRegistry": null, "InsecureRegistry": null,
"RegistryMirror": null, "RegistryMirror": null,
"HostOnlyCIDR": "192.168.99.1/24", "HostOnlyCIDR": "192.168.99.1/24",
"HypervVirtualSwitch": "", "HypervVirtualSwitch": "",
"KVMNetwork": "default", "KVMNetwork": "default",
"KVMQemuURI": "qemu:///system", "KVMQemuURI": "qemu:///system",
"KVMGPU": false, "KVMGPU": false,
"KVMHidden": false, "KVMHidden": false,
"DockerOpt": null, "DockerOpt": null,
"DisableDriverMounts": false, "DisableDriverMounts": false,
"NFSShare": [], "NFSShare": [],
"NFSSharesRoot": "/nfsshares", "NFSSharesRoot": "/nfsshares",
"UUID": "", "UUID": "",
"NoVTXCheck": false, "NoVTXCheck": false,
"DNSProxy": false, "DNSProxy": false,
"HostDNSResolver": true "HostDNSResolver": true,
},
"KubernetesConfig": { "KubernetesConfig": {
"KubernetesVersion": "v1.15.0", "KubernetesVersion": "v1.15.0",
"NodeIP": "192.168.64.75", "NodeIP": "192.168.64.75",

View File

@ -1,32 +1,31 @@
{ {
"MachineConfig": { "Name": "p2",
"KeepContext": false, "KeepContext": false,
"MinikubeISO": "https://storage.googleapis.com/minikube/iso/minikube-v1.2.0.iso", "MinikubeISO": "https://storage.googleapis.com/minikube/iso/minikube-v1.2.0.iso",
"Memory": 2000, "Memory": 2000,
"CPUs": 2, "CPUs": 2,
"DiskSize": 20000, "DiskSize": 20000,
"VMDriver": "virtualbox", "VMDriver": "virtualbox",
"ContainerRuntime": "docker", "ContainerRuntime": "docker",
"HyperkitVpnKitSock": "", "HyperkitVpnKitSock": "",
"HyperkitVSockPorts": [], "HyperkitVSockPorts": [],
"DockerEnv": null, "DockerEnv": null,
"InsecureRegistry": null, "InsecureRegistry": null,
"RegistryMirror": null, "RegistryMirror": null,
"HostOnlyCIDR": "192.168.99.1/24", "HostOnlyCIDR": "192.168.99.1/24",
"HypervVirtualSwitch": "", "HypervVirtualSwitch": "",
"KVMNetwork": "default", "KVMNetwork": "default",
"KVMQemuURI": "qemu:///system", "KVMQemuURI": "qemu:///system",
"KVMGPU": false, "KVMGPU": false,
"KVMHidden": false, "KVMHidden": false,
"DockerOpt": null, "DockerOpt": null,
"DisableDriverMounts": false, "DisableDriverMounts": false,
"NFSShare": [], "NFSShare": [],
"NFSSharesRoot": "/nfsshares", "NFSSharesRoot": "/nfsshares",
"UUID": "", "UUID": "",
"NoVTXCheck": false, "NoVTXCheck": false,
"DNSProxy": false, "DNSProxy": false,
"HostDNSResolver": true "HostDNSResolver": true,
},
"KubernetesConfig": { "KubernetesConfig": {
"KubernetesVersion": "v1.15.0", "KubernetesVersion": "v1.15.0",
"NodeIP": "192.168.99.136", "NodeIP": "192.168.99.136",

View File

@ -1,32 +1,30 @@
{ {
"MachineConfig": { "KeepContext": false,
"KeepContext": false, "MinikubeISO": "https://storage.googleapis.com/minikube/iso/minikube-v1.2.0.iso",
"MinikubeISO": "https://storage.googleapis.com/minikube/iso/minikube-v1.2.0.iso", "Memory": 2000,
"Memory": 2000, "CPUs": 2,
"CPUs": 2, "DiskSize": 20000,
"DiskSize": 20000, "ContainerRuntime": "docker",
"ContainerRuntime": "docker", "HyperkitVpnKitSock": "",
"HyperkitVpnKitSock": "", "HyperkitVSockPorts": [],
"HyperkitVSockPorts": [], "XhyveDiskDriver": "ahci-hd",
"XhyveDiskDriver": "ahci-hd", "DockerEnv": null,
"DockerEnv": null, "InsecureRegistry": null,
"InsecureRegistry": null, "RegistryMirror": null,
"RegistryMirror": null, "HostOnlyCIDR": "192.168.99.1/24",
"HostOnlyCIDR": "192.168.99.1/24", "HypervVirtualSwitch": "",
"HypervVirtualSwitch": "", "KVMNetwork": "default",
"KVMNetwork": "default", "KVMQemuURI": "qemu:///system",
"KVMQemuURI": "qemu:///system", "KVMGPU": false,
"KVMGPU": false, "KVMHidden": false,
"KVMHidden": false, "DockerOpt": null,
"DockerOpt": null, "DisableDriverMounts": false,
"DisableDriverMounts": false, "NFSShare": [],
"NFSShare": [], "NFSSharesRoot": "/nfsshares",
"NFSSharesRoot": "/nfsshares", "UUID": "",
"UUID": "", "NoVTXCheck": false,
"NoVTXCheck": false, "DNSProxy": false,
"DNSProxy": false, "HostDNSResolver": true,
"HostDNSResolver": true
},
"KubernetesConfig": { "KubernetesConfig": {
"NodePort": 8443, "NodePort": 8443,
"NodeName": "minikube", "NodeName": "minikube",

View File

@ -26,13 +26,7 @@ import (
// Profile represents a minikube profile // Profile represents a minikube profile
type Profile struct { type Profile struct {
Name string Name string
Config *Config Config []*MachineConfig
}
// Config contains machine and k8s config
type Config struct {
MachineConfig MachineConfig
KubernetesConfig KubernetesConfig
} }
// MachineConfig contains the parameters used to start a cluster. // MachineConfig contains the parameters used to start a cluster.
@ -66,6 +60,7 @@ type MachineConfig struct {
NoVTXCheck bool // Only used by virtualbox NoVTXCheck bool // Only used by virtualbox
DNSProxy bool // Only used by virtualbox DNSProxy bool // Only used by virtualbox
HostDNSResolver bool // Only used by virtualbox HostDNSResolver bool // Only used by virtualbox
KubernetesConfig KubernetesConfig
} }
// KubernetesConfig contains the parameters used to configure the VM Kubernetes. // KubernetesConfig contains the parameters used to configure the VM Kubernetes.

View File

@ -135,7 +135,7 @@ func CacheAndLoadImages(images []string) error {
if err != nil { if err != nil {
return err return err
} }
h, err := api.Load(cc.MachineConfig.Name) h, err := api.Load(cc.Name)
if err != nil { if err != nil {
return err return err
} }

View File

@ -64,7 +64,7 @@ func (m *clusterInspector) getStateAndRoute() (HostState, *Route, error) {
if err != nil { if err != nil {
return hostState, nil, err return hostState, nil, err
} }
var c *config.Config var c *config.MachineConfig
c, err = m.configLoader.LoadConfigFromFile(m.machineName) c, err = m.configLoader.LoadConfigFromFile(m.machineName)
if err != nil { if err != nil {
err = errors.Wrapf(err, "error loading config for %s", m.machineName) err = errors.Wrapf(err, "error loading config for %s", m.machineName)
@ -80,7 +80,7 @@ func (m *clusterInspector) getStateAndRoute() (HostState, *Route, error) {
return hostState, route, nil return hostState, route, nil
} }
func getRoute(host *host.Host, clusterConfig config.Config) (*Route, error) { func getRoute(host *host.Host, clusterConfig config.MachineConfig) (*Route, error) {
hostDriverIP, err := host.Driver.GetIP() hostDriverIP, err := host.Driver.GetIP()
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "error getting host IP for %s", host.Name) return nil, errors.Wrapf(err, "error getting host IP for %s", host.Name)

View File

@ -62,7 +62,7 @@ func TestMinikubeCheckReturnsHostInformation(t *testing.T) {
} }
configLoader := &stubConfigLoader{ configLoader := &stubConfigLoader{
c: &config.Config{ c: &config.MachineConfig{
KubernetesConfig: config.KubernetesConfig{ KubernetesConfig: config.KubernetesConfig{
ServiceCIDR: "96.0.0.0/12", ServiceCIDR: "96.0.0.0/12",
}, },
@ -100,7 +100,7 @@ func TestMinikubeCheckReturnsHostInformation(t *testing.T) {
} }
func TestUnparseableCIDR(t *testing.T) { func TestUnparseableCIDR(t *testing.T) {
cfg := config.Config{ cfg := config.MachineConfig{
KubernetesConfig: config.KubernetesConfig{ KubernetesConfig: config.KubernetesConfig{
ServiceCIDR: "bad.cidr.0.0/12", ServiceCIDR: "bad.cidr.0.0/12",
}} }}
@ -120,7 +120,7 @@ func TestUnparseableCIDR(t *testing.T) {
func TestRouteIPDetection(t *testing.T) { func TestRouteIPDetection(t *testing.T) {
expectedTargetCIDR := "10.96.0.0/12" expectedTargetCIDR := "10.96.0.0/12"
cfg := config.Config{ cfg := config.MachineConfig{
KubernetesConfig: config.KubernetesConfig{ KubernetesConfig: config.KubernetesConfig{
ServiceCIDR: expectedTargetCIDR, ServiceCIDR: expectedTargetCIDR,
}, },

View File

@ -82,10 +82,10 @@ func (r *fakeRouter) Inspect(route *Route) (exists bool, conflict string, overla
} }
type stubConfigLoader struct { type stubConfigLoader struct {
c *config.Config c *config.MachineConfig
e error e error
} }
func (l *stubConfigLoader) LoadConfigFromFile(profile string, miniHome ...string) (*config.Config, error) { func (l *stubConfigLoader) LoadConfigFromFile(profile string, miniHome ...string) (*config.MachineConfig, error) {
return l.c, l.e return l.c, l.e
} }

View File

@ -423,7 +423,7 @@ func TestTunnel(t *testing.T) {
}, },
} }
configLoader := &stubConfigLoader{ configLoader := &stubConfigLoader{
c: &config.Config{ c: &config.MachineConfig{
KubernetesConfig: config.KubernetesConfig{ KubernetesConfig: config.KubernetesConfig{
ServiceCIDR: tc.serviceCIDR, ServiceCIDR: tc.serviceCIDR,
}}, }},
@ -478,7 +478,7 @@ func TestErrorCreatingTunnel(t *testing.T) {
} }
configLoader := &stubConfigLoader{ configLoader := &stubConfigLoader{
c: &config.Config{ c: &config.MachineConfig{
KubernetesConfig: config.KubernetesConfig{ KubernetesConfig: config.KubernetesConfig{
ServiceCIDR: "10.96.0.0/12", ServiceCIDR: "10.96.0.0/12",
}}, }},

View File

@ -330,7 +330,7 @@ func configureAuth(p *BuildrootProvisioner) error {
return err return err
} }
if config.MachineConfig.ContainerRuntime == "" { if config.ContainerRuntime == "" {
if err := p.Service("docker", serviceaction.Enable); err != nil { if err := p.Service("docker", serviceaction.Enable); err != nil {
return err return err

View File

@ -107,7 +107,7 @@ func TestDownloadOnly(t *testing.T) {
got := "" got := ""
for _, p := range ps["valid"] { for _, p := range ps["valid"] {
if p.Name == profile { if p.Name == profile {
got = p.Config.MachineConfig.VMDriver got = p.Config[0].VMDriver
} }
} }