Skip to content

Commit

Permalink
Remove docker.io prefixing when listing images
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasjm committed Jul 29, 2024
1 parent 6a417d5 commit a7cb5fa
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 34 deletions.
28 changes: 1 addition & 27 deletions pkg/minikube/cruntime/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/docker"
"k8s.io/minikube/pkg/minikube/download"
"k8s.io/minikube/pkg/minikube/image"
"k8s.io/minikube/pkg/minikube/style"
"k8s.io/minikube/pkg/minikube/sysinit"
)
Expand Down Expand Up @@ -292,7 +291,7 @@ func (r *Docker) ListImages(ListImagesOptions) ([]ListImage, error) {
result = append(result, ListImage{
ID: strings.TrimPrefix(jsonImage.ID, "sha256:"),
RepoDigests: []string{},
RepoTags: []string{addDockerIO(repoTag)},
RepoTags: []string{repoTag},
Size: fmt.Sprintf("%d", size),
})
}
Expand Down Expand Up @@ -678,15 +677,13 @@ func dockerImagesPreloaded(runner command.Runner, images []string) bool {
}
preloadedImages := map[string]struct{}{}
for _, i := range strings.Split(rr.Stdout.String(), "\n") {
i = image.TrimDockerIO(i)
preloadedImages[i] = struct{}{}
}

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

// Make sure images == imgs
for _, i := range images {
i = image.TrimDockerIO(i)
if _, ok := preloadedImages[i]; !ok {
klog.Infof("%s wasn't preloaded", i)
return false
Expand All @@ -695,29 +692,6 @@ func dockerImagesPreloaded(runner command.Runner, images []string) bool {
return true
}

// Add docker.io prefix
func addDockerIO(name string) string {
var reg, usr, img string
p := strings.SplitN(name, "/", 2)
if len(p) > 1 && strings.Contains(p[0], ".") {
reg = p[0]
img = p[1]
} else {
reg = "docker.io"
img = name
p = strings.SplitN(img, "/", 2)
if len(p) > 1 {
usr = p[0]
img = p[1]
} else {
usr = "library"
img = name
}
return reg + "/" + usr + "/" + img
}
return reg + "/" + img
}

func dockerBoundToContainerd(runner command.Runner) bool {
// NOTE: assumes systemd
rr, err := runner.RunCmd(exec.Command("sudo", "systemctl", "cat", "docker.service"))
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/download/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func ImageExistsInDaemon(img string) bool {
klog.Warningf("failed to list docker images: %v", err)
return false
}
if !strings.Contains(string(output), image.TrimDockerIO(img)) {
if !strings.Contains(string(output), img) {
return false
}
correctArch, err := isImageCorrectArch(img)
Expand Down
6 changes: 0 additions & 6 deletions pkg/minikube/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,3 @@ func normalizeTagName(image string) string {
}
return base + ":" + tag
}

// Remove docker.io prefix since it won't be included in image names
// when we call `docker images`.
func TrimDockerIO(name string) string {
return strings.TrimPrefix(name, "docker.io/")
}

0 comments on commit a7cb5fa

Please sign in to comment.