You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by du...@apache.org on 2022/03/25 02:01:12 UTC
[rocketmq-operator] branch master updated: fix #80 by skipping generating data replication command when remote command returns error
This is an automated email from the ASF dual-hosted git repository.
duhengforever pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-operator.git
The following commit(s) were added to refs/heads/master by this push:
new b640c94 fix #80 by skipping generating data replication command when remote command returns error
new abb2ebd Merge pull request #82 from caigy/issue-80
b640c94 is described below
commit b640c949c8a6c2ea714ecf81087d1b73c4529515
Author: caigy <cs...@163.com>
AuthorDate: Thu Aug 26 21:06:31 2021 +0800
fix #80 by skipping generating data replication command when remote command returns error
---
pkg/controller/broker/broker_controller.go | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/pkg/controller/broker/broker_controller.go b/pkg/controller/broker/broker_controller.go
index 5b2de77..8bcc8db 100644
--- a/pkg/controller/broker/broker_controller.go
+++ b/pkg/controller/broker/broker_controller.go
@@ -273,7 +273,14 @@ func (r *ReconcileBroker) Reconcile(request reconcile.Request) (reconcile.Result
log.Info("subscriptionGroupCommand: " + subscriptionGroupCommand)
MakeConfigDirCommand := "mkdir -p " + cons.StoreConfigDir
ChmodDirCommand := "chmod a+rw " + cons.StoreConfigDir
- cmd = []string{"/bin/bash", "-c", MakeConfigDirCommand + " && " + ChmodDirCommand + " && " + topicsCommand + " && " + subscriptionGroupCommand}
+ cmdContent := MakeConfigDirCommand + " && " + ChmodDirCommand
+ if topicsCommand != "" {
+ cmdContent = cmdContent + " && " + topicsCommand
+ }
+ if subscriptionGroupCommand != "" {
+ cmdContent = cmdContent + " && " + subscriptionGroupCommand
+ }
+ cmd = []string{"/bin/bash", "-c", cmdContent}
}
// Update status.Size if needed
@@ -324,7 +331,11 @@ func (r *ReconcileBroker) Reconcile(request reconcile.Request) (reconcile.Result
func getCopyMetadataJsonCommand(dir string, sourcePodName string, namespace string, k8s *tool.K8sClient) string {
cmdOpts := buildInputCommand(dir)
- topicsJsonStr := exec(cmdOpts, sourcePodName, k8s, namespace)
+ topicsJsonStr, err := exec(cmdOpts, sourcePodName, k8s, namespace)
+ if err != nil {
+ log.Error(err, "exec command failed, output is: "+output)
+ return ""
+ }
topicsCommand := buildOutputCommand(topicsJsonStr, dir)
return strings.Join(topicsCommand, " ")
}
@@ -349,7 +360,7 @@ func buildOutputCommand(content string, dest string) []string {
return cmdOpts
}
-func exec(cmdOpts []string, podName string, k8s *tool.K8sClient, namespace string) string {
+func exec(cmdOpts []string, podName string, k8s *tool.K8sClient, namespace string) (string, error) {
log.Info("On pod " + podName + ", command being run: " + strings.Join(cmdOpts, " "))
container := cons.BrokerContainerName
outputBytes, stderrBytes, err := k8s.Exec(namespace, podName, container, cmdOpts, nil)
@@ -359,14 +370,14 @@ func exec(cmdOpts []string, podName string, k8s *tool.K8sClient, namespace strin
if stderrBytes != nil {
log.Info("STDERR: " + stderr)
}
+ log.Info("output: " + output)
if err != nil {
log.Error(err, "Error occurred while running command: "+strings.Join(cmdOpts, " "))
- log.Info("stdout: " + output)
- } else {
- log.Info("output: " + output)
+ return output, err
}
- return output
+
+ return output, nil
}
func getBrokerName(broker *rocketmqv1alpha1.Broker, brokerGroupIndex int) string {