kubernetes / minikube

Run Kubernetes locally
https://minikube.sigs.k8s.io/
Apache License 2.0
28.78k stars 4.81k forks source link

Can't load the image that is in the localhost registry #19155

Open smartroaddev opened 1 week ago

smartroaddev commented 1 week ago

What Happened?

I used podman to built the image into localhost registry then tried to load image via "minikube image load" command but it was failed. Is there a reason to not allow image in localhost registry to be loaded? I tested with other registry name without "." it was happening too.

Attach the log file

Screenshot from 2024-06-28 15-48-25

Operating System

Redhat/Fedora

Driver

Podman

afbjorklund commented 1 week ago

Try without the "localhost/" prefix, it is not a real registry but just an annoying prefix that podman adds.

This full name is buggy: docker.io/localhost/..., it was not supposed to add the default registry there...

smartroaddev commented 1 week ago

Actually, I've try other registry names and success. But do minikube have a plan to support local built registry name?

afbjorklund commented 1 week ago

Well, it's a bug. It is supposed to not add any registry when one is present, even if it is a fake host it is still there.

Possibly related to this hack:

// addRepoTagToImageName makes sure the image name has a repo tag in it.
// in crictl images list have the repo tag prepended to them
// for example "kubernetesui/dashboard:v2.0.0 will show up as "docker.io/kubernetesui/dashboard:v2.0.0"
// warning this is only meant for kubernetes images where we know the GCR addresses have .io in them
// not mean to be used for public images
func addRepoTagToImageName(imgName string) string {
        if !strings.Contains(imgName, ".io/") {
                return "docker.io/" + imgName
        } // else it already has repo name dont add anything
        return imgName
}

Which should use the real code...


https://pkg.go.dev/github.com/distribution/reference#ParseNormalizedNamed

// ParseImageName parses a docker image string into three parts: repo, tag and digest.
// If both tag and digest are empty, a default image tag will be returned.
func ParseImageName(image string) (string, string, string, error) {
        named, err := dockerref.ParseNormalizedNamed(image)
        if err != nil {
                return "", "", "", fmt.Errorf("couldn't parse image name %q: %v", image, err)
        }

        repoToPull := named.Name()
        var tag, digest string

        tagged, ok := named.(dockerref.Tagged)
        if ok {
                tag = tagged.Tag()
        }

        digested, ok := named.(dockerref.Digested)
        if ok {
                digest = digested.Digest().String()
        }
        // If no tag was specified, use the default "latest".
        if len(tag) == 0 && len(digest) == 0 {
                tag = "latest"
        }
        return repoToPull, tag, digest, nil
}