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

fix --wait's failure to work on coredns pods #19748

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
27 changes: 24 additions & 3 deletions pkg/minikube/bootstrapper/bsutil/kverify/system_pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ func WaitForSystemPods(r cruntime.Manager, bs bootstrapper.Bootstrapper, cfg con
}

// ExpectAppsRunning returns whether or not all expected k8s-apps are running. (without waiting for them)
func ExpectAppsRunning(cs *kubernetes.Clientset, expected []string) error {
func ExpectAppsRunning(cfg *config.ClusterConfig, cs *kubernetes.Clientset, expected []string) error {

found := map[string]bool{}

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

for !config.IsHA(*cfg) && !cfg.DisableOptimizations {
// when --disable-optimization is not specified
// for non-HA cluster
// core dns deployment has been scaled to 1 pods, wait until there is only 1 pod
corednsPods, err := cs.CoreV1().Pods("kube-system").List(context.Background(), meta.ListOptions{
LabelSelector: "k8s-app=kube-dns",
})
if err != nil {
return err
}
if len(corednsPods.Items) == 1 {
ComradeProgrammer marked this conversation as resolved.
Show resolved Hide resolved
break
}
}

for _, pod := range pods.Items {
klog.Info(podStatusMsg(pod))

if pod.Status.Phase != core.PodRunning {
continue
}
for _, cs := range pod.Status.ContainerStatuses {
if !cs.Ready {
continue
}
}

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

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

checkRunning := func() error {
return ExpectAppsRunning(cs, expected)
return ExpectAppsRunning(cfg, cs, expected)
}

if err := retry.Local(checkRunning, timeout); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ func (k *Bootstrapper) WaitForNode(cfg config.ClusterConfig, n config.Node, time
}

if cfg.VerifyComponents[kverify.AppsRunningKey] {
if err := kverify.WaitForAppsRunning(client, kverify.AppsRunningList, timeout); err != nil {
if err := kverify.WaitForAppsRunning(&cfg, client, kverify.AppsRunningList, timeout); err != nil {
return errors.Wrap(err, "waiting for apps_running")
}
}
Expand Down
Loading