Skip to content

Commit 455dc24

Browse files
use right ip to register broker when in hostnetwork (#203)
1 parent bd3757e commit 455dc24

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

images/broker/alpine/brokerGenConfig.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ function create_config() {
2727
echo "brokerClusterName=$BROKER_CLUSTER_NAME" >> $BROKER_CONFIG_FILE
2828
echo "brokerName=$BROKER_NAME" >> $BROKER_CONFIG_FILE
2929
echo "brokerId=$BROKER_ID" >> $BROKER_CONFIG_FILE
30-
echo "brokerIP1=`hostname -i`" >> $BROKER_CONFIG_FILE
30+
31+
echo "brokerIP1=${POD_IP}" >> $BROKER_CONFIG_FILE
3132
if [ $BROKER_ID != 0 ]; then
3233
sed -i 's/brokerRole=.*/brokerRole=SLAVE/g' $BROKER_CONFIG_FILE
3334
fi

pkg/constants/constants.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,7 @@ const (
172172

173173
// EnvControllerAddr is the container environment variable name of Controller address in Broker
174174
EnvControllerAddr = "controllerAddr"
175+
176+
// EnvPodIp is the container environment variable name of pod ip.
177+
EnvPodIp = "POD_IP"
175178
)

pkg/controller/broker/broker_controller.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,12 @@ func getENV(broker *rocketmqv1alpha1.Broker, replicaIndex int, brokerGroupIndex
525525
}, {
526526
Name: cons.EnvBrokerName,
527527
Value: broker.Name + "-" + strconv.Itoa(brokerGroupIndex),
528+
}, {
529+
Name: cons.EnvPodIp,
530+
ValueFrom: &corev1.EnvVarSource{
531+
FieldRef: &corev1.ObjectFieldSelector{
532+
FieldPath: "status.podIP"},
533+
},
528534
}}
529535
if broker.Spec.ClusterMode == "CONTROLLER" {
530536
envs = append(envs, corev1.EnvVar{Name: cons.EnvEnableControllerMode, Value: "true"})

0 commit comments

Comments
 (0)