Skip to content

Commit

Permalink
Pod ready status reflect to cr (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
drivebyer authored Dec 22, 2023
1 parent a866571 commit d5e797b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/controller/broker/broker_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,15 @@ func (r *ReconcileBroker) Reconcile(ctx context.Context, request reconcile.Reque
podNames := getPodNames(podList.Items)
log.Info("broker.Status.Nodes length = " + strconv.Itoa(len(broker.Status.Nodes)))
log.Info("podNames length = " + strconv.Itoa(len(podNames)))
// Ensure every pod is in running phase
// Ensure every pod is in ready
for _, pod := range podList.Items {
if !reflect.DeepEqual(pod.Status.Phase, corev1.PodRunning) {
log.Info("pod " + pod.Name + " phase is " + string(pod.Status.Phase) + ", wait for a moment...")
}
if !isReady(pod) {
reqLogger.Info("pod " + pod.Name + " is not ready, wait for a moment...")
return reconcile.Result{Requeue: true, RequeueAfter: time.Duration(cons.RequeueIntervalInSecond) * time.Second}, nil
}
}

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

func isReady(po corev1.Pod) bool {
for _, cond := range po.Status.Conditions {
if cond.Type == corev1.PodReady {
return cond.Status == corev1.ConditionTrue
}
}
return false
}

// getBrokerStatefulSet returns a broker StatefulSet object
func (r *ReconcileBroker) getBrokerStatefulSet(broker *rocketmqv1alpha1.Broker, brokerGroupIndex int, replicaIndex int) *appsv1.StatefulSet {
ls := labelsForBroker(broker.Name)
Expand Down

0 comments on commit d5e797b

Please sign in to comment.