Skip to content

Commit 310f1fe

Browse files
committed
test fix ports
1 parent e7eea9a commit 310f1fe

2 files changed

Lines changed: 67 additions & 7 deletions

File tree

internal/controller/rabbitmq/proxy.go

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,37 @@ 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+
// Note: We don't override container ports here because:
133+
// 1. Ports are just metadata declarations, not actual network configuration
134+
// 2. What RabbitMQ actually listens on is controlled by our listener config
135+
// 3. Overriding ports can cause conflicts with cluster operator defaults
136+
137+
Log.Info("Updated RabbitMQ container readiness probe for proxy mode",
138+
"readinessProbePort", rabbitmqBackendPort)
139+
break
140+
}
141+
}
142+
112143
// Add volume for proxy script
113144
if podSpec.Volumes == nil {
114145
podSpec.Volumes = []corev1.Volume{}
@@ -137,6 +168,10 @@ func (r *Reconciler) addProxySidecar(
137168
})
138169
}
139170

171+
// Note: rabbitmq-tls volume is automatically added by the cluster operator when
172+
// cluster.Spec.TLS.SecretName is set (which we keep for inter-node TLS).
173+
// The proxy container will mount this volume via buildProxySidecarContainer().
174+
140175
// Add rabbitmq-tls-ca volume if CA is in a separate secret
141176
if instance.Spec.TLS.CaSecretName != "" && instance.Spec.TLS.CaSecretName != instance.Spec.TLS.SecretName {
142177
caVolumeExists := false
@@ -317,10 +352,23 @@ func (r *Reconciler) removeProxySidecar(cluster *rabbitmqv2.RabbitmqCluster) {
317352
}
318353
podSpec.Containers = newContainers
319354

320-
// Remove proxy-script volume
355+
// Restore RabbitMQ container's readiness probe to default
356+
// When proxy is removed, RabbitMQ listens on standard ports again
357+
// Setting probe to nil allows the cluster operator to restore its default
358+
if removed {
359+
for i, container := range podSpec.Containers {
360+
if container.Name == "rabbitmq" {
361+
podSpec.Containers[i].ReadinessProbe = nil
362+
Log.Info("Restored RabbitMQ container readiness probe to default")
363+
break
364+
}
365+
}
366+
}
367+
368+
// Remove proxy-script and rabbitmq-tls-ca volumes
321369
newVolumes := []corev1.Volume{}
322370
for _, vol := range podSpec.Volumes {
323-
if vol.Name != "proxy-script" {
371+
if vol.Name != "proxy-script" && vol.Name != "rabbitmq-tls-ca" {
324372
newVolumes = append(newVolumes, vol)
325373
}
326374
}
@@ -404,15 +452,18 @@ func (r *Reconciler) configureRabbitMQBackendPort(
404452
tlsStatus = "with TLS"
405453
}
406454

407-
// Configure RabbitMQ to listen on localhost:5673 without TLS
455+
// Configure RabbitMQ to listen on localhost:5673 without TLS for AMQP
408456
// The proxy will handle TLS termination (if enabled) on 0.0.0.0:5671 or 0.0.0.0:5672
457+
// Override the default listeners set by the cluster operator
409458
additionalConfig := fmt.Sprintf(`
410459
# Proxy sidecar configuration
411-
# RabbitMQ listens on localhost:%d without TLS (proxy handles encryption)
460+
# RabbitMQ listens on localhost:%d without TLS for AMQP (proxy handles client encryption)
412461
# External clients connect to proxy on port %d %s
413-
# Disable all default listeners to prevent bypassing the proxy and port conflicts
414-
listeners.tcp = none
415-
listeners.ssl = none
462+
# Override default AMQP listeners set by cluster operator
463+
# Management and Prometheus SSL listeners remain active
464+
listeners.ssl.default = none
465+
listeners.tcp.default = none
466+
# Configure AMQP to listen on localhost only (proxy forwards to this)
416467
listeners.tcp.1 = 127.0.0.1:%d
417468
`, rabbitmqBackendPort, listenPort, tlsStatus, rabbitmqBackendPort)
418469

internal/controller/rabbitmq/rabbitmq_controller.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,15 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ct
535535
return ctrl.Result{}, fmt.Errorf("error creating RabbitmqCluster Spec: %w", err)
536536
}
537537

538+
// IMPORTANT: If proxy will be enabled, configure TLS for inter-node only
539+
// We keep TLS enabled for secure inter-node communication, but disable client-facing
540+
// SSL listeners. The proxy will handle client TLS termination instead.
541+
// Set DisableNonTLSListeners=false so the operator doesn't force SSL listeners.
542+
if r.shouldEnableProxy(instance) {
543+
rabbitmqCluster.Spec.TLS.DisableNonTLSListeners = false
544+
Log.Info("Proxy will be enabled - configured TLS for inter-node only (proxy will handle client TLS)")
545+
}
546+
538547
instance.Status.Conditions.MarkTrue(condition.ServiceConfigReadyCondition, condition.ServiceConfigReadyMessage)
539548

540549
//

0 commit comments

Comments
 (0)