From 1f6e140e005db1fdfaf7f1e2df2f394f68be229f Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Thu, 4 Jun 2020 12:23:14 -0700 Subject: [PATCH 1/7] try to save image as tarball on download-only --- cmd/minikube/cmd/start.go | 5 +++++ go.mod | 6 +++--- go.sum | 7 +++++++ pkg/minikube/image/image.go | 6 ++++++ pkg/minikube/node/cache.go | 22 +++++++++++++++++----- pkg/minikube/node/start.go | 2 +- 6 files changed, 39 insertions(+), 9 deletions(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index d831876bdc6b..2f39dca52560 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -613,6 +613,11 @@ func validateDriver(ds registry.DriverState, existing *config.ClusterConfig) { exit.WithCodeT(exit.Unavailable, "The driver '{{.driver}}' is not supported on {{.os}}", out.V{"driver": name, "os": runtime.GOOS}) } + // if we are only downloading artifacts for a driver, we can stop validation here + if viper.GetBool("download-only") { + return + } + st := ds.State glog.Infof("status for %s: %+v", name, st) diff --git a/go.mod b/go.mod index 4aa16d86a212..b7df0bc7a6b3 100644 --- a/go.mod +++ b/go.mod @@ -92,9 +92,9 @@ require ( gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 // indirect gopkg.in/yaml.v2 v2.2.8 gotest.tools/v3 v3.0.2 // indirect - k8s.io/api v0.17.3 - k8s.io/apimachinery v0.17.3 - k8s.io/client-go v0.17.3 + k8s.io/api v0.17.4 + k8s.io/apimachinery v0.17.4 + k8s.io/client-go v0.17.4 k8s.io/kubectl v0.0.0 k8s.io/kubernetes v1.17.3 k8s.io/utils v0.0.0-20200229041039-0a110f9eb7ab // indirect diff --git a/go.sum b/go.sum index 6b690e42238e..f9f61f4369e8 100644 --- a/go.sum +++ b/go.sum @@ -359,6 +359,7 @@ github.com/google/cadvisor v0.35.0/go.mod h1:1nql6U13uTHaLYB8rLS5x9IJc2qT6Xd/Tr1 github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-containerregistry v0.0.0-20200131185320-aec8da010de2 h1:/z0FoA29APs30PljxT6GoZQekF5c1cYhow2osFsj1XU= github.com/google/go-containerregistry v0.0.0-20200131185320-aec8da010de2/go.mod h1:Wtl/v6YdQxv397EREtzwgd9+Ud7Q5D8XMbi3Zazgkrs= @@ -544,6 +545,7 @@ github.com/maruel/panicparse v1.5.0/go.mod h1:aOutY/MUjdj80R0AEVI9qE2zHqig+67t2f github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE= github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= @@ -551,6 +553,7 @@ github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.9 h1:d5US/mDsogSGW37IV293h//ZFaeajb69h+EHFsv2xGg= github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= +github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y= @@ -817,6 +820,7 @@ github.com/valyala/fasthttp v1.2.0/go.mod h1:4vX61m6KN+xDduDNwXrhIAVZaZaZiQ1luJk github.com/valyala/quicktemplate v1.1.1/go.mod h1:EH+4AkTd43SvgIbQHYu59/cJyxDoOVRUAfrukLPuGJ4= github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= github.com/vdemeester/k8s-pkg-credentialprovider v0.0.0-20200107171650-7c61ffa44238/go.mod h1:JwQJCMWpUDqjZrB5jpw0f5VbN7U95zxFy1ZDpoEarGo= +github.com/vdemeester/k8s-pkg-credentialprovider v1.17.4/go.mod h1:inCTmtUdr5KJbreVojo06krnTgaeAz/Z7lynpPk/Q2c= github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw= github.com/vishvananda/netlink v1.0.0 h1:bqNY2lgheFIu1meHUFSH3d7vG93AFyqg3oGbJCOJgSM= github.com/vishvananda/netlink v1.0.0/go.mod h1:+SR5DhBJrl6ZM7CoCKvpw5BKroDKQ+PJqOg65H/2ktk= @@ -968,6 +972,7 @@ golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20191010194322-b09406accb47 h1:/XfQ9z7ib8eEJX2hdgFTZJ/ntt0swNk5oYBziWeTCvY= golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.0.0-20170915090833-1cbadb444a80/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1016,9 +1021,11 @@ golang.org/x/tools v0.0.0-20190920225731-5eefd052ad72/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200115165105-de0b1760071a h1:bEJ3JL2YUH3tt9KX9dsy0WUF3WOrhjtNjK93o0svepY= golang.org/x/tools v0.0.0-20200115165105-de0b1760071a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200210192313-1ace956b0e17/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gonum.org/v1/gonum v0.0.0-20190331200053-3d26580ed485/go.mod h1:2ltnJ7xHfj0zHS40VVPYEAAMTa3ZGguvHGBSJeRWqE0= gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw= diff --git a/pkg/minikube/image/image.go b/pkg/minikube/image/image.go index ea966eabaf37..1307ed13a61a 100644 --- a/pkg/minikube/image/image.go +++ b/pkg/minikube/image/image.go @@ -135,6 +135,12 @@ func WriteImageToDaemon(img string) error { return nil } +// Tarball writes the img to a tarball in the minikube cache +func Tarball(img string) error { + + return nil +} + func retrieveImage(ref name.Reference) (v1.Image, error) { glog.Infof("retrieving image: %+v", ref) img, err := daemon.Image(ref) diff --git a/pkg/minikube/node/cache.go b/pkg/minikube/node/cache.go index cae0144d7c1d..850e7980cdeb 100644 --- a/pkg/minikube/node/cache.go +++ b/pkg/minikube/node/cache.go @@ -102,7 +102,7 @@ func doCacheBinaries(k8sVersion string) error { } // beginDownloadKicBaseImage downloads the kic image -func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig) { +func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig, downloadOnly bool) { if cc.Driver != "docker" { // TODO: driver == "podman" glog.Info("Driver isn't docker, skipping base image download") @@ -117,17 +117,29 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig) { out.T(out.Pulling, "Pulling base image ...") g.Go(func() error { // TODO #8004 : make base-image respect --image-repository + var finalImg string + // If we end up using a fallback image, notify the user + defer func() { + if finalImg != "" && finalImg != cc.KicBaseImage { + out.WarningT(fmt.Sprintf("minikube was unable to download %s, but successfully downloaded %s\n minikube will use %s as a fallback image", image.Tag(cc.KicBaseImage), image.Tag(finalImg), image.Tag(finalImg))) + cc.KicBaseImage = finalImg + } + }() for _, img := range append([]string{cc.KicBaseImage}, kic.FallbackImages...) { glog.Infof("Downloading %s to local daemon", img) err := image.WriteImageToDaemon(img) if err == nil { - if img != cc.KicBaseImage { - out.WarningT(fmt.Sprintf("minikube was unable to download %s, but successfully downloaded %s\n minikube will use %s as a fallback image", image.Tag(cc.KicBaseImage), image.Tag(img), image.Tag(img))) - cc.KicBaseImage = img - } glog.Infof("successfully downloaded %s", img) + finalImg = img return nil } + if downloadOnly { + if err := image.Tarball(img); err == nil { + glog.Infof("successfully saved %s as a tarball", img) + finalImg = img + return nil + } + } glog.Infof("failed to download %s, will try fallback image if available: %v", img, err) } return fmt.Errorf("failed to download kic base image or any fallback image") diff --git a/pkg/minikube/node/start.go b/pkg/minikube/node/start.go index 383df8c06271..810b7a1054d2 100644 --- a/pkg/minikube/node/start.go +++ b/pkg/minikube/node/start.go @@ -195,7 +195,7 @@ func Provision(cc *config.ClusterConfig, n *config.Node, apiServer bool) (comman } if driver.IsKIC(cc.Driver) { - beginDownloadKicBaseImage(&kicGroup, cc) + beginDownloadKicBaseImage(&kicGroup, cc, viper.GetBool("download-only")) } if !driver.BareMetal(cc.Driver) { From c629b9b81c8957cd833fad4ea9327c3ccd2fb423 Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Thu, 4 Jun 2020 12:40:19 -0700 Subject: [PATCH 2/7] load from tarball if cached kic image exists --- pkg/minikube/image/image.go | 26 ++++++++++++++++++++------ pkg/minikube/node/cache.go | 7 ++++++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/pkg/minikube/image/image.go b/pkg/minikube/image/image.go index 1307ed13a61a..ea50384699fc 100644 --- a/pkg/minikube/image/image.go +++ b/pkg/minikube/image/image.go @@ -34,8 +34,10 @@ import ( v1 "github.com/google/go-containerregistry/pkg/v1" "github.com/google/go-containerregistry/pkg/v1/daemon" "github.com/google/go-containerregistry/pkg/v1/remote" + "github.com/google/go-containerregistry/pkg/v1/tarball" "github.com/pkg/errors" "k8s.io/minikube/pkg/minikube/constants" + "k8s.io/minikube/pkg/minikube/localpath" ) var defaultPlatform = v1.Platform{ @@ -94,6 +96,24 @@ func ExistsImageInDaemon(img string) bool { return false } +// LoadFromTarball checks if the image exists as a tarball and tries to load it to the local daemon +func LoadFromTarball(img string) error { + p := filepath.Join(constants.ImageCacheDir, img) + p = localpath.SanitizeCacheDir(p) + + tag, err := name.NewTag(img) + if err != nil { + return errors.Wrap(err, "tag") + } + + i, err := tarball.ImageFromPath(p, &tag) + _, err = daemon.Write(tag, i) + if err != nil { + return errors.Wrap(err, "writing daemon image") + } + return nil +} + // Tag returns just the image with the tag // eg image:tag@sha256:digest -> image:tag if there is an associated tag // if not possible, just return the initial img @@ -135,12 +155,6 @@ func WriteImageToDaemon(img string) error { return nil } -// Tarball writes the img to a tarball in the minikube cache -func Tarball(img string) error { - - return nil -} - func retrieveImage(ref name.Reference) (v1.Image, error) { glog.Infof("retrieving image: %+v", ref) img, err := daemon.Image(ref) diff --git a/pkg/minikube/node/cache.go b/pkg/minikube/node/cache.go index 850e7980cdeb..076020944248 100644 --- a/pkg/minikube/node/cache.go +++ b/pkg/minikube/node/cache.go @@ -126,6 +126,11 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig, down } }() for _, img := range append([]string{cc.KicBaseImage}, kic.FallbackImages...) { + if err := image.LoadFromTarball(img); err == nil { + glog.Infof("successfully loaded %s from cached tarball", img) + finalImg = img + return nil + } glog.Infof("Downloading %s to local daemon", img) err := image.WriteImageToDaemon(img) if err == nil { @@ -134,7 +139,7 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig, down return nil } if downloadOnly { - if err := image.Tarball(img); err == nil { + if err := image.SaveToDir([]string{img}, constants.ImageCacheDir); err == nil { glog.Infof("successfully saved %s as a tarball", img) finalImg = img return nil From 99d75c6b5b75d7a85689f2050a917f4d55945420 Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Mon, 8 Jun 2020 10:53:47 -0700 Subject: [PATCH 3/7] WIP --- pkg/minikube/image/image.go | 13 +++---------- pkg/minikube/node/cache.go | 2 ++ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/pkg/minikube/image/image.go b/pkg/minikube/image/image.go index ea50384699fc..cf5cfdde9a24 100644 --- a/pkg/minikube/image/image.go +++ b/pkg/minikube/image/image.go @@ -34,7 +34,6 @@ import ( v1 "github.com/google/go-containerregistry/pkg/v1" "github.com/google/go-containerregistry/pkg/v1/daemon" "github.com/google/go-containerregistry/pkg/v1/remote" - "github.com/google/go-containerregistry/pkg/v1/tarball" "github.com/pkg/errors" "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/localpath" @@ -101,15 +100,9 @@ func LoadFromTarball(img string) error { p := filepath.Join(constants.ImageCacheDir, img) p = localpath.SanitizeCacheDir(p) - tag, err := name.NewTag(img) - if err != nil { - return errors.Wrap(err, "tag") - } - - i, err := tarball.ImageFromPath(p, &tag) - _, err = daemon.Write(tag, i) - if err != nil { - return errors.Wrap(err, "writing daemon image") + cmd := exec.Command("docker", "load", "-i", p) + if output, err := cmd.CombinedOutput(); err != nil { + return errors.Wrapf(err, "%s", string(output)) } return nil } diff --git a/pkg/minikube/node/cache.go b/pkg/minikube/node/cache.go index 076020944248..e8c97edf95ba 100644 --- a/pkg/minikube/node/cache.go +++ b/pkg/minikube/node/cache.go @@ -130,6 +130,8 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig, down glog.Infof("successfully loaded %s from cached tarball", img) finalImg = img return nil + } else { + fmt.Println("Failed to load tarball:", err) } glog.Infof("Downloading %s to local daemon", img) err := image.WriteImageToDaemon(img) From 173666d203e27d8e80058f02623b89a5419d47f2 Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Mon, 8 Jun 2020 14:01:06 -0700 Subject: [PATCH 4/7] Use go-containerregistry library instead of docker CLI --- pkg/minikube/image/image.go | 16 ++++++++++++---- pkg/minikube/node/cache.go | 6 +++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/pkg/minikube/image/image.go b/pkg/minikube/image/image.go index cf5cfdde9a24..8321886edaf5 100644 --- a/pkg/minikube/image/image.go +++ b/pkg/minikube/image/image.go @@ -34,6 +34,7 @@ import ( v1 "github.com/google/go-containerregistry/pkg/v1" "github.com/google/go-containerregistry/pkg/v1/daemon" "github.com/google/go-containerregistry/pkg/v1/remote" + "github.com/google/go-containerregistry/pkg/v1/tarball" "github.com/pkg/errors" "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/localpath" @@ -100,11 +101,18 @@ func LoadFromTarball(img string) error { p := filepath.Join(constants.ImageCacheDir, img) p = localpath.SanitizeCacheDir(p) - cmd := exec.Command("docker", "load", "-i", p) - if output, err := cmd.CombinedOutput(); err != nil { - return errors.Wrapf(err, "%s", string(output)) + tag, err := name.NewTag(Tag(img)) + if err != nil { + return errors.Wrap(err, "new tag") } - return nil + + i, err := tarball.ImageFromPath(p, &tag) + if err != nil { + return errors.Wrap(err, "tarball") + } + + _, err = daemon.Write(tag, i) + return err } // Tag returns just the image with the tag diff --git a/pkg/minikube/node/cache.go b/pkg/minikube/node/cache.go index e8c97edf95ba..67e2be7817df 100644 --- a/pkg/minikube/node/cache.go +++ b/pkg/minikube/node/cache.go @@ -128,10 +128,10 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig, down for _, img := range append([]string{cc.KicBaseImage}, kic.FallbackImages...) { if err := image.LoadFromTarball(img); err == nil { glog.Infof("successfully loaded %s from cached tarball", img) - finalImg = img + // strip the digest from the img before saving it in the config + // because loading an image from tarball to daemon doesn't load the digest + finalImg = image.Tag(img) return nil - } else { - fmt.Println("Failed to load tarball:", err) } glog.Infof("Downloading %s to local daemon", img) err := image.WriteImageToDaemon(img) From 94da5201a62f90cc1dd3c77c3cbdba1e6f63a10f Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Mon, 8 Jun 2020 14:10:11 -0700 Subject: [PATCH 5/7] Add TODO --- pkg/minikube/image/image.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/minikube/image/image.go b/pkg/minikube/image/image.go index 8321886edaf5..2a42373e1850 100644 --- a/pkg/minikube/image/image.go +++ b/pkg/minikube/image/image.go @@ -97,6 +97,7 @@ func ExistsImageInDaemon(img string) bool { } // LoadFromTarball checks if the image exists as a tarball and tries to load it to the local daemon +// TODO: Pass in if we are loading to docker or podman so this function can also be used for podman func LoadFromTarball(img string) error { p := filepath.Join(constants.ImageCacheDir, img) p = localpath.SanitizeCacheDir(p) From e37da349fbfee6f1c390ba2cf5d8b7033b9ed9e1 Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Tue, 9 Jun 2020 10:18:53 -0700 Subject: [PATCH 6/7] pass in driver to load from tarball --- pkg/minikube/image/image.go | 27 +++++++++++++++++---------- pkg/minikube/node/cache.go | 3 ++- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/pkg/minikube/image/image.go b/pkg/minikube/image/image.go index 2a42373e1850..486b01825aac 100644 --- a/pkg/minikube/image/image.go +++ b/pkg/minikube/image/image.go @@ -37,6 +37,7 @@ import ( "github.com/google/go-containerregistry/pkg/v1/tarball" "github.com/pkg/errors" "k8s.io/minikube/pkg/minikube/constants" + "k8s.io/minikube/pkg/minikube/driver" "k8s.io/minikube/pkg/minikube/localpath" ) @@ -98,22 +99,28 @@ func ExistsImageInDaemon(img string) bool { // LoadFromTarball checks if the image exists as a tarball and tries to load it to the local daemon // TODO: Pass in if we are loading to docker or podman so this function can also be used for podman -func LoadFromTarball(img string) error { +func LoadFromTarball(binary, img string) error { p := filepath.Join(constants.ImageCacheDir, img) p = localpath.SanitizeCacheDir(p) - tag, err := name.NewTag(Tag(img)) - if err != nil { - return errors.Wrap(err, "new tag") - } + switch binary { + case driver.Podman: + return fmt.Errorf("not yet implemented, see issue #8426") + default: + tag, err := name.NewTag(Tag(img)) + if err != nil { + return errors.Wrap(err, "new tag") + } - i, err := tarball.ImageFromPath(p, &tag) - if err != nil { - return errors.Wrap(err, "tarball") + i, err := tarball.ImageFromPath(p, &tag) + if err != nil { + return errors.Wrap(err, "tarball") + } + + _, err = daemon.Write(tag, i) + return err } - _, err = daemon.Write(tag, i) - return err } // Tag returns just the image with the tag diff --git a/pkg/minikube/node/cache.go b/pkg/minikube/node/cache.go index 67e2be7817df..8f4142745ac4 100644 --- a/pkg/minikube/node/cache.go +++ b/pkg/minikube/node/cache.go @@ -31,6 +31,7 @@ import ( "k8s.io/minikube/pkg/minikube/config" "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/download" + "k8s.io/minikube/pkg/minikube/driver" "k8s.io/minikube/pkg/minikube/exit" "k8s.io/minikube/pkg/minikube/image" "k8s.io/minikube/pkg/minikube/localpath" @@ -126,7 +127,7 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig, down } }() for _, img := range append([]string{cc.KicBaseImage}, kic.FallbackImages...) { - if err := image.LoadFromTarball(img); err == nil { + if err := image.LoadFromTarball(driver.Docker, img); err == nil { glog.Infof("successfully loaded %s from cached tarball", img) // strip the digest from the img before saving it in the config // because loading an image from tarball to daemon doesn't load the digest From 11096160fe2f8f3514641b2254ae78d1dc809e3d Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Tue, 9 Jun 2020 10:25:18 -0700 Subject: [PATCH 7/7] improve warning message so it fits on one line --- pkg/minikube/node/cache.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/minikube/node/cache.go b/pkg/minikube/node/cache.go index 8f4142745ac4..711408646769 100644 --- a/pkg/minikube/node/cache.go +++ b/pkg/minikube/node/cache.go @@ -122,7 +122,7 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig, down // If we end up using a fallback image, notify the user defer func() { if finalImg != "" && finalImg != cc.KicBaseImage { - out.WarningT(fmt.Sprintf("minikube was unable to download %s, but successfully downloaded %s\n minikube will use %s as a fallback image", image.Tag(cc.KicBaseImage), image.Tag(finalImg), image.Tag(finalImg))) + out.WarningT(fmt.Sprintf("minikube was unable to download %s, but successfully downloaded %s as a fallback image", image.Tag(cc.KicBaseImage), image.Tag(finalImg))) cc.KicBaseImage = finalImg } }()