Skip to content

Commit bbf147d

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: notificationsRabbitmq: user: custom-user vhost: custom-vhost Jira: https://issues.redhat.com/browse/OSPRH-23739
1 parent eb14ec3 commit bbf147d

10 files changed

Lines changed: 108 additions & 10 deletions

File tree

‎api/bases/glance.openstack.org_glances.yaml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,17 @@ spec:
16291629
Needed to request a transportURL that is created and used for notification
16301630
purposes
16311631
type: string
1632+
notificationsRabbitmq:
1633+
description: NotificationsRabbitMq - Configuration for RabbitMQ for
1634+
notifications bus (username and vhost)
1635+
properties:
1636+
user:
1637+
description: User - RabbitMQ username
1638+
type: string
1639+
vhost:
1640+
description: Vhost - RabbitMQ vhost name
1641+
type: string
1642+
type: object
16321643
passwordSelectors:
16331644
default:
16341645
service: GlancePassword

‎api/go.mod‎

Lines changed: 1 addition & 1 deletion
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.20251215110339-4871011e89fb
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

‎api/go.sum‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ github.com/onsi/gomega v1.38.2 h1:eZCjf2xjZAqe+LeWvKb5weQ+NcPwX84kqJ0cZNxok2A=
8080
github.com/onsi/gomega v1.38.2/go.mod h1:W2MJcYxRGV63b418Ai34Ud0hEdTVXq9NW9+Sx6uXf3k=
8181
github.com/openshift/api v0.0.0-20250711200046-c86d80652a9e h1:E1OdwSpqWuDPCedyUt0GEdoAE+r5TXy7YS21yNEo+2U=
8282
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=
83+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251215110339-4871011e89fb h1:R81bAZaAxF0SdUecxsP5pxqVqP8MTFnhCfLZWixCOIw=
84+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251215110339-4871011e89fb/go.mod h1:ex8ou6/3ms6ovR+CMXD6XhTlNakm1GhB6UZgagVRNW8=
8585
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251122131503-b76943960b6c h1:wM8qXCB5mQwSosCvtaydzuXitWVVKBHTzH0A2znQ+Jg=
8686
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251122131503-b76943960b6c/go.mod h1:+Me0raWPPdz8gRi9D4z1khmvUgS9vIKAVC8ckg1yJZU=
8787
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20251122131503-b76943960b6c h1:dVIaDL5BeIdJjERGaN/XlcvZVplfkzh0uUfiVUHj/6Q=

‎api/v1beta1/glance_types.go‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ const (
3838
GlanceWSGILabel = "glance.openstack.org/wsgi"
3939
)
4040

