Skip to content

Commit 49920c1

Browse files
committed
Rabbitmq vhost and user support
Add optional rabbitmq.user and rabbitmq.vhost fields to the spec to allow configuring custom RabbitMQ credentials and virtual hosts. The controller sets these values on the TransportURL when specified. Includes functional tests verifying custom and default configurations. Example usage: spec: rabbitmq: user: main-user vhost: main-vhost notificationsRabbitmq: user: notifications-user vhost: notifications-vhost Jira: https://issues.redhat.com/browse/OSPRH-22694
1 parent f9d7fba commit 49920c1

File tree

10 files changed

+468
-11
lines changed

10 files changed

+468
-11
lines changed

api/bases/cinder.openstack.org_cinders.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,6 +2037,18 @@ spec:
20372037
RabbitMQ instance name used to request a transportURL that is used for
20382038
notification purposes
20392039
type: string
2040+
notificationsRabbitmq:
2041+
description: |-
2042+
NotificationsRabbitMq configuration (username and vhost) for the notifications bus.
2043+
If not specified, defaults to the main RabbitMq configuration.
2044+
properties:
2045+
user:
2046+
description: User - RabbitMQ username
2047+
type: string
2048+
vhost:
2049+
description: Vhost - RabbitMQ vhost name
2050+
type: string
2051+
type: object
20402052
passwordSelectors:
20412053
default:
20422054
service: CinderPassword
@@ -2060,6 +2072,16 @@ spec:
20602072
RabbitMQ instance name
20612073
Needed to request a transportURL that is created and used in Cinder
20622074
type: string
2075+
rabbitmq:
2076+
description: RabbitMQ configuration (username and vhost)
2077+
properties:
2078+
user:
2079+
description: User - RabbitMQ username
2080+
type: string
2081+
vhost:
2082+
description: Vhost - RabbitMQ vhost name
2083+
type: string
2084+
type: object
20632085
secret:
20642086
description: Secret containing OpenStack password information
20652087
type: string

api/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/openstack-k8s-operators/cinder-operator/api
33
go 1.24.4
44

