Don't require authentication to get checksum
parent
97bf128703
commit
dee885267b
1
go.mod
1
go.mod
|
@ -70,6 +70,7 @@ require (
|
||||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
|
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
|
||||||
golang.org/x/sys v0.0.0-20191010194322-b09406accb47
|
golang.org/x/sys v0.0.0-20191010194322-b09406accb47
|
||||||
golang.org/x/text v0.3.2
|
golang.org/x/text v0.3.2
|
||||||
|
google.golang.org/api v0.9.0
|
||||||
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 // indirect
|
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 // indirect
|
||||||
k8s.io/api v0.17.2
|
k8s.io/api v0.17.2
|
||||||
k8s.io/apimachinery v0.17.2
|
k8s.io/apimachinery v0.17.2
|
||||||
|
|
|
@ -26,6 +26,8 @@ import (
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
"cloud.google.com/go/storage"
|
"cloud.google.com/go/storage"
|
||||||
|
"google.golang.org/api/option"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
"github.com/hashicorp/go-getter"
|
"github.com/hashicorp/go-getter"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -87,7 +89,7 @@ func CacheTarball(k8sVersion, containerRuntime string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
out.T(out.FileDownload, "Downloading preloaded images tarball for k8s {{.version}}:", out.V{"version": k8sVersion})
|
out.T(out.FileDownload, "Downloading preloaded images tarball for k8s {{.version}} ...", out.V{"version": k8sVersion})
|
||||||
client := &getter.Client{
|
client := &getter.Client{
|
||||||
Src: url,
|
Src: url,
|
||||||
Dst: targetFilepath,
|
Dst: targetFilepath,
|
||||||
|
@ -112,13 +114,13 @@ func CacheTarball(k8sVersion, containerRuntime string) error {
|
||||||
|
|
||||||
func saveChecksumFile(k8sVersion string) error {
|
func saveChecksumFile(k8sVersion string) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
client, err := storage.NewClient(ctx)
|
client, err := storage.NewClient(ctx, option.WithoutAuthentication())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.Wrap(err, "getting storage client")
|
||||||
}
|
}
|
||||||
attrs, err := client.Bucket(constants.PreloadedVolumeTarballsBucket).Object(tarballName(k8sVersion)).Attrs(ctx)
|
attrs, err := client.Bucket(constants.PreloadedVolumeTarballsBucket).Object(tarballName(k8sVersion)).Attrs(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.Wrap(err, "getting storage object")
|
||||||
}
|
}
|
||||||
checksum := attrs.MD5
|
checksum := attrs.MD5
|
||||||
return ioutil.WriteFile(checksumFilepath(k8sVersion), checksum, 0644)
|
return ioutil.WriteFile(checksumFilepath(k8sVersion), checksum, 0644)
|
||||||
|
@ -141,7 +143,7 @@ func verifyChecksum(k8sVersion string) error {
|
||||||
|
|
||||||
// create a slice of checksum, which is [16]byte
|
// create a slice of checksum, which is [16]byte
|
||||||
if string(remoteChecksum) != string(checksum[:]) {
|
if string(remoteChecksum) != string(checksum[:]) {
|
||||||
return fmt.Errorf("checksum of %s does not match remote checksum", TarballFilepath(k8sVersion))
|
return fmt.Errorf("checksum of %s does not match remote checksum (%s != %s)", TarballFilepath(k8sVersion), string(remoteChecksum), string(checksum[:]))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue