commit
6fcf2cda6d
|
@ -34,7 +34,11 @@ import (
|
|||
var dirs = [...]string{
|
||||
constants.Minipath,
|
||||
constants.MakeMiniPath("certs"),
|
||||
constants.MakeMiniPath("machines")}
|
||||
constants.MakeMiniPath("machines"),
|
||||
constants.MakeMiniPath("cache"),
|
||||
constants.MakeMiniPath("cache", "iso"),
|
||||
constants.MakeMiniPath("cache", "localkube"),
|
||||
constants.MakeMiniPath("config")}
|
||||
|
||||
var (
|
||||
showLibmachineLogs bool
|
||||
|
@ -77,7 +81,7 @@ func init() {
|
|||
// initConfig reads in config file and ENV variables if set.
|
||||
func initConfig() {
|
||||
viper.SetConfigName("config")
|
||||
viper.AddConfigPath(constants.ConfigFilePath)
|
||||
viper.AddConfigPath(constants.MakeMiniPath("config"))
|
||||
viper.ReadInConfig()
|
||||
viper.SetDefault(config.WantUpdateNotification, true)
|
||||
viper.SetDefault(config.ReminderWaitPeriodInHours, 24)
|
||||
|
|
|
@ -20,8 +20,12 @@ import (
|
|||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -293,16 +297,56 @@ func engineOptions(config MachineConfig) *engine.Options {
|
|||
|
||||
func createVirtualboxHost(config MachineConfig) drivers.Driver {
|
||||
d := virtualbox.NewDriver(constants.MachineName, constants.Minipath)
|
||||
d.Boot2DockerURL = config.MinikubeISO
|
||||
d.Boot2DockerURL = config.GetISOCacheFileURI()
|
||||
d.Memory = config.Memory
|
||||
d.CPU = config.CPUs
|
||||
d.DiskSize = int(config.DiskSize)
|
||||
return d
|
||||
}
|
||||
|
||||
func (m *MachineConfig) CacheMinikubeISO() error {
|
||||
// store the miniube-iso inside the .minikube dir
|
||||
response, err := http.Get(m.MinikubeISO)
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
out, err := os.Create(m.GetISOCacheFilepath())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
defer response.Body.Close()
|
||||
if _, err = io.Copy(out, response.Body); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MachineConfig) GetISOCacheFilepath() string {
|
||||
return filepath.Join(constants.Minipath, "cache", "iso", filepath.Base(m.MinikubeISO))
|
||||
}
|
||||
|
||||
func (m *MachineConfig) GetISOCacheFileURI() string {
|
||||
return "file://" + path.Join(constants.Minipath, "cache", "iso", filepath.Base(m.MinikubeISO))
|
||||
}
|
||||
|
||||
func (m *MachineConfig) IsMinikubeISOCached() bool {
|
||||
if _, err := os.Stat(m.GetISOCacheFilepath()); os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func createHost(api libmachine.API, config MachineConfig) (*host.Host, error) {
|
||||
var driver interface{}
|
||||
|
||||
if !config.IsMinikubeISOCached() {
|
||||
if err := config.CacheMinikubeISO(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
switch config.VMDriver {
|
||||
case "virtualbox":
|
||||
driver = createVirtualboxHost(config)
|
||||
|
|
|
@ -24,7 +24,7 @@ import (
|
|||
|
||||
func createVMwareFusionHost(config MachineConfig) drivers.Driver {
|
||||
d := vmwarefusion.NewDriver(constants.MachineName, constants.Minipath).(*vmwarefusion.Driver)
|
||||
d.Boot2DockerURL = config.MinikubeISO
|
||||
d.Boot2DockerURL = config.GetISOCacheFileURI()
|
||||
d.Memory = config.Memory
|
||||
d.CPU = config.CPUs
|
||||
|
||||
|
@ -59,7 +59,7 @@ func createXhyveHost(config MachineConfig) *xhyveDriver {
|
|||
},
|
||||
Memory: config.Memory,
|
||||
CPU: config.CPUs,
|
||||
Boot2DockerURL: config.MinikubeISO,
|
||||
Boot2DockerURL: config.GetISOCacheFileURI(),
|
||||
BootCmd: "loglevel=3 user=docker console=ttyS0 console=tty0 noembed nomodeset norestore waitusb=10 base host=boot2docker",
|
||||
DiskSize: int64(config.DiskSize),
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ func createKVMHost(config MachineConfig) *kvmDriver {
|
|||
CPU: config.CPUs,
|
||||
Network: "default",
|
||||
PrivateNetwork: "docker-machines",
|
||||
Boot2DockerURL: config.MinikubeISO,
|
||||
Boot2DockerURL: config.GetISOCacheFileURI(),
|
||||
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"),
|
||||
|
|
|
@ -33,7 +33,8 @@ import (
|
|||
"k8s.io/minikube/pkg/minikube/tests"
|
||||
)
|
||||
|
||||
var defaultMachineConfig = MachineConfig{VMDriver: constants.DefaultVMDriver}
|
||||
var defaultMachineConfig = MachineConfig{VMDriver: constants.DefaultVMDriver,
|
||||
MinikubeISO: constants.DefaultIsoUrl}
|
||||
|
||||
func TestCreateHost(t *testing.T) {
|
||||
api := tests.NewMockAPI()
|
||||
|
@ -361,6 +362,9 @@ func TestSetupCerts(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetHostDockerEnv(t *testing.T) {
|
||||
tempDir := tests.MakeTempDir()
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
api := tests.NewMockAPI()
|
||||
h, err := createHost(api, defaultMachineConfig)
|
||||
if err != nil {
|
||||
|
|
|
@ -40,8 +40,10 @@ var KubeconfigPath = clientcmd.RecommendedHomeFile
|
|||
const MinikubeContext = "minikube"
|
||||
|
||||
// MakeMiniPath is a utility to calculate a relative path to our directory.
|
||||
func MakeMiniPath(fileName string) string {
|
||||
return filepath.Join(Minipath, fileName)
|
||||
func MakeMiniPath(fileName ...string) string {
|
||||
args := []string{Minipath}
|
||||
args = append(args, fileName...)
|
||||
return filepath.Join(args...)
|
||||
}
|
||||
|
||||
// Only pass along these flags to localkube.
|
||||
|
@ -69,5 +71,3 @@ const (
|
|||
RemoteLocalKubeErrPath = "/var/lib/localkube/localkube.err"
|
||||
RemoteLocalKubeOutPath = "/var/lib/localkube/localkube.out"
|
||||
)
|
||||
|
||||
var ConfigFilePath = MakeMiniPath("config")
|
||||
|
|
|
@ -19,6 +19,8 @@ package tests
|
|||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
)
|
||||
|
@ -28,6 +30,14 @@ func MakeTempDir() string {
|
|||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = os.MkdirAll(filepath.Join(tempDir, "cache", "iso"), 0777)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = os.MkdirAll(filepath.Join(tempDir, "cache", "localkube"), 0777)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
constants.Minipath = tempDir
|
||||
return tempDir
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue