Skip to content

Commit 3fef3ea

Browse files
fix --wait's failure to work on coredns pods (#19748)
* fix --wait's failure to work on coredns pods * fix ha test failure
1 parent f909b0d commit 3fef3ea

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

pkg/minikube/bootstrapper/bsutil/kverify/system_pods.go

+24-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ func WaitForSystemPods(r cruntime.Manager, bs bootstrapper.Bootstrapper, cfg con
7676
}
7777

7878
// ExpectAppsRunning returns whether or not all expected k8s-apps are running. (without waiting for them)
79-
func ExpectAppsRunning(cs *kubernetes.Clientset, expected []string) error {
79+
func ExpectAppsRunning(cfg *config.ClusterConfig, cs *kubernetes.Clientset, expected []string) error {
80+
8081
found := map[string]bool{}
8182

8283
pods, err := cs.CoreV1().Pods("kube-system").List(context.Background(), meta.ListOptions{})
@@ -85,12 +86,32 @@ func ExpectAppsRunning(cs *kubernetes.Clientset, expected []string) error {
8586
}
8687
klog.Infof("%d kube-system pods found", len(pods.Items))
8788

89+
for !config.IsHA(*cfg) && !cfg.DisableOptimizations {
90+
// when --disable-optimization is not specified
91+
// for non-HA cluster
92+
// core dns deployment has been scaled to 1 pods, wait until there is only 1 pod
93+
corednsPods, err := cs.CoreV1().Pods("kube-system").List(context.Background(), meta.ListOptions{
94+
LabelSelector: "k8s-app=kube-dns",
95+
})
96+
if err != nil {
97+
return err
98+
}
99+
if len(corednsPods.Items) == 1 {
100+
break
101+
}
102+
}
103+
88104
for _, pod := range pods.Items {
89105
klog.Info(podStatusMsg(pod))
90106

91107
if pod.Status.Phase != core.PodRunning {
92108
continue
93109
}
110+
for _, cs := range pod.Status.ContainerStatuses {
111+
if !cs.Ready {
112+
continue
113+
}
114+
}
94115

95116
for k, v := range pod.ObjectMeta.Labels {
96117
if k == "component" || k == "k8s-app" {
@@ -112,12 +133,12 @@ func ExpectAppsRunning(cs *kubernetes.Clientset, expected []string) error {
112133
}
113134

114135
// WaitForAppsRunning waits for expected Apps To be running
115-
func WaitForAppsRunning(cs *kubernetes.Clientset, expected []string, timeout time.Duration) error {
136+
func WaitForAppsRunning(cfg *config.ClusterConfig, cs *kubernetes.Clientset, expected []string, timeout time.Duration) error {
116137
klog.Info("waiting for k8s-apps to be running ...")
117138
start := time.Now()
118139

119140
checkRunning := func() error {
120-
return ExpectAppsRunning(cs, expected)
141+
return ExpectAppsRunning(cfg, cs, expected)
121142
}
122143

123144
if err := retry.Local(checkRunning, timeout); err != nil {

pkg/minikube/bootstrapper/kubeadm/kubeadm.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ func (k *Bootstrapper) WaitForNode(cfg config.ClusterConfig, n config.Node, time
567567
}
568568

569569
if cfg.VerifyComponents[kverify.AppsRunningKey] {
570-
if err := kverify.WaitForAppsRunning(client, kverify.AppsRunningList, timeout); err != nil {
570+
if err := kverify.WaitForAppsRunning(&cfg, client, kverify.AppsRunningList, timeout); err != nil {
571571
return errors.Wrap(err, "waiting for apps_running")
572572
}
573573
}

0 commit comments

Comments
 (0)