This is an automated email from the ASF dual-hosted git repository.

caigy 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 455dc24  use right ip to register broker when in hostnetwork (#203)
455dc24 is described below

commit 455dc2403791fc439a63a471175e0bae6743e058
Author: usernameisnull <rangerforce...@gmail.com>
AuthorDate: Sun Feb 4 15:10:57 2024 +0800

    use right ip to register broker when in hostnetwork (#203)
---
 images/broker/alpine/brokerGenConfig.sh    | 3 ++-
 pkg/constants/constants.go                 | 3 +++
 pkg/controller/broker/broker_controller.go | 6 ++++++
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/images/broker/alpine/brokerGenConfig.sh 
b/images/broker/alpine/brokerGenConfig.sh
index 033dda7..5c290c7 100755
--- a/images/broker/alpine/brokerGenConfig.sh
+++ b/images/broker/alpine/brokerGenConfig.sh
@@ -27,7 +27,8 @@ function create_config() {
     echo "brokerClusterName=$BROKER_CLUSTER_NAME" >> $BROKER_CONFIG_FILE
     echo "brokerName=$BROKER_NAME" >> $BROKER_CONFIG_FILE
     echo "brokerId=$BROKER_ID" >> $BROKER_CONFIG_FILE
-    echo "brokerIP1=`hostname -i`" >> $BROKER_CONFIG_FILE
+
+    echo "brokerIP1=${POD_IP}" >> $BROKER_CONFIG_FILE
     if [ $BROKER_ID != 0 ]; then
         sed -i 's/brokerRole=.*/brokerRole=SLAVE/g' $BROKER_CONFIG_FILE
     fi
diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go
index 653b3d7..cc5e209 100644
--- a/pkg/constants/constants.go
+++ b/pkg/constants/constants.go
@@ -172,4 +172,7 @@ const (
 
        // EnvControllerAddr is the container environment variable name of 
Controller address in Broker
        EnvControllerAddr = "controllerAddr"
+
+       // EnvPodIp is the container environment variable name of pod ip.
+       EnvPodIp = "POD_IP"
 )
diff --git a/pkg/controller/broker/broker_controller.go 
b/pkg/controller/broker/broker_controller.go
index 86d2b8a..f6ea664 100644
--- a/pkg/controller/broker/broker_controller.go
+++ b/pkg/controller/broker/broker_controller.go
@@ -525,6 +525,12 @@ func getENV(broker *rocketmqv1alpha1.Broker, replicaIndex 
int, brokerGroupIndex
        }, {
                Name:  cons.EnvBrokerName,
                Value: broker.Name + "-" + strconv.Itoa(brokerGroupIndex),
+       }, {
+               Name: cons.EnvPodIp,
+               ValueFrom: &corev1.EnvVarSource{
+                       FieldRef: &corev1.ObjectFieldSelector{
+                               FieldPath: "status.podIP"},
+               },
        }}
        if broker.Spec.ClusterMode == "CONTROLLER" {
                envs = append(envs, corev1.EnvVar{Name: 
cons.EnvEnableControllerMode, Value: "true"})

Reply via email to