Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding retriable http get #4474

Merged
merged 3 commits into from
Jun 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions deploy/minikube/release_sanity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ 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"
)

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
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
3 changes: 2 additions & 1 deletion pkg/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion test/integration/addons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion test/integration/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}
Expand Down
40 changes: 25 additions & 15 deletions test/integration/version_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,49 +20,59 @@ 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, 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, 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, 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, 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")
if err != nil || tf == nil {
t.Fatal(errors.Wrap(err, "Failed to download minikube binary."))
}
defer os.Remove(tf.Name())

releaseRunner := NewMinikubeRunner(t)
releaseRunner.BinaryPath = tf.Name()
Expand Down