Skip to content

Commit

Permalink
cleanup: remove unused code, make internal-only func private
Browse files Browse the repository at this point in the history
  • Loading branch information
prezha committed Feb 16, 2021
1 parent b8052fe commit 8099f75
Showing 1 changed file with 3 additions and 45 deletions.
48 changes: 3 additions & 45 deletions pkg/minikube/bootstrapper/bsutil/kverify/pod_ready.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func WaitExtra(cs *kubernetes.Clientset, labels []string, timeout time.Duration)

var errs []string
for _, label := range labels {
if err := WaitForPodReadyByLabel(cs, label, "kube-system", timeout); err != nil {
if err := waitForPodReadyByLabel(cs, label, "kube-system", timeout); err != nil {
errs = append(errs, fmt.Sprintf("%q: %q", label, err.Error()))
}
}
Expand All @@ -52,10 +52,10 @@ func WaitExtra(cs *kubernetes.Clientset, labels []string, timeout time.Duration)
return nil
}

// WaitForPodReadyByLabel waits for pod with label ([key:]val) in a namespace to be in Ready condition.
// waitForPodReadyByLabel waits for pod with label ([key:]val) in a namespace to be in Ready condition.
// If namespace is not provided, it defaults to "kube-system".
// If label key is not provided, it will try with "component" and "k8s-app".
func WaitForPodReadyByLabel(cs *kubernetes.Clientset, label, namespace string, timeout time.Duration) error {
func waitForPodReadyByLabel(cs *kubernetes.Clientset, label, namespace string, timeout time.Duration) error {
klog.Infof("waiting %v for pod with %q label in %q namespace to be Ready ...", timeout, label, namespace)
start := time.Now()
defer func() {
Expand Down Expand Up @@ -116,48 +116,6 @@ func WaitForPodReadyByLabel(cs *kubernetes.Clientset, label, namespace string, t
return nil
}

// WaitForPodReadyByName waits for pod with name in a namespace to be in Ready condition.
// If namespace is not provided, it defaults to "kube-system".
func WaitForPodReadyByName(cs *kubernetes.Clientset, name, namespace string, timeout time.Duration) error {
klog.Infof("waiting %v for pod %q in %q namespace to be Ready ...", timeout, name, namespace)
start := time.Now()
defer func() {
klog.Infof("duration metric: took %v to run WaitForPodReadyByName for pod %q in %q namespace ...", time.Since(start), name, namespace)
}()

if namespace == "" {
namespace = "kube-system"
}

lap := time.Now()
checkReady := func() (bool, error) {
if time.Since(start) > timeout {
return false, fmt.Errorf("wait for pod %q in %q namespace to be Ready timed out", name, namespace)
}
pod, err := cs.CoreV1().Pods(namespace).Get(name, meta.GetOptions{})
if err != nil {
klog.Infof("error getting pod %q in %q namespace, will retry: %v", name, namespace, err)
return false, nil
}
ready, reason := IsPodReady(pod)
if ready {
klog.Info(reason)
return true, nil
}
// reduce log spam
if time.Since(lap) > (1 * time.Second) {
klog.Info(reason)
lap = time.Now()
}
return false, nil
}
if err := wait.PollImmediate(kconst.APICallRetryInterval, kconst.DefaultControlPlaneTimeout, checkReady); err != nil {
return errors.Wrapf(err, "wait pod Ready")
}

return nil
}

// IsPodReady returns if pod is Ready and verbose reason.
func IsPodReady(pod *core.Pod) (ready bool, reason string) {
if pod.Status.Phase != core.PodRunning {
Expand Down

0 comments on commit 8099f75

Please sign in to comment.