From aa1ed99aa1d914c476cf535990d3f006aeaa4db6 Mon Sep 17 00:00:00 2001 From: Rory Z <16801068+Rory-Z@users.noreply.github.com> Date: Tue, 9 Apr 2024 17:10:33 +0800 Subject: [PATCH] chore: pick container ready pods Signed-off-by: Rory Z <16801068+Rory-Z@users.noreply.github.com> --- controllers/apps/v2beta1/emqx_controller.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/controllers/apps/v2beta1/emqx_controller.go b/controllers/apps/v2beta1/emqx_controller.go index d64d7f6f..05948851 100644 --- a/controllers/apps/v2beta1/emqx_controller.go +++ b/controllers/apps/v2beta1/emqx_controller.go @@ -121,6 +121,7 @@ func (r *EMQXReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl. for _, subReconciler := range []subReconciler{ &addBootstrap{r}, + &updatePodConditions{r}, &updateStatus{r}, &syncConfig{r}, &addCore{r}, @@ -198,13 +199,17 @@ func newRequester(ctx context.Context, k8sClient client.Client, instance *appsv2 }) for _, pod := range podList.Items { - if pod.GetDeletionTimestamp() == nil && pod.Status.Phase == corev1.PodRunning && pod.Status.PodIP != "" { - return &innerReq.Requester{ - Schema: schema, - Host: net.JoinHostPort(pod.Status.PodIP, port), - Username: username, - Password: password, - }, nil + if pod.GetDeletionTimestamp() == nil && pod.Status.PodIP != "" { + for _, cond := range pod.Status.Conditions { + if cond.Type == corev1.ContainersReady && cond.Status == corev1.ConditionTrue { + return &innerReq.Requester{ + Schema: schema, + Host: net.JoinHostPort(pod.Status.PodIP, port), + Username: username, + Password: password, + }, nil + } + } } }