Merge pull request #7044 from priyawadhwa/preload-arch
Skip preload if not running on amd64pull/7269/head
commit
0db42a6f1a
|
@ -63,7 +63,7 @@ func main() {
|
|||
|
||||
for _, kv := range k8sVersions {
|
||||
for _, cr := range containerRuntimes {
|
||||
tf := download.TarballName(kv)
|
||||
tf := download.TarballName(kv, cr)
|
||||
if download.PreloadExists(kv, cr) {
|
||||
fmt.Printf("A preloaded tarball for k8s version %s already exists, skipping generation.\n", kv)
|
||||
continue
|
||||
|
|
|
@ -121,14 +121,14 @@ func (d *Driver) Create() error {
|
|||
return errors.Wrap(err, "prepare kic ssh")
|
||||
}
|
||||
|
||||
// If preload doesn't exist, don't both extracting tarball to volume
|
||||
// If preload doesn't exist, don't bother extracting tarball to volume
|
||||
if !download.PreloadExists(d.NodeConfig.KubernetesVersion, d.NodeConfig.ContainerRuntime) {
|
||||
return nil
|
||||
}
|
||||
t := time.Now()
|
||||
glog.Infof("Starting extracting preloaded images to volume")
|
||||
// Extract preloaded images to container
|
||||
if err := oci.ExtractTarballToVolume(download.TarballPath(d.NodeConfig.KubernetesVersion), params.Name, BaseImage); err != nil {
|
||||
if err := oci.ExtractTarballToVolume(download.TarballPath(d.NodeConfig.KubernetesVersion, d.NodeConfig.ContainerRuntime), params.Name, BaseImage); err != nil {
|
||||
glog.Infof("Unable to extract preloaded tarball to volume: %v", err)
|
||||
} else {
|
||||
glog.Infof("Took %f seconds to extract preloaded images to volume", time.Since(t).Seconds())
|
||||
|
|
|
@ -294,6 +294,7 @@ func (r *Docker) Preload(cfg config.KubernetesConfig) error {
|
|||
return nil
|
||||
}
|
||||
k8sVersion := cfg.KubernetesVersion
|
||||
cRuntime := cfg.ContainerRuntime
|
||||
|
||||
// If images already exist, return
|
||||
images, err := images.Kubeadm(cfg.ImageRepository, k8sVersion)
|
||||
|
@ -310,7 +311,7 @@ func (r *Docker) Preload(cfg config.KubernetesConfig) error {
|
|||
glog.Infof("error saving reference store: %v", err)
|
||||
}
|
||||
|
||||
tarballPath := download.TarballPath(k8sVersion)
|
||||
tarballPath := download.TarballPath(k8sVersion, cRuntime)
|
||||
targetDir := "/"
|
||||
targetName := "preloaded.tar.lz4"
|
||||
dest := path.Join(targetDir, targetName)
|
||||
|
|
|
@ -24,6 +24,7 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"cloud.google.com/go/storage"
|
||||
"google.golang.org/api/option"
|
||||
|
@ -46,13 +47,13 @@ const (
|
|||
)
|
||||
|
||||
// TarballName returns name of the tarball
|
||||
func TarballName(k8sVersion string) string {
|
||||
return fmt.Sprintf("preloaded-images-k8s-%s-%s-docker-overlay2-amd64.tar.lz4", PreloadVersion, k8sVersion)
|
||||
func TarballName(k8sVersion, containerRuntime string) string {
|
||||
return fmt.Sprintf("preloaded-images-k8s-%s-%s-%s-overlay2-%s.tar.lz4", PreloadVersion, k8sVersion, containerRuntime, runtime.GOARCH)
|
||||
}
|
||||
|
||||
// returns the name of the checksum file
|
||||
func checksumName(k8sVersion string) string {
|
||||
return fmt.Sprintf("%s.checksum", TarballName(k8sVersion))
|
||||
func checksumName(k8sVersion, containerRuntime string) string {
|
||||
return fmt.Sprintf("%s.checksum", TarballName(k8sVersion, containerRuntime))
|
||||
}
|
||||
|
||||
// returns target dir for all cached items related to preloading
|
||||
|
@ -61,18 +62,18 @@ func targetDir() string {
|
|||
}
|
||||
|
||||
// PreloadChecksumPath returns the local path to the cached checksum file
|
||||
func PreloadChecksumPath(k8sVersion string) string {
|
||||
return filepath.Join(targetDir(), checksumName(k8sVersion))
|
||||
func PreloadChecksumPath(k8sVersion, containerRuntime string) string {
|
||||
return filepath.Join(targetDir(), checksumName(k8sVersion, containerRuntime))
|
||||
}
|
||||
|
||||
// TarballPath returns the local path to the cached preload tarball
|
||||
func TarballPath(k8sVersion string) string {
|
||||
return filepath.Join(targetDir(), TarballName(k8sVersion))
|
||||
func TarballPath(k8sVersion, containerRuntime string) string {
|
||||
return filepath.Join(targetDir(), TarballName(k8sVersion, containerRuntime))
|
||||
}
|
||||
|
||||
// remoteTarballURL returns the URL for the remote tarball in GCS
|
||||
func remoteTarballURL(k8sVersion string) string {
|
||||
return fmt.Sprintf("https://storage.googleapis.com/%s/%s", PreloadBucket, TarballName(k8sVersion))
|
||||
func remoteTarballURL(k8sVersion, containerRuntime string) string {
|
||||
return fmt.Sprintf("https://storage.googleapis.com/%s/%s", PreloadBucket, TarballName(k8sVersion, containerRuntime))
|
||||
}
|
||||
|
||||
// PreloadExists returns true if there is a preloaded tarball that can be used
|
||||
|
@ -91,13 +92,13 @@ func PreloadExists(k8sVersion, containerRuntime string) bool {
|
|||
}
|
||||
|
||||
// Omit remote check if tarball exists locally
|
||||
targetPath := TarballPath(k8sVersion)
|
||||
targetPath := TarballPath(k8sVersion, containerRuntime)
|
||||
if _, err := os.Stat(targetPath); err == nil {
|
||||
glog.Infof("Found local preload: %s", targetPath)
|
||||
return true
|
||||
}
|
||||
|
||||
url := remoteTarballURL(k8sVersion)
|
||||
url := remoteTarballURL(k8sVersion, containerRuntime)
|
||||
resp, err := http.Head(url)
|
||||
if err != nil {
|
||||
glog.Warningf("%s fetch error: %v", url, err)
|
||||
|
@ -116,10 +117,7 @@ func PreloadExists(k8sVersion, containerRuntime string) bool {
|
|||
|
||||
// Preload caches the preloaded images tarball on the host machine
|
||||
func Preload(k8sVersion, containerRuntime string) error {
|
||||
if containerRuntime != "docker" {
|
||||
return nil
|
||||
}
|
||||
targetPath := TarballPath(k8sVersion)
|
||||
targetPath := TarballPath(k8sVersion, containerRuntime)
|
||||
|
||||
if _, err := os.Stat(targetPath); err == nil {
|
||||
glog.Infof("Found %s in cache, skipping download", targetPath)
|
||||
|
@ -133,7 +131,7 @@ func Preload(k8sVersion, containerRuntime string) error {
|
|||
}
|
||||
|
||||
out.T(out.FileDownload, "Downloading Kubernetes {{.version}} preload ...", out.V{"version": k8sVersion})
|
||||
url := remoteTarballURL(k8sVersion)
|
||||
url := remoteTarballURL(k8sVersion, containerRuntime)
|
||||
|
||||
tmpDst := targetPath + ".download"
|
||||
client := &getter.Client{
|
||||
|
@ -148,34 +146,34 @@ func Preload(k8sVersion, containerRuntime string) error {
|
|||
return errors.Wrapf(err, "download failed: %s", url)
|
||||
}
|
||||
|
||||
if err := saveChecksumFile(k8sVersion); err != nil {
|
||||
if err := saveChecksumFile(k8sVersion, containerRuntime); err != nil {
|
||||
return errors.Wrap(err, "saving checksum file")
|
||||
}
|
||||
|
||||
if err := verifyChecksum(k8sVersion, tmpDst); err != nil {
|
||||
if err := verifyChecksum(k8sVersion, containerRuntime, tmpDst); err != nil {
|
||||
return errors.Wrap(err, "verify")
|
||||
}
|
||||
return os.Rename(tmpDst, targetPath)
|
||||
}
|
||||
|
||||
func saveChecksumFile(k8sVersion string) error {
|
||||
glog.Infof("saving checksum for %s ...", TarballName(k8sVersion))
|
||||
func saveChecksumFile(k8sVersion, containerRuntime string) error {
|
||||
glog.Infof("saving checksum for %s ...", TarballName(k8sVersion, containerRuntime))
|
||||
ctx := context.Background()
|
||||
client, err := storage.NewClient(ctx, option.WithoutAuthentication())
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "getting storage client")
|
||||
}
|
||||
attrs, err := client.Bucket(PreloadBucket).Object(TarballName(k8sVersion)).Attrs(ctx)
|
||||
attrs, err := client.Bucket(PreloadBucket).Object(TarballName(k8sVersion, containerRuntime)).Attrs(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "getting storage object")
|
||||
}
|
||||
checksum := attrs.MD5
|
||||
return ioutil.WriteFile(PreloadChecksumPath(k8sVersion), checksum, 0644)
|
||||
return ioutil.WriteFile(PreloadChecksumPath(k8sVersion, containerRuntime), checksum, 0644)
|
||||
}
|
||||
|
||||
// verifyChecksum returns true if the checksum of the local binary matches
|
||||
// the checksum of the remote binary
|
||||
func verifyChecksum(k8sVersion string, path string) error {
|
||||
func verifyChecksum(k8sVersion, containerRuntime, path string) error {
|
||||
glog.Infof("verifying checksumm of %s ...", path)
|
||||
// get md5 checksum of tarball path
|
||||
contents, err := ioutil.ReadFile(path)
|
||||
|
@ -184,7 +182,7 @@ func verifyChecksum(k8sVersion string, path string) error {
|
|||
}
|
||||
checksum := md5.Sum(contents)
|
||||
|
||||
remoteChecksum, err := ioutil.ReadFile(PreloadChecksumPath(k8sVersion))
|
||||
remoteChecksum, err := ioutil.ReadFile(PreloadChecksumPath(k8sVersion, containerRuntime))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "reading checksum file")
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ func TestDownloadOnly(t *testing.T) {
|
|||
if !NoneDriver() {
|
||||
if download.PreloadExists(v, r) {
|
||||
// Just make sure the tarball path exists
|
||||
if _, err := os.Stat(download.TarballPath(v)); err != nil {
|
||||
if _, err := os.Stat(download.TarballPath(v, r)); err != nil {
|
||||
t.Errorf("failed to verify preloaded tarball file exists: %v", err)
|
||||
}
|
||||
return
|
||||
|
@ -154,6 +154,8 @@ func TestDownloadOnlyKic(t *testing.T) {
|
|||
ctx, cancel := context.WithTimeout(context.Background(), Minutes(15))
|
||||
defer Cleanup(t, profile, cancel)
|
||||
|
||||
cRuntime := "docker"
|
||||
|
||||
args := []string{"start", "--download-only", "-p", profile, "--force", "--alsologtostderr"}
|
||||
args = append(args, StartArgs()...)
|
||||
|
||||
|
@ -162,16 +164,16 @@ func TestDownloadOnlyKic(t *testing.T) {
|
|||
}
|
||||
|
||||
// Make sure the downloaded image tarball exists
|
||||
tarball := download.TarballPath(constants.DefaultKubernetesVersion)
|
||||
tarball := download.TarballPath(constants.DefaultKubernetesVersion, cRuntime)
|
||||
contents, err := ioutil.ReadFile(tarball)
|
||||
if err != nil {
|
||||
t.Errorf("failed to read tarball file %q: %v", tarball, err)
|
||||
}
|
||||
// Make sure it has the correct checksum
|
||||
checksum := md5.Sum(contents)
|
||||
remoteChecksum, err := ioutil.ReadFile(download.PreloadChecksumPath(constants.DefaultKubernetesVersion))
|
||||
remoteChecksum, err := ioutil.ReadFile(download.PreloadChecksumPath(constants.DefaultKubernetesVersion, cRuntime))
|
||||
if err != nil {
|
||||
t.Errorf("failed to read checksum file %q : %v", download.PreloadChecksumPath(constants.DefaultKubernetesVersion), err)
|
||||
t.Errorf("failed to read checksum file %q : %v", download.PreloadChecksumPath(constants.DefaultKubernetesVersion, cRuntime), err)
|
||||
}
|
||||
if string(remoteChecksum) != string(checksum[:]) {
|
||||
t.Errorf("failed to verify checksum. checksum of %q does not match remote checksum (%q != %q)", tarball, string(remoteChecksum), string(checksum[:]))
|
||||
|
|
Loading…
Reference in New Issue