From bd4e244ce8a7bad35d01867f200f4cb685dbd5b6 Mon Sep 17 00:00:00 2001 From: Aaron Prindle Date: Thu, 14 Jul 2016 14:31:52 -0700 Subject: [PATCH] Updated docs. Added retrying for the localkube download. --- Makefile | 2 +- cmd/minikube/cmd/start.go | 15 ++++++++------- docs/minikube_start.md | 2 +- pkg/minikube/cluster/cluster.go | 25 +++++++++++++++++++------ pkg/minikube/constants/constants.go | 2 -- pkg/util/utils.go | 1 + 6 files changed, 30 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 3259f552de..8728a95019 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ BUILD_OS := $(shell uname -s) # Set the version information for the Kubernetes servers, and build localkube statically K8S_VERSION_LDFLAGS := $(shell $(PYTHON) hack/get_k8s_version.py 2>&1) -MINIKUBE_LDFLAGS := -X k8s.io/minikube/pkg/version.version=$(VERSION) $(K8S_VERSION_LDFLAGS) +MINIKUBE_LDFLAGS := -X k8s.io/minikube/pkg/version.version=$(VERSION) LOCALKUBE_LDFLAGS := "$(K8S_VERSION_LDFLAGS) $(MINIKUBE_LDFLAGS) -s -w -extldflags '-static'" MKGOPATH := if [ ! -e $(GOPATH)/src/$(ORG) ]; then mkdir -p $(GOPATH)/src/$(ORG) && ln -s -f $(shell pwd) $(GOPATH)/src/$(ORG); fi diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 0d801f5500..c8103dce94 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -35,13 +35,14 @@ import ( ) var ( - minikubeISO string - memory int - cpus int - disk = newUnitValue(20 * units.GB) - vmDriver string - dockerEnv []string - insecureRegistry []string + minikubeISO string + memory int + cpus int + disk = newUnitValue(20 * units.GB) + vmDriver string + dockerEnv []string + insecureRegistry []string + kubernetesVersion string ) // startCmd represents the start command diff --git a/docs/minikube_start.md b/docs/minikube_start.md index bdf174b358..781d31186f 100644 --- a/docs/minikube_start.md +++ b/docs/minikube_start.md @@ -20,7 +20,7 @@ minikube start --docker-env=[]: Environment variables to pass to the Docker daemon. (format: key=value) --insecure-registry=[]: Insecure Docker registries to pass to the Docker daemon --iso-url="https://storage.googleapis.com/minikube/minikube-0.5.iso": Location of the minikube iso - --kubernetes-version="v1.3.0+$Format:%h$": The kubernetes version that the minikube VM will run + --kubernetes-version="v1.3.0": The kubernetes version that the minikube VM will run --memory=1024: Amount of RAM allocated to the minikube VM --vm-driver="virtualbox": VM driver is one of: [virtualbox vmwarefusion kvm xhyve] ``` diff --git a/pkg/minikube/cluster/cluster.go b/pkg/minikube/cluster/cluster.go index f65e3442e9..a61b6cab4b 100644 --- a/pkg/minikube/cluster/cluster.go +++ b/pkg/minikube/cluster/cluster.go @@ -49,6 +49,8 @@ var ( certs = []string{"ca.crt", "ca.key", "apiserver.crt", "apiserver.key"} ) +var numRetries = 5 + //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 @@ -227,23 +229,34 @@ var assets = []fileToCopy{ }, } +// Returns a function that will return n errors, then return successfully forever. +func localkubeDownloader(resp *http.Response, config KubernetesConfig) func() error { + return func() (err error) { + tmpResp, err := http.Get(util.GetLocalkubeDownloadURL(config.KubernetesVersion, + constants.LocalkubeLinuxFilename)) + resp.Body = tmpResp.Body + resp.ContentLength = tmpResp.ContentLength + fmt.Println(int(resp.ContentLength)) + return err + } +} + func UpdateCluster(h sshAble, d drivers.Driver, config KubernetesConfig) error { client, err := sshutil.NewSSHClient(d) if err != nil { return err } if localkubeURLWasSpecified(config) { - resp, err := http.Get(util.GetLocalkubeDownloadURL(config.KubernetesVersion, - constants.LocalkubeLinuxFilename)) - if err != nil { + resp := &http.Response{} + f := localkubeDownloader(resp, config) + if err := util.Retry(5, f); err != nil { return err } + fmt.Println(int(resp.ContentLength)) if err := sshutil.Transfer(resp.Body, int(resp.ContentLength), "/usr/local/bin", - "localkube", "0777", - client); err != nil { + "localkube", "0777", client); err != nil { return err } - } else { contents, err := Asset("out/localkube") if err != nil { diff --git a/pkg/minikube/constants/constants.go b/pkg/minikube/constants/constants.go index 940987b754..5f9eb86630 100644 --- a/pkg/minikube/constants/constants.go +++ b/pkg/minikube/constants/constants.go @@ -17,9 +17,7 @@ limitations under the License. package constants import ( - "fmt" "path/filepath" - "strings" "k8s.io/kubernetes/pkg/client/unversioned/clientcmd" "k8s.io/kubernetes/pkg/util/homedir" diff --git a/pkg/util/utils.go b/pkg/util/utils.go index 7d3d08e7b3..fcd2bee14b 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -20,6 +20,7 @@ import ( "fmt" "io" "os" + "strings" "time" "k8s.io/minikube/pkg/minikube/constants"