Skip to content

Commit

Permalink
when the broker uses hostNetwork, the broker's IP returned by NameSer…
Browse files Browse the repository at this point in the history
…ver is the IP of the k8s node where the broker is located.
  • Loading branch information
usernameisnull committed Dec 22, 2023
1 parent a866571 commit 2ecdb14
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion images/broker/alpine/brokerGenConfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ 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
# If the STATUS_POD_IP ip is not empty, the pod uses hostNetwork: true
if [ -n "${HOST_NETWORK_POD_IP}" ]; then
echo "brokerIP1=${HOST_NETWORK_POD_IP}" >> ${BROKER_CONFIG_FILE}
else
echo "brokerIP1=`hostname -i`" >> $BROKER_CONFIG_FILE
fi
if [ $BROKER_ID != 0 ]; then
sed -i 's/brokerRole=.*/brokerRole=SLAVE/g' $BROKER_CONFIG_FILE
fi
Expand Down
2 changes: 2 additions & 0 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,6 @@ const (

// EnvControllerAddr is the container environment variable name of Controller address in Broker
EnvControllerAddr = "controllerAddr"
// EnvHostNetworkPodIp is the container environment variable name of host network pod ip, to help the brokerStart.sh script to get the host network pod ip
EnvHostNetworkPodIp = "HOST_NETWORK_POD_IP"
)
12 changes: 12 additions & 0 deletions pkg/controller/broker/broker_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,18 @@ func getENV(broker *rocketmqv1alpha1.Broker, replicaIndex int, brokerGroupIndex
envs = append(envs, corev1.EnvVar{Name: cons.EnvEnableControllerMode, Value: "true"})
envs = append(envs, corev1.EnvVar{Name: cons.EnvControllerAddr, Value: share.ControllerAccessPoint})
}
if broker.Spec.HostNetwork {
envs = append(
envs,
corev1.EnvVar{
Name: cons.EnvHostNetworkPodIp,
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "status.podIP"},
},
},
)
}
envs = append(envs, broker.Spec.Env...)
return envs
}
Expand Down

0 comments on commit 2ecdb14

Please sign in to comment.