Skip to content

Commit dbc55cf

Browse files
committed
Rabbitmq vhost and user support
Add new notificationsBus interface to hold cluster, user and vhost names for optional usage. The controller adds these values to the TransportURL create request when present. Additionally, we migrate RabbitMQ cluster name to RabbitMq config struct using DefaultRabbitMqConfig from infra-operator to automatically populate the new Cluster field from legacy RabbitMqClusterName. Example usage: spec: notificationsBus: cluster: rabbitmq user: custom-user vhost: custom-vhost Jira: https://issues.redhat.com/browse/OSPRH-23739
1 parent eb14ec3 commit dbc55cf

File tree

12 files changed

+208
-15
lines changed

12 files changed

+208
-15
lines changed

api/bases/glance.openstack.org_glances.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,23 @@ spec:
16291629
Needed to request a transportURL that is created and used for notification
16301630
purposes
16311631
type: string
1632+
notificationsBus:
1633+
description: NotificationsBus configuration (username, vhost, and
1634+
cluster) for notifications
1635+
properties:
1636+
cluster:
1637+
description: Name of the cluster
1638+
minLength: 1
1639+
type: string
1640+
user:
1641+
description: User - RabbitMQ username
1642+
type: string
1643+
vhost:
1644+
description: Vhost - RabbitMQ vhost name
1645+
type: string
1646+
required:
1647+
- cluster
1648+
type: object
16321649
passwordSelectors:
16331650
default:
16341651
service: GlancePassword

api/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.24.4
44

