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

fix: trim docker.io to prevent always writing to daemon #14956

Merged
merged 5 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 3 additions & 9 deletions pkg/minikube/cruntime/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"k8s.io/minikube/pkg/minikube/config"
"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 @@ -604,15 +605,15 @@ func dockerImagesPreloaded(runner command.Runner, images []string) bool {
}
preloadedImages := map[string]struct{}{}
for _, i := range strings.Split(rr.Stdout.String(), "\n") {
i = trimDockerIO(i)
i = image.TrimDockerIO(i)
preloadedImages[i] = struct{}{}
}

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

// Make sure images == imgs
for _, i := range images {
i = trimDockerIO(i)
i = image.TrimDockerIO(i)
if _, ok := preloadedImages[i]; !ok {
klog.Infof("%s wasn't preloaded", i)
return false
Expand Down Expand Up @@ -644,13 +645,6 @@ func addDockerIO(name string) string {
return reg + "/" + img
}

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

func dockerBoundToContainerd(runner command.Runner) bool {
// NOTE: assumes systemd
rr, err := runner.RunCmd(exec.Command("sudo", "systemctl", "cat", "docker.service"))
Expand Down
3 changes: 2 additions & 1 deletion pkg/minikube/download/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/pkg/errors"
"k8s.io/klog/v2"
"k8s.io/minikube/pkg/minikube/detect"
"k8s.io/minikube/pkg/minikube/image"
"k8s.io/minikube/pkg/minikube/localpath"
)

Expand Down Expand Up @@ -75,7 +76,7 @@ func ImageExistsInDaemon(img string) bool {
klog.Infof("Checking for %s in local docker daemon", img)
cmd := exec.Command("docker", "images", "--format", "{{.Repository}}:{{.Tag}}@{{.Digest}}")
if output, err := cmd.Output(); err == nil {
if strings.Contains(string(output), img) {
if strings.Contains(string(output), image.TrimDockerIO(img)) {
klog.Infof("Found %s in local docker daemon, skipping pull", img)
return true
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/minikube/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,9 @@ 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/")
}