Added MINIKUBE_HOME env variable which sets .minikube directory

pull/1104/head
Aaron Prindle 2017-02-07 22:31:14 -08:00
parent ab9cbf7ec0
commit c418095c38
11 changed files with 37 additions and 21 deletions

View File

@ -37,7 +37,7 @@ import (
)
var dirs = [...]string{
constants.Minipath,
constants.GetMinipath(),
constants.MakeMiniPath("certs"),
constants.MakeMiniPath("machines"),
constants.MakeMiniPath("cache"),

View File

@ -238,7 +238,7 @@ func localkubeURIWasSpecified(config KubernetesConfig) bool {
// SetupCerts gets the generated credentials required to talk to the APIServer.
func SetupCerts(d drivers.Driver) error {
localPath := constants.Minipath
localPath := constants.GetMinipath()
ipStr, err := d.GetIP()
if err != nil {
return errors.Wrap(err, "Error getting ip from driver")
@ -287,7 +287,7 @@ func engineOptions(config MachineConfig) *engine.Options {
}
func createVirtualboxHost(config MachineConfig) drivers.Driver {
d := virtualbox.NewDriver(constants.MachineName, constants.Minipath)
d := virtualbox.NewDriver(constants.MachineName, constants.GetMinipath())
d.Boot2DockerURL = config.Downloader.GetISOFileURI(config.MinikubeISO)
d.Memory = config.Memory
d.CPU = config.CPUs
@ -328,8 +328,8 @@ func createHost(api libmachine.API, config MachineConfig) (*host.Host, error) {
return nil, errors.Wrap(err, "Error creating new host")
}
h.HostOptions.AuthOptions.CertDir = constants.Minipath
h.HostOptions.AuthOptions.StorePath = constants.Minipath
h.HostOptions.AuthOptions.CertDir = constants.GetMinipath()
h.HostOptions.AuthOptions.StorePath = constants.GetMinipath()
h.HostOptions.EngineOptions = engineOptions(config)
if err := api.Create(h); err != nil {

View File

@ -23,7 +23,7 @@ import (
)
func createVMwareFusionHost(config MachineConfig) drivers.Driver {
d := vmwarefusion.NewDriver(constants.MachineName, constants.Minipath).(*vmwarefusion.Driver)
d := vmwarefusion.NewDriver(constants.MachineName, constants.GetMinipath()).(*vmwarefusion.Driver)
d.Boot2DockerURL = config.Downloader.GetISOFileURI(config.MinikubeISO)
d.Memory = config.Memory
d.CPU = config.CPUs
@ -56,7 +56,7 @@ func createXhyveHost(config MachineConfig) *xhyveDriver {
return &xhyveDriver{
BaseDriver: &drivers.BaseDriver{
MachineName: constants.MachineName,
StorePath: constants.Minipath,
StorePath: constants.GetMinipath(),
},
Memory: config.Memory,
CPU: config.CPUs,

View File

@ -29,7 +29,7 @@ func createKVMHost(config MachineConfig) *kvm.Driver {
return &kvm.Driver{
BaseDriver: &drivers.BaseDriver{
MachineName: constants.MachineName,
StorePath: constants.Minipath,
StorePath: constants.GetMinipath(),
},
Memory: config.Memory,
CPU: config.CPUs,
@ -37,8 +37,8 @@ func createKVMHost(config MachineConfig) *kvm.Driver {
PrivateNetwork: "docker-machines",
Boot2DockerURL: config.Downloader.GetISOFileURI(config.MinikubeISO),
DiskSize: config.DiskSize,
DiskPath: filepath.Join(constants.Minipath, "machines", constants.MachineName, fmt.Sprintf("%s.img", constants.MachineName)),
ISO: filepath.Join(constants.Minipath, "machines", constants.MachineName, "boot2docker.iso"),
DiskPath: filepath.Join(constants.GetMinipath(), "machines", constants.MachineName, fmt.Sprintf("%s.img", constants.MachineName)),
ISO: filepath.Join(constants.GetMinipath(), "machines", constants.MachineName, "boot2docker.iso"),
CacheMode: "default",
IOMode: "threads",
}

View File

@ -23,7 +23,7 @@ import (
)
func createHypervHost(config MachineConfig) drivers.Driver {
d := hyperv.NewDriver(constants.MachineName, constants.Minipath)
d := hyperv.NewDriver(constants.MachineName, constants.GetMinipath())
d.Boot2DockerURL = config.Downloader.GetISOFileURI(config.MinikubeISO)
d.VSwitch = config.HypervVirtualSwitch
d.MemSize = config.Memory

View File

@ -53,7 +53,7 @@ type localkubeCacher struct {
}
func (l *localkubeCacher) getLocalkubeCacheFilepath() string {
return filepath.Join(constants.Minipath, "cache", "localkube",
return filepath.Join(constants.GetMinipath(), "cache", "localkube",
filepath.Base(url.QueryEscape("localkube-"+l.k8sConf.KubernetesVersion)))
}

View File

@ -18,6 +18,7 @@ package constants
import (
"fmt"
"os"
"path/filepath"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
@ -32,8 +33,20 @@ const MachineName = "minikube"
// APIServerPort is the port that the API server should listen on.
const APIServerPort = 8443
const MinikubeHome = "MINIKUBE_HOME"
// Minipath is the path to the user's minikube dir
var Minipath = filepath.Join(homedir.HomeDir(), ".minikube")
func GetMinipath() string {
if os.Getenv(MinikubeHome) == "" {
return DefaultMinipath
}
if filepath.Base(os.Getenv(MinikubeHome)) == ".minikube" {
return os.Getenv(MinikubeHome)
}
return filepath.Join(os.Getenv(MinikubeHome), ".minikube")
}
var DefaultMinipath = filepath.Join(homedir.HomeDir(), ".minikube")
// KubeconfigPath is the path to the Kubernetes client config
var KubeconfigPath = clientcmd.RecommendedHomeFile
@ -49,7 +62,7 @@ const MinikubeEnvPrefix = "MINIKUBE"
// MakeMiniPath is a utility to calculate a relative path to our directory.
func MakeMiniPath(fileName ...string) string {
args := []string{Minipath}
args := []string{GetMinipath()}
args = append(args, fileName...)
return filepath.Join(args...)
}

View File

@ -79,7 +79,7 @@ const (
// Gets a new client depending on the clientType specified
// defaults to the libmachine client
func NewAPIClient(clientType ClientType) (libmachine.API, error) {
storePath := constants.Minipath
storePath := constants.GetMinipath()
certsDir := constants.MakeMiniPath("certs")
newClientFactory, ok := clientFactories[clientType]
if !ok {

View File

@ -22,6 +22,7 @@ import (
"log"
"net"
"os"
"path/filepath"
"testing"
"github.com/docker/machine/libmachine/drivers/plugin/localbinary"
@ -33,8 +34,9 @@ func makeTempDir() string {
if err != nil {
log.Fatal(err)
}
constants.Minipath = tempDir
return tempDir
tempDir = filepath.Join(tempDir, ".minikube")
os.Setenv(constants.MinikubeHome, tempDir)
return constants.GetMinipath()
}
func TestRunNotDriver(t *testing.T) {

View File

@ -30,6 +30,7 @@ func MakeTempDir() string {
if err != nil {
log.Fatal(err)
}
tempDir = filepath.Join(tempDir, ".minikube")
err = os.MkdirAll(filepath.Join(tempDir, "addons"), 0777)
if err != nil {
log.Fatal(err)
@ -42,6 +43,6 @@ func MakeTempDir() string {
if err != nil {
log.Fatal(err)
}
constants.Minipath = tempDir
return tempDir
os.Setenv(constants.MinikubeHome, tempDir)
return constants.GetMinipath()
}

View File

@ -46,7 +46,7 @@ func (f DefaultDownloader) GetISOFileURI(isoURL string) string {
if urlObj.Scheme == fileScheme {
return isoURL
}
isoPath := filepath.Join(constants.Minipath, "cache", "iso", filepath.Base(isoURL))
isoPath := filepath.Join(constants.GetMinipath(), "cache", "iso", filepath.Base(isoURL))
// As this is a file URL there should be no backslashes regardless of platform running on.
return "file://" + filepath.ToSlash(isoPath)
}
@ -97,7 +97,7 @@ func (f DefaultDownloader) shouldCacheMinikubeISO(isoURL string) bool {
}
func (f DefaultDownloader) getISOCacheFilepath(isoURL string) string {
return filepath.Join(constants.Minipath, "cache", "iso", filepath.Base(isoURL))
return filepath.Join(constants.GetMinipath(), "cache", "iso", filepath.Base(isoURL))
}
func (f DefaultDownloader) isMinikubeISOCached(isoURL string) bool {