kubernetes / minikube

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

"warn if docker is slow" logic doesnt work #19577

Open medyagh opened 2 months ago

medyagh commented 2 months ago

when trying to fix this issue https://github.com/kubernetes/minikube/pull/19576 that docker desktop Hangs on listing containers... I didnt get any warnninig from minikube that docker is slow and minikube hanged....

(only with a docker desktop Docker Desktop 4.34.0 with macos)

$ minikube delete --all --alsologtostderr
I0906 10:47:45.127199   28913 out.go:291] Setting OutFile to fd 1 ...
I0906 10:47:45.128263   28913 out.go:343] isatty.IsTerminal(1) = true
I0906 10:47:45.128272   28913 out.go:304] Setting ErrFile to fd 2...
I0906 10:47:45.128278   28913 out.go:343] isatty.IsTerminal(2) = true
I0906 10:47:45.128634   28913 root.go:338] Updating PATH: /Users/medya/.minikube/bin
I0906 10:47:45.130362   28913 out.go:298] Setting JSON to false
I0906 10:47:45.130901   28913 cli_runner.go:164] Run: docker ps -a --filter label=name.minikube.sigs.k8s.io --format {{.Names}}

I remembered that we had a logic that was supposed to Warn users but apparantly that logic doesnt work here is the code that lists the containers in oci.go

// ListContainersByLabel returns all the container names with a specified label
func ListContainersByLabel(ctx context.Context, ociBin string, label string, warnSlow ...bool) ([]string, error) {
    rr, err := runCmd(exec.CommandContext(ctx, ociBin, "ps", "-a", "--filter", fmt.Sprintf("label=%s", label), "--format", "{{.Names}}"), warnSlow...)
    if err != nil {
        return nil, err
    }
    s := bufio.NewScanner(bytes.NewReader(rr.Stdout.Bytes()))
    var names []string
    for s.Scan() {
        n := strings.TrimSpace(s.Text())
        if n != "" {
            names = append(names, n)
        }
    }
    return names, s.Err()

and also here is the runCmd logic that was supposed to Warn users that the docker or podman is returning slow

the logic is in cli_runner.go

// runCmd runs a command exec.Command against docker daemon or podman
func runCmd(cmd *exec.Cmd, warnSlow ...bool) (*RunResult, error) {
    cmd = PrefixCmd(cmd)

    warn := false
    if len(warnSlow) > 0 {
        warn = warnSlow[0]
    }

    killTime := 19 * time.Second // this will be applied only if warnSlow is true
    warnTime := 2 * time.Second

we need to fix this code so it can be triggered the slowness of docker or podman. it really hurts user experience when they try to delete minikube and it just hangs ...without any info

to mock this , you can make a dummy "docker" binary in your path that Waits 10 minutes(to emulate a slow docker)

xcarolan commented 2 months ago

I'll take a look