Skip to content

Commit c58167e

Browse files
fix: fix empty tarball when generating image save
1 parent 796759d commit c58167e

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

pkg/minikube/cruntime/containerd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func (r *Containerd) Disable() error {
265265
// ImageExists checks if image exists based on image name and optionally image sha
266266
func (r *Containerd) ImageExists(name string, sha string) bool {
267267
klog.Infof("Checking existence of image with name %q and sha %q", name, sha)
268-
c := exec.Command("sudo", "ctr", "-n=k8s.io", "images", "check")
268+
c := exec.Command("sudo", "ctr", "-n=k8s.io", "images", "ls", fmt.Sprintf("name==%s", name))
269269
// note: image name and image id's sha can be on different lines in ctr output
270270
if rr, err := r.Runner.RunCmd(c); err != nil ||
271271
!strings.Contains(rr.Output(), name) ||

pkg/minikube/cruntime/docker.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ func (r *Docker) ListImages(ListImagesOptions) ([]ListImage, error) {
292292
result = append(result, ListImage{
293293
ID: strings.TrimPrefix(jsonImage.ID, "sha256:"),
294294
RepoDigests: []string{},
295-
RepoTags: []string{addDockerIO(repoTag)},
295+
RepoTags: []string{AddDockerIO(repoTag)},
296296
Size: fmt.Sprintf("%d", size),
297297
})
298298
}
@@ -696,10 +696,13 @@ func dockerImagesPreloaded(runner command.Runner, images []string) bool {
696696
}
697697

698698
// Add docker.io prefix
699-
func addDockerIO(name string) string {
699+
func AddDockerIO(name string) string {
700700
var reg, usr, img string
701701
p := strings.SplitN(name, "/", 2)
702-
if len(p) > 1 && strings.Contains(p[0], ".") {
702+
// containing . means that it is a valid url for registry(e.g. xxx.io)
703+
// containing : means it contains some port number (e.g. xxx:5432)
704+
// it may also start with localhost, which is also regarded as a valid registry
705+
if len(p) > 1 && (strings.Contains(p[0], ".") || strings.Contains(p[0], ":") || strings.Contains(p[0], "localhost")) {
703706
reg = p[0]
704707
img = p[1]
705708
} else {

pkg/minikube/machine/cache_images.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,11 @@ func transferAndSaveImage(cr command.Runner, k8s config.KubernetesConfig, dst st
474474
}
475475

476476
if !r.ImageExists(imgName, "") {
477-
return errors.Errorf("image %s not found", imgName)
477+
imgName = cruntime.AddDockerIO(imgName)
478+
// we add the image name with default prefix docker.io if it doesn't specify a registry
479+
if !r.ImageExists(imgName, "") {
480+
return errors.Errorf("image %s not found", imgName)
481+
}
478482
}
479483

480484
klog.Infof("Saving image to: %s", dst)

test/integration/functional_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import (
5757
"golang.org/x/build/kubernetes/api"
5858
)
5959

60-
const echoServerImg = "docker.io/kicbase/echo-server"
60+
const echoServerImg = "kicbase/echo-server"
6161

6262
// validateFunc are for subtests that share a single setup
6363
type validateFunc func(context.Context, *testing.T, string)

0 commit comments

Comments
 (0)