@@ -109,6 +109,53 @@ func (r *Reconciler) addProxySidecar(
109109 // Add proxy sidecar container
110110 podSpec .Containers = append (podSpec .Containers , r .buildProxySidecarContainer (instance ))
111111
112+ // Update RabbitMQ container's readiness probe and ports to match backend configuration
113+ // The RabbitMQ cluster operator sets a probe on port 5671 and exposes ports by default,
114+ // but with the proxy enabled, RabbitMQ only listens on localhost:5673
115+ for i , container := range podSpec .Containers {
116+ if container .Name == "rabbitmq" {
117+ // Override the readiness probe to check the backend port
118+ podSpec .Containers [i ].ReadinessProbe = & corev1.Probe {
119+ ProbeHandler : corev1.ProbeHandler {
120+ TCPSocket : & corev1.TCPSocketAction {
121+ Host : "127.0.0.1" ,
122+ Port : intstr .FromInt32 (int32 (rabbitmqBackendPort )),
123+ },
124+ },
125+ InitialDelaySeconds : 10 ,
126+ TimeoutSeconds : 5 ,
127+ PeriodSeconds : 10 ,
128+ SuccessThreshold : 1 ,
129+ FailureThreshold : 3 ,
130+ }
131+
132+ // Override container ports to only expose management ports (15671, 15691)
133+ // and cluster port (4369). Don't expose AMQP ports since proxy handles those.
134+ podSpec .Containers [i ].Ports = []corev1.ContainerPort {
135+ {
136+ Name : "epmd" ,
137+ ContainerPort : 4369 ,
138+ Protocol : corev1 .ProtocolTCP ,
139+ },
140+ {
141+ Name : "management" ,
142+ ContainerPort : 15671 ,
143+ Protocol : corev1 .ProtocolTCP ,
144+ },
145+ {
146+ Name : "prometheus" ,
147+ ContainerPort : 15691 ,
148+ Protocol : corev1 .ProtocolTCP ,
149+ },
150+ }
151+
152+ Log .Info ("Updated RabbitMQ container for proxy mode" ,
153+ "readinessProbePort" , rabbitmqBackendPort ,
154+ "exposedPorts" , "4369,15671,15691" )
155+ break
156+ }
157+ }
158+
112159 // Add volume for proxy script
113160 if podSpec .Volumes == nil {
114161 podSpec .Volumes = []corev1.Volume {}
@@ -137,6 +184,55 @@ func (r *Reconciler) addProxySidecar(
137184 })
138185 }
139186
187+ // Add rabbitmq-tls volume for TLS certificates (used by both RabbitMQ inter-node and proxy)
188+ // When proxy is enabled, we clear cluster.Spec.TLS to prevent RabbitMQ from configuring
189+ // SSL listeners, but we still need the TLS volumes mounted for:
190+ // 1. RabbitMQ inter-node encryption
191+ // 2. Proxy TLS termination
192+ if instance .Spec .TLS .SecretName != "" {
193+ // Check if rabbitmq-tls volume already exists
194+ tlsVolumeExists := false
195+ for _ , vol := range podSpec .Volumes {
196+ if vol .Name == "rabbitmq-tls" {
197+ tlsVolumeExists = true
198+ break
199+ }
200+ }
201+
202+ if ! tlsVolumeExists {
203+ podSpec .Volumes = append (podSpec .Volumes , corev1.Volume {
204+ Name : "rabbitmq-tls" ,
205+ VolumeSource : corev1.VolumeSource {
206+ Secret : & corev1.SecretVolumeSource {
207+ SecretName : instance .Spec .TLS .SecretName ,
208+ DefaultMode : ptr.To [int32 ](0400 ), // Read-only
209+ },
210+ },
211+ })
212+ }
213+
214+ // Ensure RabbitMQ container has the TLS volume mounted (for inter-node TLS)
215+ for i , container := range podSpec .Containers {
216+ if container .Name == "rabbitmq" {
217+ hasTLSMount := false
218+ for _ , mount := range container .VolumeMounts {
219+ if mount .Name == "rabbitmq-tls" {
220+ hasTLSMount = true
221+ break
222+ }
223+ }
224+ if ! hasTLSMount {
225+ podSpec .Containers [i ].VolumeMounts = append (podSpec .Containers [i ].VolumeMounts , corev1.VolumeMount {
226+ Name : "rabbitmq-tls" ,
227+ MountPath : "/etc/rabbitmq-tls" ,
228+ ReadOnly : true ,
229+ })
230+ }
231+ break
232+ }
233+ }
234+ }
235+
140236 // Add rabbitmq-tls-ca volume if CA is in a separate secret
141237 if instance .Spec .TLS .CaSecretName != "" && instance .Spec .TLS .CaSecretName != instance .Spec .TLS .SecretName {
142238 caVolumeExists := false
@@ -317,10 +413,24 @@ func (r *Reconciler) removeProxySidecar(cluster *rabbitmqv2.RabbitmqCluster) {
317413 }
318414 podSpec .Containers = newContainers
319415
320- // Remove proxy-script volume
416+ // Restore RabbitMQ container's readiness probe and ports to defaults
417+ // When proxy is removed, RabbitMQ listens on standard ports again
418+ // Setting these to nil allows the cluster operator to restore its defaults
419+ if removed {
420+ for i , container := range podSpec .Containers {
421+ if container .Name == "rabbitmq" {
422+ podSpec .Containers [i ].ReadinessProbe = nil
423+ podSpec .Containers [i ].Ports = nil
424+ Log .Info ("Restored RabbitMQ container configuration to defaults" )
425+ break
426+ }
427+ }
428+ }
429+
430+ // Remove proxy-script and rabbitmq-tls-ca volumes
321431 newVolumes := []corev1.Volume {}
322432 for _ , vol := range podSpec .Volumes {
323- if vol .Name != "proxy-script" {
433+ if vol .Name != "proxy-script" && vol . Name != "rabbitmq-tls-ca" {
324434 newVolumes = append (newVolumes , vol )
325435 }
326436 }
0 commit comments