Skip to content

Commit d5e797b

Browse files
authored
Pod ready status reflect to cr (#186)
1 parent a866571 commit d5e797b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

pkg/controller/broker/broker_controller.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,15 @@ func (r *ReconcileBroker) Reconcile(ctx context.Context, request reconcile.Reque
267267
podNames := getPodNames(podList.Items)
268268
log.Info("broker.Status.Nodes length = " + strconv.Itoa(len(broker.Status.Nodes)))
269269
log.Info("podNames length = " + strconv.Itoa(len(podNames)))
270-
// Ensure every pod is in running phase
270+
// Ensure every pod is in ready
271271
for _, pod := range podList.Items {
272272
if !reflect.DeepEqual(pod.Status.Phase, corev1.PodRunning) {
273273
log.Info("pod " + pod.Name + " phase is " + string(pod.Status.Phase) + ", wait for a moment...")
274274
}
275+
if !isReady(pod) {
276+
reqLogger.Info("pod " + pod.Name + " is not ready, wait for a moment...")
277+
return reconcile.Result{Requeue: true, RequeueAfter: time.Duration(cons.RequeueIntervalInSecond) * time.Second}, nil
278+
}
275279
}
276280

277281
if broker.Status.Size != 0 && broker.Spec.Size > broker.Status.Size {
@@ -398,6 +402,15 @@ func getBrokerName(broker *rocketmqv1alpha1.Broker, brokerGroupIndex int) string
398402
return broker.Name + "-" + strconv.Itoa(brokerGroupIndex)
399403
}
400404

405+
func isReady(po corev1.Pod) bool {
406+
for _, cond := range po.Status.Conditions {
407+
if cond.Type == corev1.PodReady {
408+
return cond.Status == corev1.ConditionTrue
409+
}
410+
}
411+
return false
412+
}
413+
401414
// getBrokerStatefulSet returns a broker StatefulSet object
402415
func (r *ReconcileBroker) getBrokerStatefulSet(broker *rocketmqv1alpha1.Broker, brokerGroupIndex int, replicaIndex int) *appsv1.StatefulSet {
403416
ls := labelsForBroker(broker.Name)

0 commit comments

Comments
 (0)