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

Replace fixed time wait with wait function for docker-env cmd #10021

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
38 changes: 36 additions & 2 deletions cmd/minikube/cmd/docker-env.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ import (
"strings"
"time"

apiWait "k8s.io/apimachinery/pkg/util/wait"

"github.com/spf13/cobra"
"k8s.io/klog/v2"

kconst "k8s.io/kubernetes/cmd/kubeadm/app/constants"
"k8s.io/minikube/pkg/drivers/kic/oci"
"k8s.io/minikube/pkg/minikube/bootstrapper/bsutil/kverify"
"k8s.io/minikube/pkg/minikube/command"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/driver"
Expand All @@ -45,6 +49,8 @@ import (
"k8s.io/minikube/pkg/minikube/sysinit"
)

const minLogCheckTime = 60 * time.Second

var dockerEnvTCPTmpl = fmt.Sprintf(
"{{ .Prefix }}%s{{ .Delimiter }}{{ .DockerTLSVerify }}{{ .Suffix }}"+
"{{ .Prefix }}%s{{ .Delimiter }}{{ .DockerHost }}{{ .Suffix }}"+
Expand Down Expand Up @@ -193,9 +199,37 @@ func mustRestartDockerd(name string, runner command.Runner) {
// if we get to the point that we have to restart docker (instead of reload)
// will need to wait for apisever container to come up, this usually takes 5 seconds
// verifying apisever using kverify would add code complexity for a rare case.
klog.Warningf("waiting 5 seconds to ensure apisever container is up...")
time.Sleep(time.Second * 5)
klog.Warningf("waiting to ensure apisever container is up...")
startTime := time.Now()
if err = WaitForAPIServerProcess(runner, startTime, time.Second*30); err != nil {
exit.Message(reason.RuntimeRestart, `The api server within '{{.name}}' is not up`, out.V{"name": name})
azhao155 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

func WaitForAPIServerProcess(cr command.Runner, start time.Time, timeout time.Duration) error {
azhao155 marked this conversation as resolved.
Show resolved Hide resolved
klog.Infof("waiting for apiserver process to appear ...")
err := apiWait.PollImmediate(time.Millisecond*500, timeout, func() (bool, error) {
if time.Since(start) > timeout {
return false, fmt.Errorf("cluster wait timed out during process check")
}

if time.Since(start) > minLogCheckTime {
klog.Infof("waiting for apiserver process to appear ...")
time.Sleep(kconst.APICallRetryInterval * 5)
}

if _, ierr := kverify.APIServerPID(cr); ierr != nil {
return false, nil
}

return true, nil
})
if err != nil {
return fmt.Errorf("apiserver process never appeared")
}
klog.Infof("duration metric: took %s to wait for apiserver process to appear ...", time.Since(start))
return nil
}

// dockerEnvCmd represents the docker-env command
Expand Down
8 changes: 4 additions & 4 deletions pkg/minikube/bootstrapper/bsutil/kverify/api_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func WaitForAPIServerProcess(r cruntime.Manager, bs bootstrapper.Bootstrapper, c
time.Sleep(kconst.APICallRetryInterval * 5)
}

if _, ierr := apiServerPID(cr); ierr != nil {
if _, ierr := APIServerPID(cr); ierr != nil {
return false, nil
}

Expand All @@ -69,8 +69,8 @@ func WaitForAPIServerProcess(r cruntime.Manager, bs bootstrapper.Bootstrapper, c
return nil
}

// apiServerPID returns our best guess to the apiserver pid
func apiServerPID(cr command.Runner) (int, error) {
// APIServerPID returns our best guess to the apiserver pid
func APIServerPID(cr command.Runner) (int, error) {
rr, err := cr.RunCmd(exec.Command("sudo", "pgrep", "-xnf", "kube-apiserver.*minikube.*"))
if err != nil {
return 0, err
Expand Down Expand Up @@ -145,7 +145,7 @@ func APIServerVersionMatch(client *kubernetes.Clientset, expected string) error
func APIServerStatus(cr command.Runner, hostname string, port int) (state.State, error) {
klog.Infof("Checking apiserver status ...")

pid, err := apiServerPID(cr)
pid, err := APIServerPID(cr)
if err != nil {
klog.Warningf("stopped: unable to get apiserver pid: %v", err)
return state.Stopped, nil
Expand Down