Merge pull request #10356 from afbjorklund/cri-socket-wait

Wait for the CRI socket to be created properly
pull/10393/head
Medya Ghazizadeh 2021-02-05 18:50:27 -08:00 committed by GitHub
commit bdd1e6de6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 42 additions and 0 deletions

View File

@ -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)