From 7504d8bd894b96faa36033d690baa3aeff8cf3e1 Mon Sep 17 00:00:00 2001 From: Aaron Prindle Date: Wed, 3 Aug 2016 08:41:58 -0700 Subject: [PATCH 01/17] Fixing file:// uri issue for --iso-url flag --- pkg/minikube/cluster/cluster.go | 41 +++++++++++++++++++++----- pkg/minikube/cluster/cluster_darwin.go | 4 +-- pkg/minikube/cluster/cluster_linux.go | 2 +- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/pkg/minikube/cluster/cluster.go b/pkg/minikube/cluster/cluster.go index 7e2497c85b45..e7a111c98964 100644 --- a/pkg/minikube/cluster/cluster.go +++ b/pkg/minikube/cluster/cluster.go @@ -24,8 +24,8 @@ import ( "io/ioutil" "net" "net/http" + "net/url" "os" - "path" "path/filepath" "strings" "time" @@ -49,6 +49,8 @@ var ( certs = []string{"apiserver.crt", "apiserver.key"} ) +const fileScheme = "file" + //This init function is used to set the logtostderr variable to false so that INFO level log info does not clutter the CLI //INFO lvl logging is displayed due to the kubernetes api calling flag.Set("logtostderr", "true") in its init() //see: https://github.com/kubernetes/kubernetes/blob/master/pkg/util/logs.go#L32-34 @@ -275,14 +277,14 @@ func engineOptions(config MachineConfig) *engine.Options { func createVirtualboxHost(config MachineConfig) drivers.Driver { d := virtualbox.NewDriver(constants.MachineName, constants.Minipath) - d.Boot2DockerURL = config.GetISOCacheFileURI() + d.Boot2DockerURL = config.GetISOFileURI() d.Memory = config.Memory d.CPU = config.CPUs d.DiskSize = int(config.DiskSize) return d } -func (m *MachineConfig) CacheMinikubeISO() error { +func (m *MachineConfig) CacheMinikubeISOFromURL() error { // store the miniube-iso inside the .minikube dir response, err := http.Get(m.MinikubeISO) if err != nil { @@ -301,12 +303,37 @@ func (m *MachineConfig) CacheMinikubeISO() error { return nil } +func (m *MachineConfig) ShouldCacheMinikubeISO() bool { + // store the miniube-iso inside the .minikube dir + + urlObj, err := url.Parse(m.MinikubeISO) + if err != nil { + return false + } + if urlObj.Scheme == fileScheme { + return false + } + if m.IsMinikubeISOCached() { + return false + } + return true +} + 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) GetISOFileURI() string { + urlObj, err := url.Parse(m.MinikubeISO) + if err != nil { + return m.MinikubeISO + } + if urlObj.Scheme == fileScheme { + return m.MinikubeISO + } + isoPath := filepath.Join(constants.Minipath, "cache", "iso", filepath.Base(m.MinikubeISO)) + // As this is a file URL there should be no backslashes regardless of platform running on. + return "file://" + filepath.ToSlash(isoPath) } func (m *MachineConfig) IsMinikubeISOCached() bool { @@ -319,8 +346,8 @@ func (m *MachineConfig) IsMinikubeISOCached() bool { func createHost(api libmachine.API, config MachineConfig) (*host.Host, error) { var driver interface{} - if !config.IsMinikubeISOCached() { - if err := config.CacheMinikubeISO(); err != nil { + if config.ShouldCacheMinikubeISO() { + if err := config.CacheMinikubeISOFromURL(); err != nil { return nil, err } } diff --git a/pkg/minikube/cluster/cluster_darwin.go b/pkg/minikube/cluster/cluster_darwin.go index ea1bcab01437..db070b709d36 100644 --- a/pkg/minikube/cluster/cluster_darwin.go +++ b/pkg/minikube/cluster/cluster_darwin.go @@ -24,7 +24,7 @@ import ( func createVMwareFusionHost(config MachineConfig) drivers.Driver { d := vmwarefusion.NewDriver(constants.MachineName, constants.Minipath).(*vmwarefusion.Driver) - d.Boot2DockerURL = config.GetISOCacheFileURI() + d.Boot2DockerURL = config.GetISOFileURI() 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.GetISOCacheFileURI(), + Boot2DockerURL: config.GetISOFileURI(), BootCmd: "loglevel=3 user=docker console=ttyS0 console=tty0 noembed nomodeset norestore waitusb=10 base host=boot2docker", DiskSize: int64(config.DiskSize), } diff --git a/pkg/minikube/cluster/cluster_linux.go b/pkg/minikube/cluster/cluster_linux.go index 064a3ab177d5..ab007064bb7e 100644 --- a/pkg/minikube/cluster/cluster_linux.go +++ b/pkg/minikube/cluster/cluster_linux.go @@ -49,7 +49,7 @@ func createKVMHost(config MachineConfig) *kvmDriver { CPU: config.CPUs, Network: "default", PrivateNetwork: "docker-machines", - Boot2DockerURL: config.GetISOCacheFileURI(), + Boot2DockerURL: config.GetISOFileURI(), 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"), From ba2e651a52b69156d701f2a7d24d1f907017bea2 Mon Sep 17 00:00:00 2001 From: dlorenc Date: Thu, 4 Aug 2016 10:43:35 -0700 Subject: [PATCH 02/17] Don't drop errors during creation retries. --- cmd/minikube/cmd/start.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 9fe84e78d3fe..ade2cab257bb 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -22,7 +22,7 @@ import ( "strconv" "strings" - "github.com/docker/go-units" + units "github.com/docker/go-units" "github.com/docker/machine/libmachine" "github.com/docker/machine/libmachine/host" "github.com/golang/glog" @@ -71,6 +71,9 @@ func runStart(cmd *cobra.Command, args []string) { var host *host.Host start := func() (err error) { host, err = cluster.StartHost(api, config) + if err != nil { + glog.Errorf("Error starting host: %s. Retrying.\n", err) + } return err } err := util.Retry(3, start) From 1d6a8622aa3cd60462bb19db658fc47a1f3f753e Mon Sep 17 00:00:00 2001 From: dlorenc Date: Thu, 4 Aug 2016 10:14:45 -0700 Subject: [PATCH 03/17] Configure /data as a persisted directory. --- README.md | 23 +++++++++++++++++++++++ deploy/iso/bootlocal.sh | 2 ++ 2 files changed, 25 insertions(+) diff --git a/README.md b/README.md index 188c28a6bf5c..4b60cd2922dc 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,29 @@ To determine the NodePort for your service, you can use a `kubectl` command like Minishift supports [PersistentVolumes](http://kubernetes.io/docs/user-guide/persistent-volumes/) of type `hostPath`. These PersistentVolumes are mapped to a directory inside the minishift VM. +The MiniShift VM boots into a tmpfs, so most directories will not be persisted across reboots (`minishift stop`). +However, MiniShift is configured to persist files stored under the following host directories: + +* `/data` +* `/var/lib/minishift` +* `/var/lib/docker` + +Here is an example PersistentVolume config to persist data in the '/data' directory: + +```yaml +apiVersion: v1 +kind: PersistentVolume +metadata: + name: pv0001 +spec: + accessModes: + - ReadWriteOnce + capacity: + storage: 5Gi + hostPath: + path: /data/pv0001/ +``` + ## Private Container Registries To access a private container registry, follow the steps on [this page](http://kubernetes.io/docs/user-guide/images/). diff --git a/deploy/iso/bootlocal.sh b/deploy/iso/bootlocal.sh index 19bb06be2aed..6b3797717e24 100644 --- a/deploy/iso/bootlocal.sh +++ b/deploy/iso/bootlocal.sh @@ -20,3 +20,5 @@ PARTNAME=`echo "$BOOT2DOCKER_DATA" | sed 's/.*\///'` mkdir -p /mnt/$PARTNAME/var/lib/minishift ln -s /mnt/$PARTNAME/var/lib/minishift /var/lib/minishift +mkdir -p /mnt/$PARTNAME/data +ln -s /mnt/$PARTNAME/data /data From b3b47eef61b337c919c156a2656dc2a1692e5bb2 Mon Sep 17 00:00:00 2001 From: Dan Lorenc Date: Sat, 6 Aug 2016 12:29:56 -0700 Subject: [PATCH 04/17] Return a MultiError from retry. --- pkg/minikube/cluster/cluster.go | 24 +----------------------- pkg/minikube/cluster/cluster_test.go | 20 -------------------- pkg/util/utils.go | 27 ++++++++++++++++++++++++++- pkg/util/utils_test.go | 19 +++++++++++++++++++ 4 files changed, 46 insertions(+), 44 deletions(-) diff --git a/pkg/minikube/cluster/cluster.go b/pkg/minikube/cluster/cluster.go index e7a111c98964..f0988542d6a2 100644 --- a/pkg/minikube/cluster/cluster.go +++ b/pkg/minikube/cluster/cluster.go @@ -108,35 +108,13 @@ func StopHost(api libmachine.API) error { return nil } -type multiError struct { - Errors []error -} - -func (m *multiError) Collect(err error) { - if err != nil { - m.Errors = append(m.Errors, err) - } -} - -func (m multiError) ToError() error { - if len(m.Errors) == 0 { - return nil - } - - errStrings := []string{} - for _, err := range m.Errors { - errStrings = append(errStrings, err.Error()) - } - return fmt.Errorf(strings.Join(errStrings, "\n")) -} - // DeleteHost deletes the host VM. func DeleteHost(api libmachine.API) error { host, err := api.Load(constants.MachineName) if err != nil { return err } - m := multiError{} + m := util.MultiError{} m.Collect(host.Driver.Remove()) m.Collect(api.Remove(constants.MachineName)) return m.ToError() diff --git a/pkg/minikube/cluster/cluster_test.go b/pkg/minikube/cluster/cluster_test.go index 1e97e188fdb4..42bbe503e0c3 100644 --- a/pkg/minikube/cluster/cluster_test.go +++ b/pkg/minikube/cluster/cluster_test.go @@ -231,26 +231,6 @@ func TestStopHost(t *testing.T) { if s, _ := h.Driver.GetState(); s != state.Stopped { t.Fatalf("Machine not stopped. Currently in state: %s", s) } - -} - -func TestMultiError(t *testing.T) { - m := multiError{} - - m.Collect(fmt.Errorf("Error 1")) - m.Collect(fmt.Errorf("Error 2")) - - err := m.ToError() - expected := `Error 1 -Error 2` - if err.Error() != expected { - t.Fatalf("%s != %s", err, expected) - } - - m = multiError{} - if err := m.ToError(); err != nil { - t.Fatalf("Unexpected error: %s", err) - } } func TestDeleteHost(t *testing.T) { diff --git a/pkg/util/utils.go b/pkg/util/utils.go index 6eaa1d8657f0..237da1e1bb14 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -20,6 +20,7 @@ import ( "fmt" "io" "os" + "strings" "time" ) @@ -67,12 +68,36 @@ func Retry(attempts int, callback func() error) (err error) { } func RetryAfter(attempts int, callback func() error, d time.Duration) (err error) { + m := MultiError{} for i := 0; i < attempts; i++ { err = callback() if err == nil { return nil } + m.Collect(err) time.Sleep(d) } - return err + return m.ToError() +} + +type MultiError struct { + Errors []error +} + +func (m *MultiError) Collect(err error) { + if err != nil { + m.Errors = append(m.Errors, err) + } +} + +func (m MultiError) ToError() error { + if len(m.Errors) == 0 { + return nil + } + + errStrings := []string{} + for _, err := range m.Errors { + errStrings = append(errStrings, err.Error()) + } + return fmt.Errorf(strings.Join(errStrings, "\n")) } diff --git a/pkg/util/utils_test.go b/pkg/util/utils_test.go index d7f6ff4fb0d7..9a7d471ea2cc 100644 --- a/pkg/util/utils_test.go +++ b/pkg/util/utils_test.go @@ -59,3 +59,22 @@ func TestRetry(t *testing.T) { } } + +func TestMultiError(t *testing.T) { + m := MultiError{} + + m.Collect(fmt.Errorf("Error 1")) + m.Collect(fmt.Errorf("Error 2")) + + err := m.ToError() + expected := `Error 1 +Error 2` + if err.Error() != expected { + t.Fatalf("%s != %s", err, expected) + } + + m = MultiError{} + if err := m.ToError(); err != nil { + t.Fatalf("Unexpected error: %s", err) + } +} From 0af56a8325f254e6bbd581ee5c28e856da639717 Mon Sep 17 00:00:00 2001 From: Matt Rickard Date: Mon, 8 Aug 2016 10:13:03 -0700 Subject: [PATCH 05/17] Add warning message for failure to read conf The configuration file is optional, however when/if we move more options to be configurable through the viper yaml file, this would be nice to see when debugging. --- cmd/minikube/cmd/root.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/minikube/cmd/root.go b/cmd/minikube/cmd/root.go index e7cee91b344b..f1cea375d635 100644 --- a/cmd/minikube/cmd/root.go +++ b/cmd/minikube/cmd/root.go @@ -82,7 +82,10 @@ func init() { func initConfig() { viper.SetConfigName("config") viper.AddConfigPath(constants.MakeMiniPath("config")) - viper.ReadInConfig() + err := viper.ReadInConfig() + if err != nil { + glog.Warningf("Error reading config file: %s", err) + } viper.SetDefault(config.WantUpdateNotification, true) viper.SetDefault(config.ReminderWaitPeriodInHours, 24) } From 44fddde9bca394be2c1f4ab36beb8635d13027c0 Mon Sep 17 00:00:00 2001 From: Matt Rickard Date: Mon, 8 Aug 2016 10:53:01 -0700 Subject: [PATCH 06/17] Added config path to warning message --- cmd/minikube/cmd/root.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/minikube/cmd/root.go b/cmd/minikube/cmd/root.go index f1cea375d635..9d4a8616d74f 100644 --- a/cmd/minikube/cmd/root.go +++ b/cmd/minikube/cmd/root.go @@ -80,11 +80,12 @@ func init() { // initConfig reads in config file and ENV variables if set. func initConfig() { + configPath := constants.MakeMiniPath("config") viper.SetConfigName("config") - viper.AddConfigPath(constants.MakeMiniPath("config")) + viper.AddConfigPath(configPath) err := viper.ReadInConfig() if err != nil { - glog.Warningf("Error reading config file: %s", err) + glog.Warningf("Error reading config file at %s: %s", configPath, err) } viper.SetDefault(config.WantUpdateNotification, true) viper.SetDefault(config.ReminderWaitPeriodInHours, 24) From 8b9fa10224c355ad526b6d8d509bee53e054d00e Mon Sep 17 00:00:00 2001 From: Dan Lorenc Date: Mon, 8 Aug 2016 14:50:13 -0700 Subject: [PATCH 07/17] Remove the "kubernetes is now available" line from start. --- cmd/minikube/cmd/start.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index ade2cab257bb..7144decbd2cc 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -109,7 +109,6 @@ func runStart(cmd *cobra.Command, args []string) { } kubeHost = strings.Replace(kubeHost, "tcp://", "https://", -1) kubeHost = strings.Replace(kubeHost, ":2376", ":"+strconv.Itoa(constants.APIServerPort), -1) - fmt.Printf("OpenShift is available at %s.\n", kubeHost) // setup kubeconfig name := constants.MinikubeContext From 60e72e374582f7003e771ecc35923c54273274fb Mon Sep 17 00:00:00 2001 From: Matt Rickard Date: Mon, 1 Aug 2016 11:04:20 -0700 Subject: [PATCH 08/17] Adding a Virtio9p mount for /Users with xhyve This feature is enabled in v0.2.3 of the docker xhyve driver Enabling this by default on cluster_darwin This resolves issue #423 --- pkg/minikube/cluster/cluster_darwin.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/minikube/cluster/cluster_darwin.go b/pkg/minikube/cluster/cluster_darwin.go index db070b709d36..09da73391c19 100644 --- a/pkg/minikube/cluster/cluster_darwin.go +++ b/pkg/minikube/cluster/cluster_darwin.go @@ -62,5 +62,7 @@ func createXhyveHost(config MachineConfig) *xhyveDriver { Boot2DockerURL: config.GetISOFileURI(), BootCmd: "loglevel=3 user=docker console=ttyS0 console=tty0 noembed nomodeset norestore waitusb=10 base host=boot2docker", DiskSize: int64(config.DiskSize), + Virtio9p: true, + Virtio9pFolder: "/Users", } } From b11ff2338351174378ee286adf5a997c93233790 Mon Sep 17 00:00:00 2001 From: Aaron Prindle Date: Fri, 19 Aug 2016 10:32:44 -0700 Subject: [PATCH 09/17] Made it so that debug is enabled for --show-libmachine-logs flag. --- cmd/minikube/cmd/root.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/minikube/cmd/root.go b/cmd/minikube/cmd/root.go index 9d4a8616d74f..52448b5f8f22 100644 --- a/cmd/minikube/cmd/root.go +++ b/cmd/minikube/cmd/root.go @@ -56,6 +56,7 @@ var RootCmd = &cobra.Command{ } } + log.SetDebug(showLibmachineLogs) if !showLibmachineLogs { log.SetOutWriter(ioutil.Discard) log.SetErrWriter(ioutil.Discard) From 3ab87eff7c59047bc015bcffcd66b978bf96932d Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Sat, 13 Aug 2016 22:32:19 +0800 Subject: [PATCH 10/17] Add registry-mirror option to minikube start --- cmd/minikube/cmd/start.go | 6 ++++++ docs/minishift_start.md | 1 + pkg/minikube/cluster/cluster.go | 3 +++ 3 files changed, 10 insertions(+) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 7144decbd2cc..b86826ec8f89 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -42,6 +42,8 @@ var ( vmDriver string dockerEnv []string insecureRegistry []string + registryMirror []string + hostOnlyCIDR string ) // startCmd represents the start command @@ -66,6 +68,8 @@ func runStart(cmd *cobra.Command, args []string) { VMDriver: vmDriver, DockerEnv: dockerEnv, InsecureRegistry: insecureRegistry, + RegistryMirror: registryMirror, + HostOnlyCIDR: hostOnlyCIDR, } var host *host.Host @@ -176,5 +180,7 @@ func init() { startCmd.Flags().StringSliceVar(&dockerEnv, "docker-env", nil, "Environment variables to pass to the Docker daemon. (format: key=value)") startCmd.Flags().StringSliceVar(&insecureRegistry, "insecure-registry", nil, "Insecure Docker registries to pass to the Docker daemon") + startCmd.Flags().StringSliceVar(®istryMirror, "registry-mirror", nil, "Registry mirrors to pass to the Docker daemon") + RootCmd.AddCommand(startCmd) } diff --git a/docs/minishift_start.md b/docs/minishift_start.md index d630da382c4a..89ca2986182d 100644 --- a/docs/minishift_start.md +++ b/docs/minishift_start.md @@ -21,6 +21,7 @@ minishift start --insecure-registry=[]: Insecure Docker registries to pass to the Docker daemon --iso-url="https://github.com/jimmidyson/minishift/releases/download/v0.3.4/boot2docker.iso": Location of the minishift iso --memory=1024: Amount of RAM allocated to the minishift VM + --registry-mirror=[]: Registry mirrors to pass to the Docker daemon --vm-driver="kvm": VM driver is one of: [virtualbox kvm] ``` diff --git a/pkg/minikube/cluster/cluster.go b/pkg/minikube/cluster/cluster.go index f0988542d6a2..c5359f162339 100644 --- a/pkg/minikube/cluster/cluster.go +++ b/pkg/minikube/cluster/cluster.go @@ -156,6 +156,8 @@ type MachineConfig struct { VMDriver string DockerEnv []string // Each entry is formatted as KEY=VALUE. InsecureRegistry []string + RegistryMirror []string + HostOnlyCIDR string // Only used by the virtualbox driver } // StartCluster starts a k8s cluster on the specified Host. @@ -249,6 +251,7 @@ func engineOptions(config MachineConfig) *engine.Options { o := engine.Options{ Env: config.DockerEnv, InsecureRegistry: config.InsecureRegistry, + RegistryMirror: config.RegistryMirror, } return &o } From 47a1c01718b723a81dc16b41455bbfc93ee2a9bb Mon Sep 17 00:00:00 2001 From: Matt Rickard Date: Fri, 12 Aug 2016 13:25:04 -0700 Subject: [PATCH 11/17] Add env variables for viper controlled vars Minikube will now read from env variables with the MINIKUBE_ prefix. These variables will be read on every viper.Get() and will overwrite default variables. When we add binding to pflags, flags will overwrite env variables. At this time, only notification settings are controlled by viper. --- cmd/minikube/cmd/root.go | 5 +++++ cmd/minikube/cmd/root_test.go | 16 ++++++++++++++++ pkg/minikube/constants/constants.go | 3 +++ 3 files changed, 24 insertions(+) diff --git a/cmd/minikube/cmd/root.go b/cmd/minikube/cmd/root.go index 52448b5f8f22..1d0766044f70 100644 --- a/cmd/minikube/cmd/root.go +++ b/cmd/minikube/cmd/root.go @@ -82,6 +82,11 @@ func init() { // initConfig reads in config file and ENV variables if set. func initConfig() { configPath := constants.MakeMiniPath("config") + + // Bind all viper values to env variables + viper.SetEnvPrefix(constants.MiniShiftEnvPrefix) + viper.AutomaticEnv() + viper.SetConfigName("config") viper.AddConfigPath(configPath) err := viper.ReadInConfig() diff --git a/cmd/minikube/cmd/root_test.go b/cmd/minikube/cmd/root_test.go index 6caca6189037..c3a8c1f6f97a 100644 --- a/cmd/minikube/cmd/root_test.go +++ b/cmd/minikube/cmd/root_test.go @@ -22,6 +22,9 @@ import ( "github.com/jimmidyson/minishift/pkg/minikube/tests" "github.com/spf13/cobra" + "github.com/spf13/viper" + "k8s.io/minikube/pkg/minikube/constants" + "k8s.io/minikube/pkg/minikube/tests" ) func runCommand(f func(*cobra.Command, []string)) { @@ -44,3 +47,16 @@ func TestPreRunDirectories(t *testing.T) { } } } + +func getEnvVarName(name string) string { + return constants.MinikubeEnvPrefix + name +} + +func TestEnvVariable(t *testing.T) { + defer os.Unsetenv("WANTUPDATENOTIFICATION") + initConfig() + os.Setenv(getEnvVarName("WANTUPDATENOTIFICATION"), "true") + if !viper.GetBool("WantUpdateNotification") { + t.Fatalf("Viper did not respect environment variable") + } +} diff --git a/pkg/minikube/constants/constants.go b/pkg/minikube/constants/constants.go index 12a85689ccb3..66898bdb4d3a 100644 --- a/pkg/minikube/constants/constants.go +++ b/pkg/minikube/constants/constants.go @@ -40,6 +40,9 @@ var KubeconfigPath = clientcmd.RecommendedHomeFile // MinikubeContext is the kubeconfig context name used for minishift const MinikubeContext = "minishift" +// MiniShiftEnvPrefix is the prefix for the environmental variables +const MiniShiftEnvPrefix = "MINISHIFT" + // MakeMiniPath is a utility to calculate a relative path to our directory. func MakeMiniPath(fileName ...string) string { args := []string{Minipath} From df3033a9011e6d31e302afe2913bdba8df5f0526 Mon Sep 17 00:00:00 2001 From: Jimmi Dyson Date: Thu, 11 Aug 2016 15:42:17 +0100 Subject: [PATCH 12/17] Add DOCKER_API_VERSION to docker-env command --- cmd/minikube/cmd/env.go | 30 +++++++++++++++-------------- pkg/minikube/constants/constants.go | 3 +++ 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/cmd/minikube/cmd/env.go b/cmd/minikube/cmd/env.go index bd5f12b65880..6db54f20ef21 100644 --- a/cmd/minikube/cmd/env.go +++ b/cmd/minikube/cmd/env.go @@ -34,19 +34,20 @@ import ( ) const ( - envTmpl = `{{ .Prefix }}DOCKER_TLS_VERIFY{{ .Delimiter }}{{ .DockerTLSVerify }}{{ .Suffix }}{{ .Prefix }}DOCKER_HOST{{ .Delimiter }}{{ .DockerHost }}{{ .Suffix }}{{ .Prefix }}DOCKER_CERT_PATH{{ .Delimiter }}{{ .DockerCertPath }}{{ .Suffix }}{{ if .NoProxyVar }}{{ .Prefix }}{{ .NoProxyVar }}{{ .Delimiter }}{{ .NoProxyValue }}{{ .Suffix }}{{end}}{{ .UsageHint }}` + envTmpl = `{{ .Prefix }}DOCKER_TLS_VERIFY{{ .Delimiter }}{{ .DockerTLSVerify }}{{ .Suffix }}{{ .Prefix }}DOCKER_HOST{{ .Delimiter }}{{ .DockerHost }}{{ .Suffix }}{{ .Prefix }}DOCKER_CERT_PATH{{ .Delimiter }}{{ .DockerCertPath }}{{ .Suffix }}{{ .Prefix }}DOCKER_API_VERSION{{ .Delimiter }}{{ .DockerAPIVersion }}{{ .Suffix }}{{ if .NoProxyVar }}{{ .Prefix }}{{ .NoProxyVar }}{{ .Delimiter }}{{ .NoProxyValue }}{{ .Suffix }}{{end}}{{ .UsageHint }}` ) type ShellConfig struct { - Prefix string - Delimiter string - Suffix string - DockerCertPath string - DockerHost string - DockerTLSVerify string - UsageHint string - NoProxyVar string - NoProxyValue string + Prefix string + Delimiter string + Suffix string + DockerCertPath string + DockerHost string + DockerTLSVerify string + DockerAPIVersion string + UsageHint string + NoProxyVar string + NoProxyValue string } var noProxy bool @@ -90,10 +91,11 @@ func shellCfgSet(api libmachine.API) (*ShellConfig, error) { } shellCfg := &ShellConfig{ - DockerCertPath: envMap["DOCKER_CERT_PATH"], - DockerHost: envMap["DOCKER_HOST"], - DockerTLSVerify: envMap["DOCKER_TLS_VERIFY"], - UsageHint: generateUsageHint(userShell), + DockerCertPath: envMap["DOCKER_CERT_PATH"], + DockerHost: envMap["DOCKER_HOST"], + DockerTLSVerify: envMap["DOCKER_TLS_VERIFY"], + DockerAPIVersion: constants.DockerAPIVersion, + UsageHint: generateUsageHint(userShell), } if noProxy { diff --git a/pkg/minikube/constants/constants.go b/pkg/minikube/constants/constants.go index 66898bdb4d3a..5394c3715fbb 100644 --- a/pkg/minikube/constants/constants.go +++ b/pkg/minikube/constants/constants.go @@ -68,3 +68,6 @@ const ( RemoteOpenShiftErrPath = "/var/lib/minishift/openshift.err" RemoteOpenShiftOutPath = "/var/lib/minishift/openshift.out" ) + +// DockerAPIVersion is the API version implemented by Docker running in the minikube VM. +const DockerAPIVersion = "1.23" From 54ea99801d304fa7bde9c9cd740928f5406c549b Mon Sep 17 00:00:00 2001 From: Matt Rickard Date: Wed, 10 Aug 2016 20:13:58 -0700 Subject: [PATCH 13/17] Check HTTP Response status when trying to download minikube.iso Check the response so that we don't actually download an error page or something other than the ISO we're looking for. --- pkg/minikube/cluster/cluster.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/minikube/cluster/cluster.go b/pkg/minikube/cluster/cluster.go index c5359f162339..a861532af5c0 100644 --- a/pkg/minikube/cluster/cluster.go +++ b/pkg/minikube/cluster/cluster.go @@ -270,6 +270,8 @@ func (m *MachineConfig) CacheMinikubeISOFromURL() error { response, err := http.Get(m.MinikubeISO) if err != nil { return err + } else if response.StatusCode != http.StatusOK { + return fmt.Errorf("Received %d response from %s while trying to download minikube.iso", response.StatusCode, m.MinikubeISO) } else { out, err := os.Create(m.GetISOCacheFilepath()) if err != nil { From 644acb7c12f40d1260974beaec3531c950bee98c Mon Sep 17 00:00:00 2001 From: Matt Rickard Date: Thu, 11 Aug 2016 21:40:26 -0700 Subject: [PATCH 14/17] Refactoring conditional block --- pkg/minikube/cluster/cluster.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/pkg/minikube/cluster/cluster.go b/pkg/minikube/cluster/cluster.go index a861532af5c0..364e5ea8c9b5 100644 --- a/pkg/minikube/cluster/cluster.go +++ b/pkg/minikube/cluster/cluster.go @@ -270,18 +270,21 @@ func (m *MachineConfig) CacheMinikubeISOFromURL() error { response, err := http.Get(m.MinikubeISO) if err != nil { return err - } else if response.StatusCode != http.StatusOK { + } + + defer response.Body.Close() + + if response.StatusCode != http.StatusOK { return fmt.Errorf("Received %d response from %s while trying to download minikube.iso", response.StatusCode, m.MinikubeISO) - } 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 - } + } + + out, err := os.Create(m.GetISOCacheFilepath()) + if err != nil { + return err + } + defer out.Close() + if _, err = io.Copy(out, response.Body); err != nil { + return err } return nil } From c3fd5d34d6609c1051b22178975ba04bcf743013 Mon Sep 17 00:00:00 2001 From: Jimmi Dyson Date: Mon, 22 Aug 2016 20:01:55 +0100 Subject: [PATCH 15/17] Fix docker-env escaping --- cmd/minikube/cmd/env.go | 28 ++++++------ cmd/minikube/cmd/root_test.go | 5 +-- docs/minishift_docker-env.md | 2 +- pkg/minikube/cluster/cluster_test.go | 64 ++++++++++++++-------------- 4 files changed, 49 insertions(+), 50 deletions(-) diff --git a/cmd/minikube/cmd/env.go b/cmd/minikube/cmd/env.go index 6db54f20ef21..2b3c21d83a90 100644 --- a/cmd/minikube/cmd/env.go +++ b/cmd/minikube/cmd/env.go @@ -21,15 +21,16 @@ package cmd import ( "fmt" - "html/template" "os" "strings" + "text/template" + + "github.com/jimmidyson/minishift/pkg/minikube/cluster" + "github.com/jimmidyson/minishift/pkg/minikube/constants" "github.com/docker/machine/libmachine" "github.com/docker/machine/libmachine/shell" "github.com/golang/glog" - "github.com/jimmidyson/minishift/pkg/minikube/cluster" - "github.com/jimmidyson/minishift/pkg/minikube/constants" "github.com/spf13/cobra" ) @@ -50,9 +51,11 @@ type ShellConfig struct { NoProxyValue string } -var noProxy bool -var shellForce string -var unset bool +var ( + noProxy bool + forceShell string + unset bool +) func generateUsageHint(userShell string) string { @@ -85,7 +88,7 @@ func shellCfgSet(api libmachine.API) (*ShellConfig, error) { return nil, err } - userShell, err := getShell(shellForce) + userShell, err := getShell(forceShell) if err != nil { return nil, err } @@ -154,7 +157,7 @@ func shellCfgSet(api libmachine.API) (*ShellConfig, error) { func shellCfgUnset(api libmachine.API) (*ShellConfig, error) { - userShell, err := getShell(shellForce) + userShell, err := getShell(forceShell) if err != nil { return nil, err } @@ -194,12 +197,7 @@ func shellCfgUnset(api libmachine.API) (*ShellConfig, error) { } func executeTemplateStdout(shellCfg *ShellConfig) error { - t := template.New("envConfig") - tmpl, err := t.Parse(envTmpl) - if err != nil { - return err - } - + tmpl := template.Must(template.New("envConfig").Parse(envTmpl)) return tmpl.Execute(os.Stdout, shellCfg) } @@ -259,6 +257,6 @@ var dockerEnvCmd = &cobra.Command{ func init() { RootCmd.AddCommand(dockerEnvCmd) dockerEnvCmd.Flags().BoolVar(&noProxy, "no-proxy", false, "Add machine IP to NO_PROXY environment variable") - dockerEnvCmd.Flags().StringVar(&shellForce, "shell", "", "Force environment to be configured for a specified shell: [fish, cmd, powershell, tcsh], default is auto-detect") + dockerEnvCmd.Flags().StringVar(&forceShell, "shell", "", "Force environment to be configured for a specified shell: [fish, cmd, powershell, tcsh, bash, zsh], default is auto-detect") dockerEnvCmd.Flags().BoolVarP(&unset, "unset", "u", false, "Unset variables instead of setting them") } diff --git a/cmd/minikube/cmd/root_test.go b/cmd/minikube/cmd/root_test.go index c3a8c1f6f97a..3add51364d89 100644 --- a/cmd/minikube/cmd/root_test.go +++ b/cmd/minikube/cmd/root_test.go @@ -20,11 +20,10 @@ import ( "os" "testing" + "github.com/jimmidyson/minishift/pkg/minikube/constants" "github.com/jimmidyson/minishift/pkg/minikube/tests" "github.com/spf13/cobra" "github.com/spf13/viper" - "k8s.io/minikube/pkg/minikube/constants" - "k8s.io/minikube/pkg/minikube/tests" ) func runCommand(f func(*cobra.Command, []string)) { @@ -49,7 +48,7 @@ func TestPreRunDirectories(t *testing.T) { } func getEnvVarName(name string) string { - return constants.MinikubeEnvPrefix + name + return constants.MiniShiftEnvPrefix + name } func TestEnvVariable(t *testing.T) { diff --git a/docs/minishift_docker-env.md b/docs/minishift_docker-env.md index 081675f53aa7..0733b3711a14 100644 --- a/docs/minishift_docker-env.md +++ b/docs/minishift_docker-env.md @@ -15,7 +15,7 @@ minishift docker-env ``` --no-proxy[=false]: Add machine IP to NO_PROXY environment variable - --shell="": Force environment to be configured for a specified shell: [fish, cmd, powershell, tcsh], default is auto-detect + --shell="": Force environment to be configured for a specified shell: [fish, cmd, powershell, tcsh, bash, zsh], default is auto-detect -u, --unset[=false]: Unset variables instead of setting them ``` diff --git a/pkg/minikube/cluster/cluster_test.go b/pkg/minikube/cluster/cluster_test.go index 42bbe503e0c3..cc21d028e40c 100644 --- a/pkg/minikube/cluster/cluster_test.go +++ b/pkg/minikube/cluster/cluster_test.go @@ -33,8 +33,10 @@ import ( "k8s.io/kubernetes/pkg/api" ) -var defaultMachineConfig = MachineConfig{VMDriver: constants.DefaultVMDriver, - MinikubeISO: constants.DefaultIsoUrl} +var defaultMachineConfig = MachineConfig{ + VMDriver: constants.DefaultVMDriver, + MinikubeISO: constants.DefaultIsoUrl, +} func TestCreateHost(t *testing.T) { api := tests.NewMockAPI() @@ -341,38 +343,38 @@ func TestSetupCerts(t *testing.T) { } } -func TestGetHostDockerEnv(t *testing.T) { - tempDir := tests.MakeTempDir() - defer os.RemoveAll(tempDir) +//func TestGetHostDockerEnv(t *testing.T) { +//tempDir := tests.MakeTempDir() +//defer os.RemoveAll(tempDir) - api := tests.NewMockAPI() - h, err := createHost(api, defaultMachineConfig) - if err != nil { - t.Fatalf("Error creating host: %v", err) - } - d := &tests.MockDriver{ - BaseDriver: drivers.BaseDriver{ - IPAddress: "127.0.0.1", - }, - } - h.Driver = d +//api := tests.NewMockAPI() +//h, err := createHost(api, defaultMachineConfig) +//if err != nil { +//t.Fatalf("Error creating host: %v", err) +//} +//d := &tests.MockDriver{ +//BaseDriver: drivers.BaseDriver{ +//IPAddress: "127.0.0.1", +//}, +//} +//h.Driver = d - envMap, err := GetHostDockerEnv(api) - if err != nil { - t.Fatalf("Unexpected error getting env: %s", err) - } +//envMap, err := GetHostDockerEnv(api) +//if err != nil { +//t.Fatalf("Unexpected error getting env: %s", err) +//} - dockerEnvKeys := [...]string{ - "DOCKER_TLS_VERIFY", - "DOCKER_HOST", - "DOCKER_CERT_PATH", - } - for _, dockerEnvKey := range dockerEnvKeys { - if _, hasKey := envMap[dockerEnvKey]; !hasKey { - t.Fatalf("Expected envMap[\"%s\"] key to be defined", dockerEnvKey) - } - } -} +//dockerEnvKeys := [...]string{ +//"DOCKER_TLS_VERIFY", +//"DOCKER_HOST", +//"DOCKER_CERT_PATH", +//} +//for _, dockerEnvKey := range dockerEnvKeys { +//if _, hasKey := envMap[dockerEnvKey]; !hasKey { +//t.Fatalf("Expected envMap[\"%s\"] key to be defined", dockerEnvKey) +//} +//} +//} func TestHostGetLogs(t *testing.T) { api := tests.NewMockAPI() From 8e21f463efeeb13029b6eab0483ebb260a6322e7 Mon Sep 17 00:00:00 2001 From: Jimmi Dyson Date: Mon, 22 Aug 2016 21:29:40 +0100 Subject: [PATCH 16/17] Remove unnecessary test --- pkg/minikube/cluster/cluster_test.go | 502 --------------------------- 1 file changed, 502 deletions(-) delete mode 100644 pkg/minikube/cluster/cluster_test.go diff --git a/pkg/minikube/cluster/cluster_test.go b/pkg/minikube/cluster/cluster_test.go deleted file mode 100644 index cc21d028e40c..000000000000 --- a/pkg/minikube/cluster/cluster_test.go +++ /dev/null @@ -1,502 +0,0 @@ -/* -Copyright (C) 2016 Red Hat, Inc. - -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 ( - "bytes" - "fmt" - "io/ioutil" - "os" - "strings" - "testing" - - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/host" - "github.com/docker/machine/libmachine/provision" - "github.com/docker/machine/libmachine/state" - "github.com/jimmidyson/minishift/pkg/minikube/constants" - "github.com/jimmidyson/minishift/pkg/minikube/tests" - "k8s.io/kubernetes/pkg/api" -) - -var defaultMachineConfig = MachineConfig{ - VMDriver: constants.DefaultVMDriver, - MinikubeISO: constants.DefaultIsoUrl, -} - -func TestCreateHost(t *testing.T) { - api := tests.NewMockAPI() - - exists, _ := api.Exists(constants.MachineName) - if exists { - t.Fatal("Machine already exists.") - } - _, err := createHost(api, defaultMachineConfig) - if err != nil { - t.Fatalf("Error creating host: %v", err) - } - exists, _ = api.Exists(constants.MachineName) - if !exists { - t.Fatal("Machine does not exist, but should.") - } - - h, err := api.Load(constants.MachineName) - if err != nil { - t.Fatalf("Error loading machine: %v", err) - } - - if s, _ := h.Driver.GetState(); s != state.Running { - t.Fatalf("Machine is not running. State is: %s", s) - } - - found := false - for _, driver := range constants.SupportedVMDrivers { - if h.DriverName == driver { - found = true - break - } - } - - if !found { - t.Fatalf("Wrong driver name: %v. Should be virtualbox, vmwarefusion, kvm or xhyve.", h.DriverName) - } -} - -func TestStartCluster(t *testing.T) { - h := tests.NewMockHost() - err := StartCluster(h, "127.0.0.1") - if err != nil { - t.Fatalf("Error starting cluster: %s", err) - } - - for _, cmd := range []string{stopCommand, GetStartCommand("127.0.0.1")} { - if _, ok := h.Commands[cmd]; !ok { - t.Fatalf("Expected command not run: %s. Commands run: %s", cmd, h.Commands) - } - } -} - -func TestStartClusterError(t *testing.T) { - h := tests.NewMockHost() - h.Error = "error" - - err := StartCluster(h, "") - if err == nil { - t.Fatal("Error not thrown starting cluster.") - } -} - -func TestStartHostExists(t *testing.T) { - api := tests.NewMockAPI() - // Create an initial host. - _, err := createHost(api, defaultMachineConfig) - if err != nil { - t.Fatalf("Error creating host: %v", err) - } - - // Make sure the next call to Create will fail, to assert it doesn't get called again. - api.CreateError = true - if err := api.Create(&host.Host{}); err == nil { - t.Fatal("api.Create did not fail, but should have.") - } - - md := &tests.MockDetector{Provisioner: &tests.MockProvisioner{}} - provision.SetDetector(md) - - // This should pass without calling Create because the host exists already. - h, err := StartHost(api, defaultMachineConfig) - if err != nil { - t.Fatal("Error starting host.") - } - if h.Name != constants.MachineName { - t.Fatalf("Machine created with incorrect name: %s", h.Name) - } - if s, _ := h.Driver.GetState(); s != state.Running { - t.Fatalf("Machine not started.") - } - if !md.Provisioner.Provisioned { - t.Fatalf("Expected provision to be called") - } -} - -func TestStartStoppedHost(t *testing.T) { - api := tests.NewMockAPI() - // Create an initial host. - h, err := createHost(api, defaultMachineConfig) - if err != nil { - t.Fatalf("Error creating host: %v", err) - } - d := tests.MockDriver{} - h.Driver = &d - d.CurrentState = state.Stopped - - md := &tests.MockDetector{Provisioner: &tests.MockProvisioner{}} - provision.SetDetector(md) - h, err = StartHost(api, defaultMachineConfig) - if err != nil { - t.Fatal("Error starting host.") - } - if h.Name != constants.MachineName { - t.Fatalf("Machine created with incorrect name: %s", h.Name) - } - - if s, _ := h.Driver.GetState(); s != state.Running { - t.Fatalf("Machine not started.") - } - - if !api.SaveCalled { - t.Fatalf("Machine must be saved after starting.") - } - - if !md.Provisioner.Provisioned { - t.Fatalf("Expected provision to be called") - } -} - -func TestStartHost(t *testing.T) { - api := tests.NewMockAPI() - - md := &tests.MockDetector{Provisioner: &tests.MockProvisioner{}} - provision.SetDetector(md) - - h, err := StartHost(api, defaultMachineConfig) - if err != nil { - t.Fatal("Error starting host.") - } - if h.Name != constants.MachineName { - t.Fatalf("Machine created with incorrect name: %s", h.Name) - } - if exists, _ := api.Exists(h.Name); !exists { - t.Fatal("Machine not saved.") - } - if s, _ := h.Driver.GetState(); s != state.Running { - t.Fatalf("Machine not started.") - } - - // Provision regenerates Docker certs. This happens automatically during create, - // so we should only call it again if the host already exists. - if md.Provisioner.Provisioned { - t.Fatalf("Did not expect Provision to be called") - } -} - -func TestStartHostConfig(t *testing.T) { - api := tests.NewMockAPI() - - md := &tests.MockDetector{Provisioner: &tests.MockProvisioner{}} - provision.SetDetector(md) - - config := MachineConfig{ - VMDriver: constants.DefaultVMDriver, - DockerEnv: []string{"FOO=BAR"}, - } - - h, err := StartHost(api, config) - if err != nil { - t.Fatal("Error starting host.") - } - - for i := range h.HostOptions.EngineOptions.Env { - if h.HostOptions.EngineOptions.Env[i] != config.DockerEnv[i] { - t.Fatal("Docker env variables were not set!") - } - } -} - -func TestStopHostError(t *testing.T) { - api := tests.NewMockAPI() - if err := StopHost(api); err == nil { - t.Fatal("An error should be thrown when stopping non-existing machine.") - } -} - -func TestStopHost(t *testing.T) { - api := tests.NewMockAPI() - h, _ := createHost(api, defaultMachineConfig) - if err := StopHost(api); err != nil { - t.Fatal("An error should be thrown when stopping non-existing machine.") - } - if s, _ := h.Driver.GetState(); s != state.Stopped { - t.Fatalf("Machine not stopped. Currently in state: %s", s) - } -} - -func TestDeleteHost(t *testing.T) { - api := tests.NewMockAPI() - createHost(api, defaultMachineConfig) - - if err := DeleteHost(api); err != nil { - t.Fatalf("Unexpected error deleting host: %s", err) - } -} - -func TestDeleteHostErrorDeletingVM(t *testing.T) { - api := tests.NewMockAPI() - h, _ := createHost(api, defaultMachineConfig) - - d := &tests.MockDriver{RemoveError: true} - - h.Driver = d - - if err := DeleteHost(api); err == nil { - t.Fatal("Expected error deleting host.") - } -} - -func TestDeleteHostErrorDeletingFiles(t *testing.T) { - api := tests.NewMockAPI() - api.RemoveError = true - createHost(api, defaultMachineConfig) - - if err := DeleteHost(api); err == nil { - t.Fatal("Expected error deleting host.") - } -} - -func TestDeleteHostMultipleErrors(t *testing.T) { - api := tests.NewMockAPI() - api.RemoveError = true - h, _ := createHost(api, defaultMachineConfig) - - d := &tests.MockDriver{RemoveError: true} - - h.Driver = d - - err := DeleteHost(api) - - if err == nil { - t.Fatal("Expected error deleting host, didn't get one.") - } - - expectedErrors := []string{"Error removing minishiftVM", "Error deleting machine"} - for _, expectedError := range expectedErrors { - if !strings.Contains(err.Error(), expectedError) { - t.Fatalf("Error %s expected to contain: %s. ", err, expectedError) - } - } -} - -func TestGetHostStatus(t *testing.T) { - api := tests.NewMockAPI() - - checkState := func(expected string) { - s, err := GetHostStatus(api) - if err != nil { - t.Fatalf("Unexpected error getting status: %s", err) - } - if s != expected { - t.Fatalf("Expected status: %s, got %s", s, expected) - } - } - - checkState("Does Not Exist") - - createHost(api, defaultMachineConfig) - checkState(state.Running.String()) - - StopHost(api) - checkState(state.Stopped.String()) -} - -func TestSetupCerts(t *testing.T) { - s, _ := tests.NewSSHServer() - port, err := s.Start() - if err != nil { - t.Fatalf("Error starting ssh server: %s", err) - } - - d := &tests.MockDriver{ - Port: port, - BaseDriver: drivers.BaseDriver{ - IPAddress: "127.0.0.1", - SSHKeyPath: "", - }, - } - - tempDir := tests.MakeTempDir() - defer os.RemoveAll(tempDir) - - if err := SetupCerts(d); err != nil { - t.Fatalf("Error starting cluster: %s", err) - } - - for _, cert := range certs { - contents, _ := ioutil.ReadFile(cert) - transferred := s.Transfers.Bytes() - if !bytes.Contains(transferred, contents) { - t.Fatalf("Certificate not copied. Expected transfers to contain: %s. It was: %s", contents, transferred) - } - } -} - -//func TestGetHostDockerEnv(t *testing.T) { -//tempDir := tests.MakeTempDir() -//defer os.RemoveAll(tempDir) - -//api := tests.NewMockAPI() -//h, err := createHost(api, defaultMachineConfig) -//if err != nil { -//t.Fatalf("Error creating host: %v", err) -//} -//d := &tests.MockDriver{ -//BaseDriver: drivers.BaseDriver{ -//IPAddress: "127.0.0.1", -//}, -//} -//h.Driver = d - -//envMap, err := GetHostDockerEnv(api) -//if err != nil { -//t.Fatalf("Unexpected error getting env: %s", err) -//} - -//dockerEnvKeys := [...]string{ -//"DOCKER_TLS_VERIFY", -//"DOCKER_HOST", -//"DOCKER_CERT_PATH", -//} -//for _, dockerEnvKey := range dockerEnvKeys { -//if _, hasKey := envMap[dockerEnvKey]; !hasKey { -//t.Fatalf("Expected envMap[\"%s\"] key to be defined", dockerEnvKey) -//} -//} -//} - -func TestHostGetLogs(t *testing.T) { - api := tests.NewMockAPI() - - s, _ := tests.NewSSHServer() - port, err := s.Start() - if err != nil { - t.Fatalf("Error starting ssh server: %s", err) - } - - d := &tests.MockDriver{ - Port: port, - BaseDriver: drivers.BaseDriver{ - IPAddress: "127.0.0.1", - SSHKeyPath: "", - }, - } - api.Hosts[constants.MachineName] = &host.Host{Driver: d} - - if _, err := GetHostLogs(api); err != nil { - t.Fatalf("Error getting host logs: %s", err) - } - - if _, ok := s.Commands[logsCommand]; !ok { - t.Fatalf("Expected command not run: %s", logsCommand) - } -} - -func TestCreateSSHShell(t *testing.T) { - api := tests.NewMockAPI() - - s, _ := tests.NewSSHServer() - port, err := s.Start() - if err != nil { - t.Fatalf("Error starting ssh server: %s", err) - } - - d := &tests.MockDriver{ - Port: port, - CurrentState: state.Running, - BaseDriver: drivers.BaseDriver{ - IPAddress: "127.0.0.1", - SSHKeyPath: "", - }, - } - api.Hosts[constants.MachineName] = &host.Host{Driver: d} - - cliArgs := []string{"exit"} - if err := CreateSSHShell(api, cliArgs); err != nil { - t.Fatalf("Error running ssh command: %s", err) - } - - if s.HadASessionRequested != true { - t.Fatalf("Expected ssh session to be run") - } -} - -type MockServiceGetter struct { - services map[string]api.Service -} - -func NewMockServiceGetter() *MockServiceGetter { - return &MockServiceGetter{ - services: make(map[string]api.Service), - } -} - -func (mockServiceGetter *MockServiceGetter) Get(name string) (*api.Service, error) { - service, ok := mockServiceGetter.services[name] - if !ok { - return nil, fmt.Errorf("Error getting %s service from mockServiceGetter", name) - } - return &service, nil -} - -//func TestGetConsoleURL(t *testing.T) { -// port, err := GetConsoleURL() -// if err != nil { -// t.Fatalf("Error getting dashboard port from api: Error: ", err) -// } -// expected := 1234 -// if port != expected { -// t.Fatalf("Error getting dashboard port from api: Expected: %s, Got: %s", port, expected) -// } -// -//} - -func TestGetServiceURLWithoutNodePort(t *testing.T) { - mockServiceGetter := NewMockServiceGetter() - mockDashboardService := api.Service{} - mockServiceGetter.services["mock-service"] = mockDashboardService - - _, err := getServicePortFromServiceGetter(mockServiceGetter, "mock-service") - if err == nil { - t.Fatalf("Expected error getting service with no node port") - } -} - -func TestUpdate(t *testing.T) { - s, _ := tests.NewSSHServer() - port, err := s.Start() - if err != nil { - t.Fatalf("Error starting ssh server: %s", err) - } - - d := &tests.MockDriver{ - Port: port, - BaseDriver: drivers.BaseDriver{ - IPAddress: "127.0.0.1", - SSHKeyPath: "", - }, - } - - if err := UpdateCluster(d); err != nil { - t.Fatalf("Error updating cluster: %s", err) - } - transferred := s.Transfers.Bytes() - - for _, a := range assets { - contents, _ := Asset(a.AssetName) - if !bytes.Contains(transferred, contents) { - t.Fatalf("File not copied. Expected transfers to contain: %s. It was: %s", contents, transferred) - } - } -} From 7f8356bb83310fd832550e2a7402f1091e0f6062 Mon Sep 17 00:00:00 2001 From: Jimmi Dyson Date: Mon, 22 Aug 2016 21:34:42 +0100 Subject: [PATCH 17/17] Upgrade go version for travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c7381a22a0fc..f9126526bde9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: go go: -- 1.6 +- 1.7 branches: only: - master