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 4 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
11 changes: 2 additions & 9 deletions pkg/minikube/cruntime/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,15 +604,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 = download.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 = download.TrimDockerIO(i)
if _, ok := preloadedImages[i]; !ok {
klog.Infof("%s wasn't preloaded", i)
return false
Expand Down Expand Up @@ -644,13 +644,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
8 changes: 7 additions & 1 deletion pkg/minikube/download/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,19 @@ func ImageExistsInCache(img string) bool {

var checkImageExistsInCache = ImageExistsInCache

// 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/")
}

// ImageExistsInDaemon if img exist in local docker daemon
func ImageExistsInDaemon(img string) bool {
// Check if image exists locally
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), TrimDockerIO(img)) {
klog.Infof("Found %s in local docker daemon, skipping pull", img)
return true
}
Expand Down