Skip to content
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 #202 #159]when the broker uses hostNetwork, the IP registered by the broker to the nameserver is not the podIP #203

Merged
merged 1 commit into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion images/broker/alpine/brokerGenConfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
6 changes: 6 additions & 0 deletions pkg/controller/broker/broker_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand Down