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

Merge repositories.json after extracting preloaded tarball so that reference store isn't lost #6985

Merged
merged 8 commits into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion pkg/minikube/cruntime/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/golang/glog"
"github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/bootstrapper/images"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/out"
)

Expand Down Expand Up @@ -310,6 +311,6 @@ func (r *Containerd) SystemLogCmd(len int) string {
}

// Preload preloads the container runtime with k8s images
func (r *Containerd) Preload(k8sVersion string) error {
func (r *Containerd) Preload(cfg config.KubernetesConfig) error {
return fmt.Errorf("not yet implemented for %s", r.Name())
}
3 changes: 2 additions & 1 deletion pkg/minikube/cruntime/crio.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/golang/glog"
"github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/bootstrapper/images"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/out"
)

Expand Down Expand Up @@ -227,6 +228,6 @@ func (r *CRIO) SystemLogCmd(len int) string {
}

// Preload preloads the container runtime with k8s images
func (r *CRIO) Preload(k8sVersion string) error {
func (r *CRIO) Preload(cfg config.KubernetesConfig) error {
return fmt.Errorf("not yet implemented for %s", r.Name())
}
3 changes: 2 additions & 1 deletion pkg/minikube/cruntime/cruntime.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/command"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/out"
)

Expand Down Expand Up @@ -100,7 +101,7 @@ type Manager interface {
// SystemLogCmd returns the command to return the system logs
SystemLogCmd(int) string
// Preload preloads the container runtime with k8s images
Preload(string) error
Preload(config.KubernetesConfig) error
}

// Config is runtime configuration
Expand Down
40 changes: 39 additions & 1 deletion pkg/minikube/cruntime/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import (
"github.com/golang/glog"
"github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/bootstrapper/images"
"k8s.io/minikube/pkg/minikube/command"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/download"
"k8s.io/minikube/pkg/minikube/out"
)
Expand Down Expand Up @@ -283,7 +286,19 @@ func (r *Docker) SystemLogCmd(len int) string {
// 1. Copy over the preloaded tarball into the VM
// 2. Extract the preloaded tarball to the correct directory
// 3. Remove the tarball within the VM
func (r *Docker) Preload(k8sVersion string) error {
func (r *Docker) Preload(cfg config.KubernetesConfig) error {
k8sVersion := cfg.KubernetesVersion

// If images already exist, return
images, err := images.Kubeadm(cfg.ImageRepository, k8sVersion)
if err != nil {
return errors.Wrap(err, "getting images")
}
if ImagesPreloaded(r.Runner, images) {
glog.Info("Images already preloaded, skipping extraction")
return nil
}

tarballPath := download.TarballPath(k8sVersion)
targetDir := "/"
targetName := "preloaded.tar.lz4"
Expand Down Expand Up @@ -316,3 +331,26 @@ func (r *Docker) Preload(k8sVersion string) error {
}
return r.Restart()
}

// ImagesPreloaded returns true if all images have been preloaded
func ImagesPreloaded(runner command.Runner, images []string) bool {
medyagh marked this conversation as resolved.
Show resolved Hide resolved
priyawadhwa marked this conversation as resolved.
Show resolved Hide resolved
rr, err := runner.RunCmd(exec.Command("docker", "images", "--format", "{{.Repository}}:{{.Tag}}"))
if err != nil {
return false
}
preloadedImages := map[string]struct{}{}
for _, i := range strings.Split(rr.Stdout.String(), "\n") {
preloadedImages[i] = struct{}{}
}

glog.Infof("Got preloaded images: %s", rr.Output())

// Make sure images == imgs
for _, i := range images {
if _, ok := preloadedImages[i]; !ok {
glog.Infof("%s wasn't preloaded", i)
return false
}
}
return true
}
26 changes: 1 addition & 25 deletions pkg/minikube/machine/cache_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ package machine
import (
"fmt"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -66,7 +64,7 @@ func CacheImagesForBootstrapper(imageRepository string, version string, clusterB
// LoadImages loads previously cached images into the container runtime
func LoadImages(cc *config.ClusterConfig, runner command.Runner, images []string, cacheDir string) error {
// Skip loading images if images already exist
if imagesPreloaded(runner, images) {
if cruntime.ImagesPreloaded(runner, images) {
glog.Infof("Images are preloaded, skipping loading")
return nil
}
Expand Down Expand Up @@ -108,28 +106,6 @@ func LoadImages(cc *config.ClusterConfig, runner command.Runner, images []string
return nil
}

func imagesPreloaded(runner command.Runner, images []string) bool {
rr, err := runner.RunCmd(exec.Command("docker", "images", "--format", "{{.Repository}}:{{.Tag}}"))
if err != nil {
return false
}
preloadedImages := map[string]struct{}{}
for _, i := range strings.Split(rr.Stdout.String(), "\n") {
preloadedImages[i] = struct{}{}
}

glog.Infof("Got preloaded images: %s", rr.Output())

// Make sure images == imgs
for _, i := range images {
if _, ok := preloadedImages[i]; !ok {
glog.Infof("%s wasn't preloaded", i)
return false
}
}
return true
}

// needsTransfer returns an error if an image needs to be retransfered
func needsTransfer(imgClient *client.Client, imgName string, cr cruntime.Manager) error {
imgDgst := "" // for instance sha256:7c92a2c6bbcb6b6beff92d0a940779769c2477b807c202954c537e2e0deb9bed
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func configureRuntimes(runner cruntime.CommandRunner, drvName string, k8s config
disableOthers = false
}
if !driver.IsKIC(drvName) {
if err := cr.Preload(k8s.KubernetesVersion); err != nil {
if err := cr.Preload(k8s); err != nil {
switch err.(type) {
case *cruntime.ErrISOFeature:
out.T(out.Tip, "Existing disk is missing new features ({{.error}}). To upgrade, run 'minikube delete'", out.V{"error": err})
Expand Down