Cleaned up start flags, added more robust URL checking for localkube

flag URL and added check to prepend 'v' to version # if it is missing
pull/239/head
Aaron Prindle 2016-07-20 10:10:03 -07:00
parent bd4e244ce8
commit b3fe5faae6
6 changed files with 20 additions and 19 deletions

View File

@ -161,14 +161,14 @@ func setupKubeconfig(name, server, certAuth, cliCert, cliKey string) error {
}
func init() {
startCmd.Flags().StringVarP(&minikubeISO, "iso-url", "", constants.DefaultIsoUrl, "Location of the minikube iso")
startCmd.Flags().StringVarP(&vmDriver, "vm-driver", "", constants.DefaultVMDriver, fmt.Sprintf("VM driver is one of: %v", constants.SupportedVMDrivers))
startCmd.Flags().IntVarP(&memory, "memory", "", constants.DefaultMemory, "Amount of RAM allocated to the minikube VM")
startCmd.Flags().IntVarP(&cpus, "cpus", "", constants.DefaultCPUS, "Number of CPUs allocated to the minikube VM")
startCmd.Flags().StringVar(&minikubeISO, "iso-url", constants.DefaultIsoUrl, "Location of the minikube iso")
startCmd.Flags().StringVar(&vmDriver, "vm-driver", constants.DefaultVMDriver, fmt.Sprintf("VM driver is one of: %v", constants.SupportedVMDrivers))
startCmd.Flags().IntVar(&memory, "memory", constants.DefaultMemory, "Amount of RAM allocated to the minikube VM")
startCmd.Flags().IntVar(&cpus, "cpus", constants.DefaultCPUS, "Number of CPUs allocated to the minikube VM")
diskFlag := startCmd.Flags().VarPF(disk, "disk-size", "", "Disk size allocated to the minikube VM (format: <number>[<unit>], where unit = b, k, m or g)")
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().StringVarP(&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 run")
RootCmd.AddCommand(startCmd)
}

View File

@ -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": The kubernetes version that the minikube VM will run
--kubernetes-version="v1.3.3": 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]
```

View File

@ -236,7 +236,6 @@ func localkubeDownloader(resp *http.Response, config KubernetesConfig) func() er
constants.LocalkubeLinuxFilename))
resp.Body = tmpResp.Body
resp.ContentLength = tmpResp.ContentLength
fmt.Println(int(resp.ContentLength))
return err
}
}
@ -252,7 +251,6 @@ func UpdateCluster(h sshAble, d drivers.Driver, config KubernetesConfig) error {
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 {
return err

View File

@ -545,12 +545,12 @@ func TestUpdateDefault(t *testing.T) {
}
}
var test_localkube_binary = "hello"
var testLocalkubeBin = "hello"
type K8sVersionHandlerCorrect struct{}
func (h *K8sVersionHandlerCorrect) ServeHTTP(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, test_localkube_binary)
io.WriteString(w, testLocalkubeBin)
}
func TestUpdateKubernetesVersion(t *testing.T) {
@ -574,14 +574,13 @@ func TestUpdateKubernetesVersion(t *testing.T) {
kubernetesConfig := KubernetesConfig{
KubernetesVersion: server.URL,
}
if err := UpdateCluster(h, d, kubernetesConfig); err != nil {
t.Fatalf("Error updating cluster: %s", err)
}
transferred := s.Transfers.Bytes()
//test that localkube is transferred properly
contents := []byte(test_localkube_binary)
contents := []byte(testLocalkubeBin)
if !bytes.Contains(transferred, contents) {
t.Fatalf("File not copied. Expected transfers to contain: %s. It was: %s", contents, transferred)
}

View File

@ -66,11 +66,8 @@ const (
RemoteLocalKubeErrPath = "/var/lib/localkube/localkube.err"
RemoteLocalKubeOutPath = "/var/lib/localkube/localkube.out"
)
<<<<<<< 77c0a09495682fa6ae6a74f0363053d2330e86be
=======
var ConfigFilePath = MakeMiniPath("config")
var LocalkubeDownloadURLPrefix = "https://storage.googleapis.com/minikube/k8sReleases/"
var LocalkubeLinuxFilename = "localkube-linux-amd64"
>>>>>>> Changed kubernetes-version to take k8s version as input (as well as

View File

@ -19,6 +19,7 @@ package util
import (
"fmt"
"io"
"net/url"
"os"
"strings"
"time"
@ -80,9 +81,15 @@ func RetryAfter(attempts int, callback func() error, d time.Duration) (err error
return err
}
func GetLocalkubeDownloadURL(version string, filename string) string {
if strings.HasPrefix(version, "http://") {
return version
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
}
return fmt.Sprintf("%s%s/%s", constants.LocalkubeDownloadURLPrefix, version, filename)
//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
versionOrURL = "v" + versionOrURL
}
return fmt.Sprintf("%s%s/%s", constants.LocalkubeDownloadURLPrefix, versionOrURL, filename)
}