Skip to content

Commit 3885c4a

Browse files
committed
Support nova-operator rabbitmq_user_name field propagation
Update GetNovaCellRabbitMqUserFromSecret to use the new rabbitmq_user_name field directly when available (nova-operator PR #1066), with fallback to parsing transport_url for backwards compatibility. Add GetNovaCellNotificationRabbitMqUserFromSecret to extract the notification RabbitMQ user name from the notification_rabbitmq_user_name field. This simplifies RabbitMQ user tracking and eliminates the need for complex transport URL parsing when using nova-operator with PR #1066 or later. Prepares openstack-operator to work with: - nova-operator PR #1066: Propagate rabbitmq users to nova-cellX secret
1 parent 7b15398 commit 3885c4a

File tree

2 files changed

+53
-14
lines changed

2 files changed

+53
-14
lines changed

config/operator/deployment/kustomization.yaml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,3 @@ patches:
2727
kind: Deployment
2828
name: openstack-operator-controller-init
2929
namespace: system
30-
- patch: '[{"op": "replace", "path": "/spec/template/spec/containers/0/env/0", "value":
31-
{"name": "OPENSTACK_RELEASE_VERSION", "value": "0.1.17-1768984468"}}]'
32-
target:
33-
kind: Deployment
34-
name: openstack-operator-controller-operator
35-
namespace: system
36-
- patch: '[{"op": "replace", "path": "/spec/template/spec/containers/0/env/0", "value":
37-
{"name": "OPENSTACK_RELEASE_VERSION", "value": "0.5.0-1770051580"}}]'
38-
target:
39-
kind: Deployment
40-
name: openstack-operator-controller-init
41-
namespace: system

internal/dataplane/rabbitmq.go

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ import (
3232
)
3333

3434
// GetNovaCellRabbitMqUserFromSecret extracts the RabbitMQ username from a nova-cellX-compute-config secret
35-
// Returns the username extracted from transport_url in the secret
35+
// Returns the username extracted from rabbitmq_user_name field (preferred) or transport_url (fallback)
36+
// As of nova-operator PR #1066, the RabbitMQUser CR name is propagated directly in the
37+
// rabbitmq_user_name and notification_rabbitmq_user_name fields for easier tracking.
3638
func GetNovaCellRabbitMqUserFromSecret(
3739
ctx context.Context,
3840
h *helper.Helper,
@@ -56,7 +58,13 @@ func GetNovaCellRabbitMqUserFromSecret(
5658
continue
5759
}
5860

59-
// Extract transport_url from secret data
61+
// Preferred: Use the rabbitmq_user_name field directly if available
62+
// This field is populated by nova-operator PR #1066 with the RabbitMQUser CR name
63+
if rabbitmqUserName, ok := secret.Data["rabbitmq_user_name"]; ok && len(rabbitmqUserName) > 0 {
64+
return string(rabbitmqUserName), nil
65+
}
66+
67+
// Fallback: Extract transport_url from secret data for backwards compatibility
6068
transportURLBytes, ok := secret.Data["transport_url"]
6169
if !ok {
6270
// Try to extract from config files as fallback (in case it's embedded)
@@ -90,6 +98,49 @@ func GetNovaCellRabbitMqUserFromSecret(
9098
return "", fmt.Errorf("no RabbitMQ username found for cell %s", cellName)
9199
}
92100

101+
// GetNovaCellNotificationRabbitMqUserFromSecret extracts the notification RabbitMQ username
102+
// from a nova-cellX-compute-config secret. This is used for tracking the RabbitMQUser CR
103+
// used for notifications (separate from the messaging/RPC bus).
104+
// Returns the username extracted from notification_rabbitmq_user_name field (preferred)
105+
// or attempts to extract from notification transport_url (fallback).
106+
func GetNovaCellNotificationRabbitMqUserFromSecret(
107+
ctx context.Context,
108+
h *helper.Helper,
109+
namespace string,
110+
cellName string,
111+
) (string, error) {
112+
// List all secrets in the namespace
113+
secretList := &corev1.SecretList{}
114+
err := h.GetClient().List(ctx, secretList, client.InNamespace(namespace))
115+
if err != nil {
116+
return "", fmt.Errorf("failed to list secrets: %w", err)
117+
}
118+
119+
// Pattern to match nova-cellX-compute-config secrets
120+
secretPattern := regexp.MustCompile(`^nova-(` + cellName + `)-compute-config(-\d+)?$`)
121+
122+
for _, secret := range secretList.Items {
123+
matches := secretPattern.FindStringSubmatch(secret.Name)
124+
if matches == nil {
125+
continue
126+
}
127+
128+
// Preferred: Use the notification_rabbitmq_user_name field directly if available
129+
// This field is populated by nova-operator PR #1066 with the RabbitMQUser CR name
130+
if notificationRabbitmqUserName, ok := secret.Data["notification_rabbitmq_user_name"]; ok && len(notificationRabbitmqUserName) > 0 {
131+
return string(notificationRabbitmqUserName), nil
132+
}
133+
134+
// If notification_rabbitmq_user_name is not available, this likely means:
135+
// 1. Nova-operator hasn't been updated to PR #1066 yet, or
136+
// 2. Notifications are not configured for this cell
137+
// Return empty string to indicate no notification user (not an error)
138+
return "", nil
139+
}
140+
141+
return "", fmt.Errorf("no compute-config secret found for cell %s", cellName)
142+
}
143+
93144
// parseUsernameFromTransportURL extracts the username from a RabbitMQ transport URL
94145
// Format: rabbit://username:password@host:port/vhost
95146
// Also supports: rabbit+tls://username:password@host1:port1,host2:port2/vhost

0 commit comments

Comments
 (0)