Refactored localkube url/asset code, fixed url.Parse code, updated flag
help message to add URI information, updated docs, fixed unused vars and removed unneeded commentspull/239/head
parent
b3fe5faae6
commit
0b1cfce102
|
@ -169,6 +169,6 @@ func init() {
|
|||
diskFlag.DefValue = constants.DefaultDiskSize
|
||||
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().StringVar(&kubernetesVersion, "kubernetes-version", constants.DefaultKubernetesVersion, "The kubernetes version that the minikube VM will run")
|
||||
startCmd.Flags().StringVar(&kubernetesVersion, "kubernetes-version", constants.DefaultKubernetesVersion, "The kubernetes version that the minikube VM will (ex: v1.2.3) \n OR a URI which contains a localkube binary (ex: https://storage.googleapis.com/minikube/k8sReleases/v1.3.0/localkube-linux-amd64)")
|
||||
RootCmd.AddCommand(startCmd)
|
||||
}
|
||||
|
|
|
@ -20,7 +20,8 @@ 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.3": The kubernetes version that the minikube VM will run
|
||||
--kubernetes-version="v1.3.3": The kubernetes version that the minikube VM will (ex: v1.2.3)
|
||||
OR a URI which contains a localkube binary (ex: https://storage.googleapis.com/minikube/k8sReleases/v1.3.0/localkube-linux-amd64)
|
||||
--memory=1024: Amount of RAM allocated to the minikube VM
|
||||
--vm-driver="virtualbox": VM driver is one of: [virtualbox vmwarefusion kvm xhyve]
|
||||
```
|
||||
|
|
|
@ -19,6 +19,7 @@ package cluster
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -37,6 +38,7 @@ import (
|
|||
"github.com/docker/machine/libmachine/host"
|
||||
"github.com/docker/machine/libmachine/state"
|
||||
"github.com/golang/glog"
|
||||
"golang.org/x/crypto/ssh"
|
||||
kubeApi "k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/client/unversioned"
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
|
||||
|
@ -49,8 +51,6 @@ 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
|
||||
|
@ -229,15 +229,40 @@ 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
|
||||
func updateLocalkubeFromURL(config KubernetesConfig, client *ssh.Client) error {
|
||||
resp := &http.Response{}
|
||||
err := errors.New("")
|
||||
downloader := func() (err error) {
|
||||
url, err := util.GetLocalkubeDownloadURL(config.KubernetesVersion,
|
||||
constants.LocalkubeLinuxFilename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resp, err = http.Get(url)
|
||||
return err
|
||||
}
|
||||
|
||||
if err = util.Retry(5, downloader); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = sshutil.Transfer(resp.Body, int(resp.ContentLength), "/usr/local/bin",
|
||||
"localkube", "0777", client); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func updateLocalkubeFromAsset(client *ssh.Client) error {
|
||||
contents, err := Asset("out/localkube")
|
||||
if err != nil {
|
||||
glog.Infof("Error loading asset out/localkube: %s", err)
|
||||
return err
|
||||
}
|
||||
if err := sshutil.Transfer(bytes.NewReader(contents), len(contents), "/usr/local/bin",
|
||||
"localkube", "0777", client); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func UpdateCluster(h sshAble, d drivers.Driver, config KubernetesConfig) error {
|
||||
|
@ -246,23 +271,11 @@ func UpdateCluster(h sshAble, d drivers.Driver, config KubernetesConfig) error {
|
|||
return err
|
||||
}
|
||||
if localkubeURLWasSpecified(config) {
|
||||
resp := &http.Response{}
|
||||
f := localkubeDownloader(resp, config)
|
||||
if err := util.Retry(5, f); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := sshutil.Transfer(resp.Body, int(resp.ContentLength), "/usr/local/bin",
|
||||
"localkube", "0777", client); err != nil {
|
||||
if err = updateLocalkubeFromURL(config, client); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
contents, err := Asset("out/localkube")
|
||||
if err != nil {
|
||||
glog.Infof("Error loading asset out/localkube: %s", err)
|
||||
return err
|
||||
}
|
||||
if err := sshutil.Transfer(bytes.NewReader(contents), len(contents), "/usr/local/bin",
|
||||
"localkube", "0777", client); err != nil {
|
||||
if err = updateLocalkubeFromAsset(client); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -282,7 +295,7 @@ func UpdateCluster(h sshAble, d drivers.Driver, config KubernetesConfig) error {
|
|||
}
|
||||
|
||||
func localkubeURLWasSpecified(config KubernetesConfig) bool {
|
||||
//see if flag is different than default -> it was passed by user
|
||||
// see if flag is different than default -> it was passed by user
|
||||
return config.KubernetesVersion != constants.DefaultKubernetesVersion
|
||||
}
|
||||
|
||||
|
|
|
@ -81,15 +81,19 @@ func RetryAfter(attempts int, callback func() error, d time.Duration) (err error
|
|||
return err
|
||||
}
|
||||
|
||||
func GetLocalkubeDownloadURL(versionOrURL string, filename string) string {
|
||||
if _, err := url.Parse(versionOrURL); err == nil {
|
||||
//input was a fully qualified URL/file-URI to a localkube binary
|
||||
return versionOrURL
|
||||
func GetLocalkubeDownloadURL(versionOrURL string, filename string) (string, error) {
|
||||
urlObj, err := url.Parse(versionOrURL)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if urlObj.IsAbs() {
|
||||
// scheme was specified in input, is a valid URI.
|
||||
// http.Get will catch unsupported schemes
|
||||
return versionOrURL, nil
|
||||
}
|
||||
//input was a version string for a localkube binary -- ex: v1.3.0 OR 1.3.0
|
||||
if !strings.HasPrefix(versionOrURL, "v") {
|
||||
//if the input version had no 'v' prefix, prepend it
|
||||
// no 'v' prefix in input, need to prepend it to version
|
||||
versionOrURL = "v" + versionOrURL
|
||||
}
|
||||
return fmt.Sprintf("%s%s/%s", constants.LocalkubeDownloadURLPrefix, versionOrURL, filename)
|
||||
return fmt.Sprintf("%s%s/%s", constants.LocalkubeDownloadURLPrefix, versionOrURL, filename), nil
|
||||
}
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
hello
|
Loading…
Reference in New Issue