From 6d4eec056be83bf5afeac7f963be156d60f6f35f Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Fri, 6 Aug 2021 00:24:28 +0000 Subject: [PATCH] fix loading an image from tar failing on existing delete --- pkg/minikube/machine/cache_images.go | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/pkg/minikube/machine/cache_images.go b/pkg/minikube/machine/cache_images.go index 36c2fe2ad4..ad97ddcf8d 100644 --- a/pkg/minikube/machine/cache_images.go +++ b/pkg/minikube/machine/cache_images.go @@ -269,11 +269,8 @@ func transferAndLoadImage(cr command.Runner, k8s config.KubernetesConfig, src st return errors.Wrap(err, "runtime") } - if err := r.RemoveImage(imgName); err != nil { - errStr := strings.ToLower(err.Error()) - if !strings.Contains(errStr, "no such image") { - return errors.Wrap(err, "removing image") - } + if err := removeExistingImage(r, src, imgName); err != nil { + return err } klog.Infof("Loading image from: %s", src) @@ -309,6 +306,26 @@ func transferAndLoadImage(cr command.Runner, k8s config.KubernetesConfig, src st return nil } +func removeExistingImage(r cruntime.Manager, src string, imgName string) error { + // if loading an image from tar, skip deleting as we don't have the actual image name + // ie. imgName = "C:\this_is_a_dir\image.tar.gz" + if src == imgName { + return nil + } + + err := r.RemoveImage(imgName) + if err == nil { + return nil + } + + errStr := strings.ToLower(err.Error()) + if !strings.Contains(errStr, "no such image") { + return errors.Wrap(err, "removing image") + } + + return nil +} + // pullImages pulls images to the container run time func pullImages(cruntime cruntime.Manager, images []string) error { klog.Infof("PullImages start: %s", images)