55
require (
66
github.com/google/go-cmp v0.7.0
7-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251206161943-786269345f99
7+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251217131115-0f117a938d4e
88
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251122131503-b76943960b6c
99
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20251122131503-b76943960b6c
1010
k8s.io/api v0.31.14
@@ -17,7 +17,6 @@ require (
1717
github.com/cespare/xxhash/v2 v2.3.0 // indirect
1818
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
1919
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
20-
github.com/evanphx/json-patch v5.9.11+incompatible // indirect
2120
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
2221
github.com/fsnotify/fsnotify v1.9.0 // indirect
2322
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
@@ -44,6 +43,7 @@ require (
4443
github.com/prometheus/client_model v0.6.2 // indirect
4544
github.com/prometheus/common v0.65.0 // indirect
4645
github.com/prometheus/procfs v0.16.1 // indirect
46+
github.com/rabbitmq/cluster-operator/v2 v2.16.0 // indirect
4747
github.com/spf13/pflag v1.0.7 // indirect
4848
github.com/stretchr/testify v1.11.1 // indirect
4949
github.com/x448/float16 v0.8.4 // indirect

api/go.sum

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
12
github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1Xbatp0=
23
github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
34
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
@@ -80,12 +81,14 @@ github.com/onsi/gomega v1.38.2 h1:eZCjf2xjZAqe+LeWvKb5weQ+NcPwX84kqJ0cZNxok2A=
8081
github.com/onsi/gomega v1.38.2/go.mod h1:W2MJcYxRGV63b418Ai34Ud0hEdTVXq9NW9+Sx6uXf3k=
8182
github.com/openshift/api v0.0.0-20250711200046-c86d80652a9e h1:E1OdwSpqWuDPCedyUt0GEdoAE+r5TXy7YS21yNEo+2U=
8283
github.com/openshift/api v0.0.0-20250711200046-c86d80652a9e/go.mod h1:Shkl4HanLwDiiBzakv+con/aMGnVE2MAGvoKp5oyYUo=
83-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251206161943-786269345f99 h1:J9SzxfFmQQEMpfoCtpKUd87LtQXLWGZORL+6nBdtP+w=
84-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251206161943-786269345f99/go.mod h1:UgaMi5mHTvaGYLdPKwewSnYiSm75P+vowRqbqknHlbw=
84+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251217131115-0f117a938d4e h1:PIjcXzMMwfvBRFgFpaq/W9tqy0t2cYvcWX+kq6uNtTM=
85+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251217131115-0f117a938d4e/go.mod h1:ex8ou6/3ms6ovR+CMXD6XhTlNakm1GhB6UZgagVRNW8=
8586
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251122131503-b76943960b6c h1:wM8qXCB5mQwSosCvtaydzuXitWVVKBHTzH0A2znQ+Jg=
8687
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251122131503-b76943960b6c/go.mod h1:+Me0raWPPdz8gRi9D4z1khmvUgS9vIKAVC8ckg1yJZU=
8788
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20251122131503-b76943960b6c h1:dVIaDL5BeIdJjERGaN/XlcvZVplfkzh0uUfiVUHj/6Q=
8889
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20251122131503-b76943960b6c/go.mod h1:fy1lvz3uuzzh01DKKdgroXvmJgMpJBsvl2r9eTtAll0=
90+
github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20250929174222-a0d328fa4dec h1:saovr368HPAKHN0aRPh8h8n9s9dn3d8Frmfua0UYRlc=
91+
github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20250929174222-a0d328fa4dec/go.mod h1:Nh2NEePLjovUQof2krTAg4JaAoLacqtPTZQXK6izNfg=
8992
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
9093
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
9194
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=

api/v1beta1/glance_types.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
rabbitmqv1 "github.com/openstack-k8s-operators/infra-operator/apis/rabbitmq/v1beta1"
21+
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
2022
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
2123
"github.com/openstack-k8s-operators/lib-common/modules/storage"
22-
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
2324
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2425
)
2526

@@ -139,6 +140,10 @@ type GlanceSpecCore struct {
139140
// Needed to request a transportURL that is created and used for notification
140141
// purposes
141142
NotificationBusInstance *string `json:"notificationBusInstance,omitempty"`
143+
144+
// +kubebuilder:validation:Optional
145+
// NotificationsBus configuration (username, vhost, and cluster) for notifications
146+
NotificationsBus *rabbitmqv1.RabbitMqConfig `json:"notificationsBus,omitempty"`
142147
}
143148

144149
// GlanceSpec defines the desired state of Glance

api/v1beta1/glance_webhook.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ import (
2121
"strings"
2222

2323
"github.com/google/go-cmp/cmp"
24+
rabbitmqv1 "github.com/openstack-k8s-operators/infra-operator/apis/rabbitmq/v1beta1"
25+
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
2426
"github.com/openstack-k8s-operators/lib-common/modules/common/service"
27+
common_webhook "github.com/openstack-k8s-operators/lib-common/modules/common/webhook"
2528
apierrors "k8s.io/apimachinery/pkg/api/errors"
2629
"k8s.io/apimachinery/pkg/runtime"
2730
"k8s.io/apimachinery/pkg/runtime/schema"
2831
"k8s.io/apimachinery/pkg/util/validation/field"
2932
logf "sigs.k8s.io/controller-runtime/pkg/log"
3033
"sigs.k8s.io/controller-runtime/pkg/webhook"
3134
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
32-
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
33-
34-
common_webhook "github.com/openstack-k8s-operators/lib-common/modules/common/webhook"
3535
)
3636

3737
// GlanceDefaults -
@@ -111,6 +111,14 @@ func (r *GlanceSpecCore) Default() {
111111
if r.DBPurge.Schedule == "" {
112112
r.DBPurge.Schedule = glanceDefaults.DBPurgeSchedule
113113
}
114+
115+
// Default NotificationsBus if NotificationBusInstance is specified
116+
if r.NotificationBusInstance != nil && *r.NotificationBusInstance != "" {
117+
if r.NotificationsBus == nil {
118+
r.NotificationsBus = &rabbitmqv1.RabbitMqConfig{}
119+
}
120+
rabbitmqv1.DefaultRabbitMqConfig(r.NotificationsBus, *r.NotificationBusInstance)
121+
}
114122
// When no glanceAPI(s) are specified in the top-level CR
115123
// we build one by default, but we set replicas=0 and we
116124
// build a "CustomServiceConfig" template that should be
@@ -352,6 +360,14 @@ func (r *GlanceSpec) ValidateUpdate(old GlanceSpec, basePath *field.Path, namesp
352360
func (r *GlanceSpecCore) ValidateUpdate(old GlanceSpecCore, basePath *field.Path, namespace string) field.ErrorList {
353361
var allErrs field.ErrorList
354362

363+
// Reject changes to deprecated NotificationBusInstance field
364+
if r.NotificationBusInstance != nil && old.NotificationBusInstance != nil &&
365+
*r.NotificationBusInstance != *old.NotificationBusInstance {
366+
allErrs = append(allErrs, field.Forbidden(
367+
basePath.Child("notificationBusInstance"),
368+
"notificationBusInstance is deprecated and cannot be changed. Please use notificationsBus.cluster instead"))
369+
}
370+
355371
// fail if a wrong topology is referenced
356372
allErrs = append(allErrs, topologyv1.ValidateTopologyRef(
357373
r.TopologyRef, *basePath.Child("topologyRef"), namespace)...)

api/v1beta1/zz_generated.deepcopy.go

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

config/crd/bases/glance.openstack.org_glances.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,23 @@ spec:
16291629
Needed to request a transportURL that is created and used for notification
16301630
purposes
16311631
type: string
1632+
notificationsBus:
1633+
description: NotificationsBus configuration (username, vhost, and
1634+
cluster) for notifications
1635+
properties:
1636+
cluster:
1637+
description: Name of the cluster
1638+
minLength: 1
1639+
type: string
1640+
user:
1641+
description: User - RabbitMQ username
1642+
type: string
1643+
vhost:
1644+
description: Vhost - RabbitMQ vhost name
1645+
type: string
1646+
required:
1647+
- cluster
1648+
type: object
16321649
passwordSelectors:
16331650
default:
16341651
service: GlancePassword

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/openstack-k8s-operators/cinder-operator/api v0.6.1-0.20251206170410-b8260d6400b7
1313
github.com/openstack-k8s-operators/glance-operator/api v0.0.0-00010101000000-000000000000
1414
github.com/openstack-k8s-operators/horizon-operator/api v0.6.1-0.20251206162807-8d3838121dac
15-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251206161943-786269345f99
15+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251217131115-0f117a938d4e
1616
github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20251206133124-593df0a7a9e1
1717
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251122131503-b76943960b6c
1818
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20251122131503-b76943960b6c

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ github.com/openstack-k8s-operators/cinder-operator/api v0.6.1-0.20251206170410-b
122122
github.com/openstack-k8s-operators/cinder-operator/api v0.6.1-0.20251206170410-b8260d6400b7/go.mod h1:h9B9rUrjGE9fuASHxkhxEdjYRhYAC8BBfSewO1qhTls=
123123
github.com/openstack-k8s-operators/horizon-operator/api v0.6.1-0.20251206162807-8d3838121dac h1:i6AB7JjsZqsj5iDSsZ9pfRSTYDxCtL3zu9utceM4NUw=
124124
github.com/openstack-k8s-operators/horizon-operator/api v0.6.1-0.20251206162807-8d3838121dac/go.mod h1:xMIUtDReoi4O+6akfB0u8mNKT9u/uSjFqvWjfYcIqQo=
125-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251206161943-786269345f99 h1:J9SzxfFmQQEMpfoCtpKUd87LtQXLWGZORL+6nBdtP+w=
126-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251206161943-786269345f99/go.mod h1:UgaMi5mHTvaGYLdPKwewSnYiSm75P+vowRqbqknHlbw=
125+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251217131115-0f117a938d4e h1:PIjcXzMMwfvBRFgFpaq/W9tqy0t2cYvcWX+kq6uNtTM=
126+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251217131115-0f117a938d4e/go.mod h1:ex8ou6/3ms6ovR+CMXD6XhTlNakm1GhB6UZgagVRNW8=
127127
github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20251206133124-593df0a7a9e1 h1:qcgbrF9c0axkaDcFGfIA2wGz8bkaxPuXHj3mdKAyz6M=
128128
github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20251206133124-593df0a7a9e1/go.mod h1:0XsZ6Fc4hTV6a/BBP8+jiH8LR+IP5z9aStdPTDHALNk=
129129
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251122131503-b76943960b6c h1:wM8qXCB5mQwSosCvtaydzuXitWVVKBHTzH0A2znQ+Jg=

internal/controller/glance_controller.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,11 @@ func (r *GlanceReconciler) reconcileNormal(ctx context.Context, instance *glance
583583
// create RabbitMQ transportURL CR and get the actual URL from the associated secret that is created
584584
//
585585
if instance.Spec.NotificationBusInstance != nil && *instance.Spec.NotificationBusInstance != "" {
586-
notificationTransportURL, op, err := r.transportURLCreateOrUpdate(ctx, instance, serviceLabels)
586+
notificationsRabbitMqConfig := rabbitmqv1.RabbitMqConfig{}
587+
if instance.Spec.NotificationsBus != nil {
588+
notificationsRabbitMqConfig = *instance.Spec.NotificationsBus
589+
}
590+
notificationTransportURL, op, err := r.transportURLCreateOrUpdate(ctx, instance, serviceLabels, notificationsRabbitMqConfig)
587591
if err != nil {
588592
instance.Status.Conditions.Set(condition.FalseCondition(
589593
condition.NotificationBusInstanceReadyCondition,
@@ -1373,6 +1377,7 @@ func (r *GlanceReconciler) transportURLCreateOrUpdate(
13731377
ctx context.Context,
13741378
instance *glancev1.Glance,
13751379
serviceLabels map[string]string,
1380+
rabbitMqConfig rabbitmqv1.RabbitMqConfig,
13761381
) (*rabbitmqv1.TransportURL, controllerutil.OperationResult, error) {
13771382
transportURL := &rabbitmqv1.TransportURL{
13781383
ObjectMeta: metav1.ObjectMeta{
@@ -1384,9 +1389,12 @@ func (r *GlanceReconciler) transportURLCreateOrUpdate(
13841389

13851390
op, err := controllerutil.CreateOrUpdate(ctx, r.Client, transportURL, func() error {
13861391
transportURL.Spec.RabbitmqClusterName = *instance.Spec.NotificationBusInstance
1387-
1388-
err := controllerutil.SetControllerReference(instance, transportURL, r.Scheme)
1389-
return err
1392+
if rabbitMqConfig.User != "" {
1393+
transportURL.Spec.Username = rabbitMqConfig.User
1394+
}
1395+
// Always set Vhost - empty string means use default "/" vhost
1396+
transportURL.Spec.Vhost = rabbitMqConfig.Vhost
1397+
return controllerutil.SetControllerReference(instance, transportURL, r.Scheme)
13901398
})
13911399

13921400
return transportURL, op, err

0 commit comments

Comments
 (0)