func TestK8sReleases(t *testing.T) { releases, err := kubernetes_versions.GetK8sVersionsFromURL(constants.KubernetesVersionGCSURL) if err != nil { t.Fatalf("Error getting k8s_releases.json: %s", err) } for _, r := range releases { fmt.Printf("Checking release: %s\n", r.Version) url, err := util.GetLocalkubeDownloadURL(r.Version, constants.LocalkubeLinuxFilename) if err != nil { t.Errorf("Error getting URL for %s. Error: %s", r.Version, err) continue } shaURL := fmt.Sprintf("%s%s", url, constants.ShaSuffix) expectedSha, err := util.ParseSHAFromURL(shaURL) if err != nil { t.Errorf("Error retrieving SHA for %s. Error: %s", r.Version, err) continue } actualSha, err := getShaFromURL(url) if err != nil { t.Errorf("Error calculating SHA for %s. Error: %s", r.Version, err) continue } if expectedSha != actualSha { t.Errorf("ERROR: SHA does not match for version %s. Expected %s, got %s.", r.Version, expectedSha, actualSha) continue } } }
func (l *localkubeCacher) downloadAndCacheLocalkube() error { resp := &http.Response{} err := errors.New("") downloader := func() (err error) { url, err := util.GetLocalkubeDownloadURL(l.k8sConf.KubernetesVersion, constants.LocalkubeLinuxFilename) if err != nil { return errors.Wrap(err, "Error getting localkube download url") } resp, err = http.Get(url) if err != nil { return errors.Wrap(err, "Error downloading localkube via http") } return nil } if err = util.Retry(5, downloader); err != nil { return errors.Wrap(err, "Max error attempts retrying localkube downloader") } if err = l.cacheLocalkube(resp.Body); err != nil { return errors.Wrap(err, "Error caching localkube to local directory") } return nil }