From d3855d4b096e67310c83162aa91f845a07074da0 Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Wed, 12 Jun 2019 10:44:04 -0700 Subject: [PATCH 1/3] adding retriable http get --- go.mod | 1 + go.sum | 4 +++ test/integration/version_upgrade_test.go | 42 +++++++++++++++--------- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index 0c945638eb..0768b42129 100644 --- a/go.mod +++ b/go.mod @@ -31,6 +31,7 @@ require ( github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce // indirect github.com/hashicorp/go-multierror v0.0.0-20160811015721-8c5f0ad93604 // indirect + github.com/hashicorp/go-retryablehttp v0.5.4 github.com/hashicorp/go-version v1.1.0 // indirect github.com/hashicorp/golang-lru v0.0.0-20160207214719-a0d98a5f2880 // indirect github.com/hashicorp/hcl v0.0.0-20160711231752-d8c773c4cba1 // indirect diff --git a/go.sum b/go.sum index a786e141e2..0632dc68dc 100644 --- a/go.sum +++ b/go.sum @@ -64,8 +64,12 @@ github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 h1:pdN6V1QBWet github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce h1:prjrVgOk2Yg6w+PflHoszQNLTUh4kaByUcEWM/9uin4= github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-cleanhttp v0.5.0 h1:wvCrVc9TjDls6+YGAF2hAifE1E5U1+b4tH6KdvN3Gig= +github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-multierror v0.0.0-20160811015721-8c5f0ad93604 h1:VIq8E7fMiC4h3agg0ya56L0jHn7QisZZcWZXVKJb9jQ= github.com/hashicorp/go-multierror v0.0.0-20160811015721-8c5f0ad93604/go.mod h1:JMRHfdO9jKNzS/+BTlxCjKNQHg/jZAft8U7LloJvN7I= +github.com/hashicorp/go-retryablehttp v0.5.4 h1:1BZvpawXoJCWX6pNtow9+rpEj+3itIlutiqnntI6jOE= +github.com/hashicorp/go-retryablehttp v0.5.4/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= github.com/hashicorp/go-version v1.1.0 h1:bPIoEKD27tNdebFGGxxYwcL4nepeY4j1QP23PFRGzg0= github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/golang-lru v0.0.0-20160207214719-a0d98a5f2880 h1:OaRuzt9oCKNui8cCskZijoKUwe+aCuuCwvx1ox8FNyw= diff --git a/test/integration/version_upgrade_test.go b/test/integration/version_upgrade_test.go index 08372e8f07..61f01fd307 100644 --- a/test/integration/version_upgrade_test.go +++ b/test/integration/version_upgrade_test.go @@ -20,49 +20,61 @@ import ( "fmt" "io" "io/ioutil" - "net/http" "os" "runtime" "testing" "github.com/docker/machine/libmachine/state" + retryablehttp "github.com/hashicorp/go-retryablehttp" "github.com/pkg/errors" "k8s.io/minikube/pkg/minikube/constants" pkgutil "k8s.io/minikube/pkg/util" ) -func TestVersionUpgrade(t *testing.T) { - currentRunner := NewMinikubeRunner(t) - currentRunner.RunCommand("delete", true) - currentRunner.CheckStatus(state.None.String()) - +func downloadMinikubeBinary(version string) (*os.File, error) { // Grab latest release binary - url := pkgutil.GetBinaryDownloadURL("latest", runtime.GOOS) - resp, err := http.Get(url) + url := pkgutil.GetBinaryDownloadURL(version, runtime.GOOS) + resp, err := retryablehttp.Get(url) if err != nil { - t.Fatal(errors.Wrap(err, "Failed to get latest release binary")) + return nil, err + // t.Fatal(errors.Wrap(err, "Failed to get latest release binary")) } defer resp.Body.Close() tf, err := ioutil.TempFile("", "minikube") if err != nil { - t.Fatal(errors.Wrap(err, "Failed to create binary file")) + return nil, err + // t.Fatal(errors.Wrap(err, "Failed to create binary file")) } - defer os.Remove(tf.Name()) - _, err = io.Copy(tf, resp.Body) if err != nil { - t.Fatal(errors.Wrap(err, "Failed to populate temp file")) + return nil, err + // t.Fatal(errors.Wrap(err, "Failed to populate temp file")) } if err := tf.Close(); err != nil { - t.Fatal(errors.Wrap(err, "Failed to close temp file")) + return nil, err + // t.Fatal(errors.Wrap(err, "Failed to close temp file")) } if runtime.GOOS != "windows" { if err := os.Chmod(tf.Name(), 0700); err != nil { - t.Fatal(errors.Wrap(err, "Failed to make binary executable.")) + return nil, err + // t.Fatal(errors.Wrap(err, "Failed to make binary executable.")) } } + return tf, err +} + +// TestVersionUpgrade downloads latest version of minikube and runs with +// the odlest supported k8s version and then runs the current head minikube +// and it tries to upgrade from the older supported k8s to news supported k8s +func TestVersionUpgrade(t *testing.T) { + currentRunner := NewMinikubeRunner(t) + currentRunner.RunCommand("delete", true) + currentRunner.CheckStatus(state.None.String()) + tf, err := downloadMinikubeBinary("latest") + t.Fatal(errors.Wrap(err, "Failed to download minikube binary.")) + defer os.Remove(tf.Name()) releaseRunner := NewMinikubeRunner(t) releaseRunner.BinaryPath = tf.Name() From 68b5ed9916f76113aec8b2a0a2cc1edec0d94af3 Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Wed, 12 Jun 2019 11:15:34 -0700 Subject: [PATCH 2/3] check error --- test/integration/version_upgrade_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/integration/version_upgrade_test.go b/test/integration/version_upgrade_test.go index 61f01fd307..301774ea50 100644 --- a/test/integration/version_upgrade_test.go +++ b/test/integration/version_upgrade_test.go @@ -73,7 +73,9 @@ func TestVersionUpgrade(t *testing.T) { currentRunner.RunCommand("delete", true) currentRunner.CheckStatus(state.None.String()) tf, err := downloadMinikubeBinary("latest") - t.Fatal(errors.Wrap(err, "Failed to download minikube binary.")) + if err != nil || tf == nil { + t.Fatal(errors.Wrap(err, "Failed to download minikube binary.")) + } defer os.Remove(tf.Name()) releaseRunner := NewMinikubeRunner(t) From 657469310c9b9eddc36d1c41c642c5626288e5e2 Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Thu, 13 Jun 2019 22:50:26 -0700 Subject: [PATCH 3/3] Use retryable http to avoid connection flakes --- deploy/minikube/release_sanity_test.go | 4 ++-- pkg/util/utils.go | 3 ++- test/integration/addons_test.go | 3 ++- test/integration/proxy_test.go | 4 +++- test/integration/version_upgrade_test.go | 12 ++++-------- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/deploy/minikube/release_sanity_test.go b/deploy/minikube/release_sanity_test.go index 38cc2f907f..53e8d46a68 100644 --- a/deploy/minikube/release_sanity_test.go +++ b/deploy/minikube/release_sanity_test.go @@ -23,9 +23,9 @@ import ( "encoding/hex" "fmt" "io/ioutil" - "net/http" "testing" + retryablehttp "github.com/hashicorp/go-retryablehttp" "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/notify" "k8s.io/minikube/pkg/util" @@ -33,7 +33,7 @@ import ( func getSHAFromURL(url string) (string, error) { fmt.Println("Downloading: ", url) - r, err := http.Get(url) + r, err := retryablehttp.Get(url) if err != nil { return "", err } diff --git a/pkg/util/utils.go b/pkg/util/utils.go index 0f2fc50399..fb062820ab 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -32,6 +32,7 @@ import ( units "github.com/docker/go-units" "github.com/golang/glog" + retryablehttp "github.com/hashicorp/go-retryablehttp" "github.com/pkg/errors" ) @@ -130,7 +131,7 @@ func RetryAfter(attempts int, callback func() error, d time.Duration) (err error // ParseSHAFromURL downloads and reads a SHA checksum from an URL func ParseSHAFromURL(url string) (string, error) { - r, err := http.Get(url) + r, err := retryablehttp.Get(url) if err != nil { return "", errors.Wrap(err, "Error downloading checksum.") } else if r.StatusCode != http.StatusOK { diff --git a/test/integration/addons_test.go b/test/integration/addons_test.go index 682cffdc2f..85b56a1c71 100644 --- a/test/integration/addons_test.go +++ b/test/integration/addons_test.go @@ -32,6 +32,7 @@ import ( "time" "github.com/docker/machine/libmachine/state" + retryablehttp "github.com/hashicorp/go-retryablehttp" "k8s.io/apimachinery/pkg/labels" pkgutil "k8s.io/minikube/pkg/util" "k8s.io/minikube/test/integration/util" @@ -105,7 +106,7 @@ func testDashboard(t *testing.T) { t.Errorf("got host %s, expected 127.0.0.1", host) } - resp, err := http.Get(u.String()) + resp, err := retryablehttp.Get(u.String()) if err != nil { t.Fatalf("failed get: %v", err) } diff --git a/test/integration/proxy_test.go b/test/integration/proxy_test.go index 7896e3e8df..7172528cbe 100644 --- a/test/integration/proxy_test.go +++ b/test/integration/proxy_test.go @@ -31,6 +31,7 @@ import ( "net/url" "github.com/elazarl/goproxy" + retryablehttp "github.com/hashicorp/go-retryablehttp" "github.com/phayes/freeport" "github.com/pkg/errors" ) @@ -148,7 +149,8 @@ func testProxyDashboard(t *testing.T) { if err != nil { t.Fatalf("failed to parse %q: %v", s, err) } - resp, err := http.Get(u.String()) + + resp, err := retryablehttp.Get(u.String()) if err != nil { t.Fatalf("failed get: %v", err) } diff --git a/test/integration/version_upgrade_test.go b/test/integration/version_upgrade_test.go index 301774ea50..53e32deb4e 100644 --- a/test/integration/version_upgrade_test.go +++ b/test/integration/version_upgrade_test.go @@ -36,24 +36,20 @@ func downloadMinikubeBinary(version string) (*os.File, error) { url := pkgutil.GetBinaryDownloadURL(version, runtime.GOOS) resp, err := retryablehttp.Get(url) if err != nil { - return nil, err - // t.Fatal(errors.Wrap(err, "Failed to get latest release binary")) + return nil, errors.Wrap(err, "Failed to get latest release binary") } defer resp.Body.Close() tf, err := ioutil.TempFile("", "minikube") if err != nil { - return nil, err - // t.Fatal(errors.Wrap(err, "Failed to create binary file")) + return nil, errors.Wrap(err, "Failed to create binary file") } _, err = io.Copy(tf, resp.Body) if err != nil { - return nil, err - // t.Fatal(errors.Wrap(err, "Failed to populate temp file")) + return nil, errors.Wrap(err, "Failed to populate temp file") } if err := tf.Close(); err != nil { - return nil, err - // t.Fatal(errors.Wrap(err, "Failed to close temp file")) + return nil, errors.Wrap(err, "Failed to close temp file") } if runtime.GOOS != "windows" {