Skip to content

Commit ee7ff70

Browse files
committed
test fix ports
1 parent e7eea9a commit ee7ff70

2 files changed

Lines changed: 106 additions & 2 deletions

File tree

internal/controller/rabbitmq/proxy.go

Lines changed: 95 additions & 2 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,55 @@ func (r *Reconciler) addProxySidecar(
137168
})
138169
}
139170

171+
// Add rabbitmq-tls volume for TLS certificates (used by both RabbitMQ inter-node and proxy)
172+
// When proxy is enabled, we clear cluster.Spec.TLS to prevent RabbitMQ from configuring
173+
// SSL listeners, but we still need the TLS volumes mounted for:
174+
// 1. RabbitMQ inter-node encryption
175+
// 2. Proxy TLS termination
176+
if instance.Spec.TLS.SecretName != "" {
177+
// Check if rabbitmq-tls volume already exists
178+
tlsVolumeExists := false
179+
for _, vol := range podSpec.Volumes {
180+
if vol.Name == "rabbitmq-tls" {
181+
tlsVolumeExists = true
182+
break
183+
}
184+
}
185+
186+
if !tlsVolumeExists {
187+
podSpec.Volumes = append(podSpec.Volumes, corev1.Volume{
188+
Name: "rabbitmq-tls",
189+
VolumeSource: corev1.VolumeSource{
190+
Secret: &corev1.SecretVolumeSource{
191+
SecretName: instance.Spec.TLS.SecretName,
192+
DefaultMode: ptr.To[int32](0400), // Read-only
193+
},
194+
},
195+
})
196+
}
197+
198+
// Ensure RabbitMQ container has the TLS volume mounted (for inter-node TLS)
199+
for i, container := range podSpec.Containers {
200+
if container.Name == "rabbitmq" {
201+
hasTLSMount := false
202+
for _, mount := range container.VolumeMounts {
203+
if mount.Name == "rabbitmq-tls" {
204+
hasTLSMount = true
205+
break
206+
}
207+
}
208+
if !hasTLSMount {
209+
podSpec.Containers[i].VolumeMounts = append(podSpec.Containers[i].VolumeMounts, corev1.VolumeMount{
210+
Name: "rabbitmq-tls",
211+
MountPath: "/etc/rabbitmq-tls",
212+
ReadOnly: true,
213+
})
214+
}
215+
break
216+
}
217+
}
218+
}
219+
140220
// Add rabbitmq-tls-ca volume if CA is in a separate secret
141221
if instance.Spec.TLS.CaSecretName != "" && instance.Spec.TLS.CaSecretName != instance.Spec.TLS.SecretName {
142222
caVolumeExists := false
@@ -317,10 +397,23 @@ func (r *Reconciler) removeProxySidecar(cluster *rabbitmqv2.RabbitmqCluster) {
317397
}
318398
podSpec.Containers = newContainers
319399

320-
// Remove proxy-script volume
400+
// Restore RabbitMQ container's readiness probe to default
401+
// When proxy is removed, RabbitMQ listens on standard ports again
402+
// Setting probe to nil allows the cluster operator to restore its default
403+
if removed {
404+
for i, container := range podSpec.Containers {
405+
if container.Name == "rabbitmq" {
406+
podSpec.Containers[i].ReadinessProbe = nil
407+
Log.Info("Restored RabbitMQ container readiness probe to default")
408+
break
409+
}
410+
}
411+
}
412+
413+
// Remove proxy-script and rabbitmq-tls-ca volumes
321414
newVolumes := []corev1.Volume{}
322415
for _, vol := range podSpec.Volumes {
323-
if vol.Name != "proxy-script" {
416+
if vol.Name != "proxy-script" && vol.Name != "rabbitmq-tls-ca" {
324417
newVolumes = append(newVolumes, vol)
325418
}
326419
}

internal/controller/rabbitmq/rabbitmq_controller.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,17 @@ 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, clear TLS from cluster spec NOW
539+
// before any configuration is generated. The proxy will handle TLS termination.
540+
// This must happen immediately after MarshalInto to prevent the cluster operator
541+
// from generating conflicting SSL listener configuration.
542+
if r.shouldEnableProxy(instance) {
543+
rabbitmqCluster.Spec.TLS.SecretName = ""
544+
rabbitmqCluster.Spec.TLS.CaSecretName = ""
545+
rabbitmqCluster.Spec.TLS.DisableNonTLSListeners = false
546+
Log.Info("Proxy will be enabled - cleared TLS from RabbitMQ cluster spec (proxy will handle TLS)")
547+
}
548+
538549
instance.Status.Conditions.MarkTrue(condition.ServiceConfigReadyCondition, condition.ServiceConfigReadyMessage)
539550

540551
//

0 commit comments

Comments
 (0)