From d84f62f0614e99a877cd1fa6c8d48bb4c5315000 Mon Sep 17 00:00:00 2001 From: balopat Date: Thu, 10 Oct 2019 13:42:08 -0700 Subject: [PATCH 1/2] not using github API for the checks to avoid rate limit --- hack/versions/pkg/version/version.go | 10 ++++----- pkg/skaffold/update/update.go | 32 +++++++++++++++++----------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/hack/versions/pkg/version/version.go b/hack/versions/pkg/version/version.go index f045b9f319c..1a119b71e45 100644 --- a/hack/versions/pkg/version/version.go +++ b/hack/versions/pkg/version/version.go @@ -17,15 +17,15 @@ limitations under the License. package version import ( - "context" "fmt" "io/ioutil" "net/http" "regexp" "strings" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/update" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" - "github.com/google/go-github/github" "github.com/sirupsen/logrus" ) @@ -40,12 +40,10 @@ func GetLatestVersion() (string, bool) { } func getLastReleasedConfigVersion() string { - client := github.NewClient(nil) - releases, _, err := client.Repositories.ListReleases(context.Background(), "GoogleContainerTools", "skaffold", &github.ListOptions{}) + lastTag, err := update.DownloadLatestVersion() if err != nil { - logrus.Fatalf("error listing Github releases: %s", err) + logrus.Fatalf("error getting latest version: %s", err) } - lastTag := *releases[0].TagName logrus.Infof("last release tag: %s", lastTag) configURL := fmt.Sprintf("https://raw.githubusercontent.com/GoogleContainerTools/skaffold/%s/pkg/skaffold/schema/latest/config.go", lastTag) resp, err := http.Get(configURL) diff --git a/pkg/skaffold/update/update.go b/pkg/skaffold/update/update.go index 7fdbee0875e..d63e18b94d9 100644 --- a/pkg/skaffold/update/update.go +++ b/pkg/skaffold/update/update.go @@ -36,7 +36,7 @@ var ( getEnv = os.Getenv ) -const latestVersionURL = "https://storage.googleapis.com/skaffold/releases/latest/VERSION" +const LatestVersionURL = "https://storage.googleapis.com/skaffold/releases/latest/VERSION" // IsUpdateCheckEnabled returns whether or not the update check is enabled // It is true by default, but setting it to any other value than true will disable the check @@ -60,19 +60,11 @@ func isUpdateCheckEnabledByEnvOrConfig(configfile string) bool { // and returns it with the current version of Skaffold func getLatestAndCurrentVersion() (semver.Version, semver.Version, error) { none := semver.Version{} - resp, err := http.Get(latestVersionURL) + versionString, err := DownloadLatestVersion() if err != nil { - return none, none, errors.Wrap(err, "getting latest version info from GCS") + return none, none, err } - defer resp.Body.Close() - if resp.StatusCode != http.StatusOK { - return none, none, errors.Wrapf(err, "http %d, error: %s", resp.StatusCode, resp.Status) - } - versionBytes, err := ioutil.ReadAll(resp.Body) - if err != nil { - return none, none, errors.Wrap(err, "reading version file from GCS") - } - latest, err := version.ParseVersion(string(versionBytes)) + latest, err := version.ParseVersion(versionString) if err != nil { return none, none, errors.Wrap(err, "parsing latest version from GCS") } @@ -82,3 +74,19 @@ func getLatestAndCurrentVersion() (semver.Version, semver.Version, error) { } return latest, current, nil } + +func DownloadLatestVersion() (string, error) { + resp, err := http.Get(LatestVersionURL) + if err != nil { + return "", errors.Wrap(err, "getting latest version info from GCS") + } + defer resp.Body.Close() + if resp.StatusCode != http.StatusOK { + return "", errors.Wrapf(err, "http %d, error: %s", resp.StatusCode, resp.Status) + } + versionBytes, err := ioutil.ReadAll(resp.Body) + if err != nil { + return "", errors.Wrap(err, "reading version file from GCS") + } + return string(versionBytes), nil +} From 89a10e12250fc6fdd52c0e8f3dc747651100a60a Mon Sep 17 00:00:00 2001 From: balopat Date: Thu, 10 Oct 2019 13:50:02 -0700 Subject: [PATCH 2/2] remove new line --- pkg/skaffold/update/update.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/skaffold/update/update.go b/pkg/skaffold/update/update.go index d63e18b94d9..0f71520a235 100644 --- a/pkg/skaffold/update/update.go +++ b/pkg/skaffold/update/update.go @@ -88,5 +88,5 @@ func DownloadLatestVersion() (string, error) { if err != nil { return "", errors.Wrap(err, "reading version file from GCS") } - return string(versionBytes), nil + return strings.TrimSuffix(string(versionBytes), "\n"), nil }