41+
// RabbitMq defines RabbitMQ configuration (username and vhost)
42+
type RabbitMq struct {
43+
// +kubebuilder:validation:Optional
44+
// User - RabbitMQ username
45+
User string `json:"user,omitempty"`
46+
47+
// +kubebuilder:validation:Optional
48+
// Vhost - RabbitMQ vhost name
49+
Vhost string `json:"vhost,omitempty"`
50+
}
51+
4152
// GlanceSpecCore defines the desired state of Glance
4253
type GlanceSpecCore struct {
4354
// +kubebuilder:validation:Optional
@@ -139,6 +150,10 @@ type GlanceSpecCore struct {
139150
// Needed to request a transportURL that is created and used for notification
140151
// purposes
141152
NotificationBusInstance *string `json:"notificationBusInstance,omitempty"`
153+
154+
// +kubebuilder:validation:Optional
155+
// NotificationsRabbitMq - Configuration for RabbitMQ for notifications bus (username and vhost)
156+
NotificationsRabbitMq RabbitMq `json:"notificationsRabbitmq,omitempty"`
142157
}
143158

144159
// GlanceSpec defines the desired state of Glance

‎api/v1beta1/zz_generated.deepcopy.go‎

Lines changed: 16 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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,17 @@ spec:
16291629
Needed to request a transportURL that is created and used for notification
16301630
purposes
16311631
type: string
1632+
notificationsRabbitmq:
1633+
description: NotificationsRabbitMq - Configuration for RabbitMQ for
1634+
notifications bus (username and vhost)
1635+
properties:
1636+
user:
1637+
description: User - RabbitMQ username
1638+
type: string
1639+
vhost:
1640+
description: Vhost - RabbitMQ vhost name
1641+
type: string
1642+
type: object
16321643
passwordSelectors:
16331644
default:
16341645
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.20251215110339-4871011e89fb
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.20251215110339-4871011e89fb h1:R81bAZaAxF0SdUecxsP5pxqVqP8MTFnhCfLZWixCOIw=
126+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251215110339-4871011e89fb/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: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ 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+
notificationTransportURL, op, err := r.transportURLCreateOrUpdate(ctx, instance, serviceLabels, instance.Spec.NotificationsRabbitMq)
587587
if err != nil {
588588
instance.Status.Conditions.Set(condition.FalseCondition(
589589
condition.NotificationBusInstanceReadyCondition,
@@ -1373,6 +1373,7 @@ func (r *GlanceReconciler) transportURLCreateOrUpdate(
13731373
ctx context.Context,
13741374
instance *glancev1.Glance,
13751375
serviceLabels map[string]string,
1376+
rabbitMqConfig glancev1.RabbitMq,
13761377
) (*rabbitmqv1.TransportURL, controllerutil.OperationResult, error) {
13771378
transportURL := &rabbitmqv1.TransportURL{
13781379
ObjectMeta: metav1.ObjectMeta{
@@ -1384,9 +1385,13 @@ func (r *GlanceReconciler) transportURLCreateOrUpdate(
13841385

13851386
op, err := controllerutil.CreateOrUpdate(ctx, r.Client, transportURL, func() error {
13861387
transportURL.Spec.RabbitmqClusterName = *instance.Spec.NotificationBusInstance
1387-
1388-
err := controllerutil.SetControllerReference(instance, transportURL, r.Scheme)
1389-
return err
1388+
if rabbitMqConfig.User != "" {
1389+
transportURL.Spec.Username = rabbitMqConfig.User
1390+
}
1391+
if rabbitMqConfig.Vhost != "" {
1392+
transportURL.Spec.Vhost = rabbitMqConfig.Vhost
1393+
}
1394+
return controllerutil.SetControllerReference(instance, transportURL, r.Scheme)
13901395
})
13911396

13921397
return transportURL, op, err

‎test/functional/glance_controller_test.go‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,46 @@ var _ = Describe("Glance controller", func() {
812812
})
813813
})
814814

815+
When("Glance is created with RabbitMQ user and vhost", func() {
816+
BeforeEach(func() {
817+
DeferCleanup(k8sClient.Delete, ctx, CreateGlanceMessageBusSecret(glanceTest.Instance.Namespace, glanceTest.RabbitmqSecretName))
818+
DeferCleanup(infra.DeleteMemcached, infra.CreateMemcached(namespace, glanceTest.MemcachedInstance, memcachedSpec))
819+
infra.SimulateMemcachedReady(glanceTest.GlanceMemcached)
820+
spec := GetGlanceDefaultSpec()
821+
spec["notificationBusInstance"] = glanceTest.NotificationsBusInstance
822+
spec["notificationsRabbitmq"] = map[string]interface{}{
823+
"user": "glance-user",
824+
"vhost": "glance-vhost",
825+
}
826+
DeferCleanup(th.DeleteInstance, CreateGlance(glanceTest.Instance, spec))
827+
})
828+
It("sets custom RabbitMQ user and vhost in TransportURL", func() {
829+
Eventually(func(g Gomega) {
830+
transportURL := infra.GetTransportURL(glanceTest.GlanceTransportURL)
831+
g.Expect(transportURL.Spec.Username).To(Equal("glance-user"))
832+
g.Expect(transportURL.Spec.Vhost).To(Equal("glance-vhost"))
833+
}, timeout, interval).Should(Succeed())
834+
})
835+
})
836+
837+
When("Glance is created without custom RabbitMQ config", func() {
838+
BeforeEach(func() {
839+
DeferCleanup(k8sClient.Delete, ctx, CreateGlanceMessageBusSecret(glanceTest.Instance.Namespace, glanceTest.RabbitmqSecretName))
840+
DeferCleanup(infra.DeleteMemcached, infra.CreateMemcached(namespace, glanceTest.MemcachedInstance, memcachedSpec))
841+
infra.SimulateMemcachedReady(glanceTest.GlanceMemcached)
842+
spec := GetGlanceDefaultSpec()
843+
spec["notificationBusInstance"] = glanceTest.NotificationsBusInstance
844+
DeferCleanup(th.DeleteInstance, CreateGlance(glanceTest.Instance, spec))
845+
})
846+
It("uses default RabbitMQ configuration in TransportURL", func() {
847+
Eventually(func(g Gomega) {
848+
transportURL := infra.GetTransportURL(glanceTest.GlanceTransportURL)
849+
g.Expect(transportURL.Spec.Username).To(BeEmpty())
850+
g.Expect(transportURL.Spec.Vhost).To(BeEmpty())
851+
}, timeout, interval).Should(Succeed())
852+
})
853+
})
854+
815855
// Run MariaDBAccount suite tests. these are pre-packaged ginkgo tests
816856
// that exercise standard account create / update patterns that should be
817857
// common to all controllers that ensure MariaDBAccount CRs.

0 commit comments

Comments
 (0)