55
require (
6-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251206161943-786269345f99
6+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251215110339-4871011e89fb
77
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251122131503-b76943960b6c
88
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20251122131503-b76943960b6c
99
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67

api/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ github.com/onsi/ginkgo/v2 v2.27.3 h1:ICsZJ8JoYafeXFFlFAG75a7CxMsJHwgKwtO+82SE9L8
7878
github.com/onsi/ginkgo/v2 v2.27.3/go.mod h1:ArE1D/XhNXBXCBkKOLkbsb2c81dQHCRcF5zwn/ykDRo=
7979
github.com/onsi/gomega v1.38.3 h1:eTX+W6dobAYfFeGC2PV6RwXRu/MyT+cQguijutvkpSM=
8080
github.com/onsi/gomega v1.38.3/go.mod h1:ZCU1pkQcXDO5Sl9/VVEGlDyp+zm0m1cmeG5TOzLgdh4=
81-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251206161943-786269345f99 h1:J9SzxfFmQQEMpfoCtpKUd87LtQXLWGZORL+6nBdtP+w=
82-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251206161943-786269345f99/go.mod h1:UgaMi5mHTvaGYLdPKwewSnYiSm75P+vowRqbqknHlbw=
81+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251215110339-4871011e89fb h1:R81bAZaAxF0SdUecxsP5pxqVqP8MTFnhCfLZWixCOIw=
82+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251215110339-4871011e89fb/go.mod h1:ex8ou6/3ms6ovR+CMXD6XhTlNakm1GhB6UZgagVRNW8=
8383
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251122131503-b76943960b6c h1:wM8qXCB5mQwSosCvtaydzuXitWVVKBHTzH0A2znQ+Jg=
8484
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251122131503-b76943960b6c/go.mod h1:+Me0raWPPdz8gRi9D4z1khmvUgS9vIKAVC8ckg1yJZU=
8585
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20251122131503-b76943960b6c h1:dVIaDL5BeIdJjERGaN/XlcvZVplfkzh0uUfiVUHj/6Q=

api/v1beta1/cinder_types.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ type CinderSpecBase struct {
7070
// Needed to request a transportURL that is created and used in Cinder
7171
RabbitMqClusterName string `json:"rabbitMqClusterName"`
7272

73+
// +kubebuilder:validation:Optional
74+
// RabbitMQ configuration (username and vhost)
75+
RabbitMq RabbitMq `json:"rabbitmq,omitempty"`
76+
77+
// +kubebuilder:validation:Optional
78+
// NotificationsRabbitMq configuration (username and vhost) for the notifications bus.
79+
// If not specified, defaults to the main RabbitMq configuration.
80+
NotificationsRabbitMq RabbitMq `json:"notificationsRabbitmq,omitempty"`
81+
7382
// +kubebuilder:validation:Required
7483
// +kubebuilder:default=memcached
7584
// Memcached instance name.
@@ -247,6 +256,16 @@ type DBPurge struct {
247256
Schedule string `json:"schedule"`
248257
}
249258

259+
// RabbitMq struct is used to specify custom RabbitMQ username and vhost
260+
type RabbitMq struct {
261+
// +kubebuilder:validation:Optional
262+
// User - RabbitMQ username
263+
User string `json:"user,omitempty"`
264+
// +kubebuilder:validation:Optional
265+
// Vhost - RabbitMQ vhost name
266+
Vhost string `json:"vhost,omitempty"`
267+
}
268+
250269
//+kubebuilder:object:root=true
251270

252271
// CinderList contains a list of Cinder

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/cinder.openstack.org_cinders.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,6 +2037,18 @@ spec:
20372037
RabbitMQ instance name used to request a transportURL that is used for
20382038
notification purposes
20392039
type: string
2040+
notificationsRabbitmq:
2041+
description: |-
2042+
NotificationsRabbitMq configuration (username and vhost) for the notifications bus.
2043+
If not specified, defaults to the main RabbitMq configuration.
2044+
properties:
2045+
user:
2046+
description: User - RabbitMQ username
2047+
type: string
2048+
vhost:
2049+
description: Vhost - RabbitMQ vhost name
2050+
type: string
2051+
type: object
20402052
passwordSelectors:
20412053
default:
20422054
service: CinderPassword
@@ -2060,6 +2072,16 @@ spec:
20602072
RabbitMQ instance name
20612073
Needed to request a transportURL that is created and used in Cinder
20622074
type: string
2075+
rabbitmq:
2076+
description: RabbitMQ configuration (username and vhost)
2077+
properties:
2078+
user:
2079+
description: User - RabbitMQ username
2080+
type: string
2081+
vhost:
2082+
description: Vhost - RabbitMQ vhost name
2083+
type: string
2084+
type: object
20632085
secret:
20642086
description: Secret containing OpenStack password information
20652087
type: string

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.7.7
99
github.com/onsi/ginkgo/v2 v2.27.3
1010
github.com/onsi/gomega v1.38.3
11-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251206161943-786269345f99
11+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251215110339-4871011e89fb
1212
github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20251206133124-593df0a7a9e1
1313
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251122131503-b76943960b6c
1414
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20251122131503-b76943960b6c

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ github.com/onsi/gomega v1.38.3 h1:eTX+W6dobAYfFeGC2PV6RwXRu/MyT+cQguijutvkpSM=
118118
github.com/onsi/gomega v1.38.3/go.mod h1:ZCU1pkQcXDO5Sl9/VVEGlDyp+zm0m1cmeG5TOzLgdh4=
119119
github.com/openshift/api v0.0.0-20250711200046-c86d80652a9e h1:E1OdwSpqWuDPCedyUt0GEdoAE+r5TXy7YS21yNEo+2U=
120120
github.com/openshift/api v0.0.0-20250711200046-c86d80652a9e/go.mod h1:Shkl4HanLwDiiBzakv+con/aMGnVE2MAGvoKp5oyYUo=
121-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251206161943-786269345f99 h1:J9SzxfFmQQEMpfoCtpKUd87LtQXLWGZORL+6nBdtP+w=
122-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251206161943-786269345f99/go.mod h1:UgaMi5mHTvaGYLdPKwewSnYiSm75P+vowRqbqknHlbw=
121+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251215110339-4871011e89fb h1:R81bAZaAxF0SdUecxsP5pxqVqP8MTFnhCfLZWixCOIw=
122+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251215110339-4871011e89fb/go.mod h1:ex8ou6/3ms6ovR+CMXD6XhTlNakm1GhB6UZgagVRNW8=
123123
github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20251206133124-593df0a7a9e1 h1:qcgbrF9c0axkaDcFGfIA2wGz8bkaxPuXHj3mdKAyz6M=
124124
github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20251206133124-593df0a7a9e1/go.mod h1:0XsZ6Fc4hTV6a/BBP8+jiH8LR+IP5z9aStdPTDHALNk=
125125
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251122131503-b76943960b6c h1:wM8qXCB5mQwSosCvtaydzuXitWVVKBHTzH0A2znQ+Jg=

internal/controller/cinder_controller.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ func (r *CinderReconciler) reconcileNormal(ctx context.Context, instance *cinder
525525
// create RabbitMQ transportURL CR and get the actual URL from the associated secret that is created
526526
//
527527

528-
transportURL, op, err := r.transportURLCreateOrUpdate(ctx, instance, serviceLabels, "")
528+
transportURL, op, err := r.transportURLCreateOrUpdate(ctx, instance, serviceLabels, "", instance.Spec.RabbitMq)
529529
if err != nil {
530530
instance.Status.Conditions.Set(condition.FalseCondition(
531531
condition.RabbitMqTransportURLReadyCondition,
@@ -573,7 +573,12 @@ func (r *CinderReconciler) reconcileNormal(ctx context.Context, instance *cinder
573573
if *instance.Spec.NotificationsBusInstance != instance.Spec.RabbitMqClusterName {
574574
notificationBusName = *instance.Spec.NotificationsBusInstance
575575
}
576-
notificationBusInstanceURL, op, err := r.transportURLCreateOrUpdate(ctx, instance, serviceLabels, notificationBusName)
576+
// Use NotificationsRabbitMq if specified, otherwise fall back to main RabbitMq config
577+
notificationsRabbitMqConfig := instance.Spec.RabbitMq
578+
if instance.Spec.NotificationsRabbitMq.User != "" || instance.Spec.NotificationsRabbitMq.Vhost != "" {
579+
notificationsRabbitMqConfig = instance.Spec.NotificationsRabbitMq
580+
}
581+
notificationBusInstanceURL, op, err := r.transportURLCreateOrUpdate(ctx, instance, serviceLabels, notificationBusName, notificationsRabbitMqConfig)
577582
if err != nil {
578583
instance.Status.Conditions.Set(condition.FalseCondition(
579584
condition.NotificationBusInstanceReadyCondition,
@@ -1192,6 +1197,7 @@ func (r *CinderReconciler) transportURLCreateOrUpdate(
11921197
instance *cinderv1beta1.Cinder,
11931198
serviceLabels map[string]string,
11941199
rabbitMqClusterName string,
1200+
rabbitMqConfig cinderv1beta1.RabbitMq,
11951201
) (*rabbitmqv1.TransportURL, controllerutil.OperationResult, error) {
11961202

11971203
// Default values used for regular messagingBus transportURL and explicitly
@@ -1215,9 +1221,13 @@ func (r *CinderReconciler) transportURLCreateOrUpdate(
12151221

12161222
op, err := controllerutil.CreateOrUpdate(ctx, r.Client, transportURL, func() error {
12171223
transportURL.Spec.RabbitmqClusterName = transportURLName
1218-
1219-
err := controllerutil.SetControllerReference(instance, transportURL, r.Scheme)
1220-
return err
1224+
if rabbitMqConfig.User != "" {
1225+
transportURL.Spec.Username = rabbitMqConfig.User
1226+
}
1227+
if rabbitMqConfig.Vhost != "" {
1228+
transportURL.Spec.Vhost = rabbitMqConfig.Vhost
1229+
}
1230+
return controllerutil.SetControllerReference(instance, transportURL, r.Scheme)
12211231
})
12221232

12231233
return transportURL, op, err

0 commit comments

Comments
 (0)