-
Notifications
You must be signed in to change notification settings - Fork 128
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
[ISSUE #185] Fix pod ready status reflect to cr #186
Conversation
@@ -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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we check PodReady
status at this stage? The brokers may be just started and initializing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I means we should wait pod to be ready, then execute follow reconcile code(
rocketmq-operator/pkg/controller/broker/broker_controller.go
Lines 277 to 343 in a866571
if broker.Status.Size != 0 && broker.Spec.Size > broker.Status.Size { | |
// Get the metadata including subscriptionGroup.json and topics.json from scale source pod | |
k8s, err := tool.NewK8sClient() | |
if err != nil { | |
log.Error(err, "Error occurred while getting K8s Client") | |
} | |
sourcePodName := broker.Spec.ScalePodName | |
topicsCommand := getCopyMetadataJsonCommand(cons.TopicJsonDir, sourcePodName, broker.Namespace, k8s) | |
log.Info("topicsCommand: " + topicsCommand) | |
subscriptionGroupCommand := getCopyMetadataJsonCommand(cons.SubscriptionGroupJsonDir, sourcePodName, broker.Namespace, k8s) | |
log.Info("subscriptionGroupCommand: " + subscriptionGroupCommand) | |
MakeConfigDirCommand := "mkdir -p " + cons.StoreConfigDir | |
ChmodDirCommand := "chmod a+rw " + cons.StoreConfigDir | |
cmdContent := MakeConfigDirCommand + " && " + ChmodDirCommand | |
if topicsCommand != "" { | |
cmdContent = cmdContent + " && " + topicsCommand | |
} | |
if subscriptionGroupCommand != "" { | |
cmdContent = cmdContent + " && " + subscriptionGroupCommand | |
} | |
cmd = []string{"/bin/bash", "-c", cmdContent} | |
} | |
// Update status.Size if needed | |
if broker.Spec.Size != broker.Status.Size { | |
log.Info("broker.Status.Size = " + strconv.Itoa(broker.Status.Size)) | |
log.Info("broker.Spec.Size = " + strconv.Itoa(broker.Spec.Size)) | |
broker.Status.Size = broker.Spec.Size | |
err = r.client.Status().Update(context.TODO(), broker) | |
if err != nil { | |
reqLogger.Error(err, "Failed to update Broker Size status.") | |
} | |
} | |
// Update status.Nodes if needed | |
if !reflect.DeepEqual(podNames, broker.Status.Nodes) { | |
broker.Status.Nodes = podNames | |
err = r.client.Status().Update(context.TODO(), broker) | |
if err != nil { | |
reqLogger.Error(err, "Failed to update Broker Nodes status.") | |
} | |
} | |
//podList := &corev1.PodList{} | |
//labelSelector := labels.SelectorFromSet(labelsForBroker(broker.Name)) | |
//listOps := &client.ListOptions{ | |
// Namespace: broker.Namespace, | |
// LabelSelector: labelSelector, | |
//} | |
//err = r.client.List(context.TODO(), listOps, podList) | |
//if err != nil { | |
// reqLogger.Error(err, "Failed to list pods.", "Broker.Namespace", broker.Namespace, "Broker.Name", broker.Name) | |
// return reconcile.Result{}, err | |
//} | |
//podNames := getPodNames(podList.Items) | |
// | |
//// Update status.Nodes if needed | |
//if !reflect.DeepEqual(podNames, broker.Status.Nodes) { | |
// broker.Status.Nodes = podNames | |
// err := r.client.Status().Update(context.TODO(), broker) | |
// if err != nil { | |
// reqLogger.Error(err, "Failed to update Broker status.") | |
// return reconcile.Result{}, err | |
// } | |
//} | |
return reconcile.Result{Requeue: true, RequeueAfter: time.Duration(cons.RequeueIntervalInSecond) * time.Second}, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how do you think about it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What is the purpose of the change
#185
Brief changelog
Fix pod ready status reflect to cr.
Verifying this change
Apply:
Status always empty
Please go through this checklist to help us incorporate your contribution quickly and easily.
Notice:
It would be helpful if you could finish the following checklist (the last one is not necessary) before request the community to review your PR
.[ISSUE #123] Fix UnknownException when host config not exist
. Each commit in the pull request should have a meaningful subject line and body.make docker-build
to build docker image for operator, try your changes from Pod inside your Kubernetes cluster, not just locally. Also provide screenshots to show that the RocketMQ cluster is healthy after the changes.make manifests
to make sure the CRD files are updated.