From 07ea0ec0a4b1906f274d910dbaf4d02d2b16833a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Wed, 3 Feb 2021 17:26:06 +0100 Subject: [PATCH] Wait for the CRI socket to be created properly Before returning the container runtime back to the caller. Wait for a minute (usually 1 second) Note that this doesn't apply to the dockershim, it only replies to runtimes that are using CRI. --- pkg/minikube/node/start.go | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/pkg/minikube/node/start.go b/pkg/minikube/node/start.go index d1081fd7bb..b17df750f6 100644 --- a/pkg/minikube/node/start.go +++ b/pkg/minikube/node/start.go @@ -277,6 +277,12 @@ func configureRuntimes(runner cruntime.CommandRunner, cc config.ClusterConfig, k exit.Error(reason.RuntimeEnable, "Failed to enable container runtime", err) } + // Wait for the CRI to be "live", before returning it + err = waitForCRISocket(runner, cr.SocketPath(), 60, 1) + if err != nil { + exit.Error(reason.RuntimeEnable, "Failed to start container runtime", err) + } + return cr } @@ -284,6 +290,42 @@ func forceSystemd() bool { return viper.GetBool("force-systemd") || os.Getenv(constants.MinikubeForceSystemdEnv) == "true" } +func pathExists(runner cruntime.CommandRunner, path string) (bool, error) { + _, err := runner.RunCmd(exec.Command("stat", path)) + if err == nil { + return true, nil + } + if os.IsNotExist(err) { + return false, nil + } + return false, err +} + +func waitForCRISocket(runner cruntime.CommandRunner, socket string, wait int, interval int) error { + + if socket == "" || socket == "/var/run/dockershim.sock" { + return nil + } + + klog.Infof("Will wait %ds for socket path %s", wait, socket) + + chkPath := func() error { + e, err := pathExists(runner, socket) + if err != nil { + return err + } + if !e { + return &retry.RetriableError{Err: err} + } + return nil + } + if err := retry.Expo(chkPath, time.Duration(interval)*time.Second, time.Duration(wait)*time.Second); err != nil { + return err + } + + return nil +} + // setupKubeAdm adds any requested files into the VM before Kubernetes is started func setupKubeAdm(mAPI libmachine.API, cfg config.ClusterConfig, n config.Node, r command.Runner) bootstrapper.Bootstrapper { bs, err := cluster.Bootstrapper(mAPI, viper.GetString(cmdcfg.Bootstrapper), cfg, r)