Skip to content

Commit e216e40

Browse files
committed
Rabbitmq vhost and user support
Add new messagingBus and notificationsBus interfaces 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: messagingBus: cluster: rpc-rabbitmq user: rpc-user vhost: rpc-vhost notificationsBus: cluster: notifications-rabbitmq user: notifications-user vhost: notifications-vhost Jira: https://issues.redhat.com/browse/OSPRH-23882
1 parent 74db373 commit e216e40

12 files changed

Lines changed: 614 additions & 34 deletions

api/bases/watcher.openstack.org_watchers.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,13 +608,46 @@ spec:
608608
description: MemcachedInstance is the name of the Memcached CR that
609609
all watcher service will use.
610610
type: string
611+
messagingBus:
612+
description: MessagingBus configuration (username, vhost, and cluster)
613+
properties:
614+
cluster:
615+
description: Name of the cluster
616+
minLength: 1
617+
type: string
618+
user:
619+
description: User - RabbitMQ username
620+
type: string
621+
vhost:
622+
description: Vhost - RabbitMQ vhost name
623+
type: string
624+
required:
625+
- cluster
626+
type: object
611627
nodeSelector:
612628
additionalProperties:
613629
type: string
614630
description: |-
615631
NodeSelector to target subset of worker nodes running this component. Setting here overrides
616632
any global NodeSelector settings within the Watcher CR.
617633
type: object
634+
notificationsBus:
635+
description: NotificationsBus configuration (username, vhost, and
636+
cluster) for notifications
637+
properties:
638+
cluster:
639+
description: Name of the cluster
640+
minLength: 1
641+
type: string
642+
user:
643+
description: User - RabbitMQ username
644+
type: string
645+
vhost:
646+
description: Vhost - RabbitMQ vhost name
647+
type: string
648+
required:
649+
- cluster
650+
type: object
618651
notificationsBusInstance:
619652
description: |-
620653
NotificationsBusInstance is the name of the RabbitMqCluster CR to select
@@ -623,6 +656,7 @@ spec:
623656
If undefined, the value will be inherited from OpenStackControlPlane.
624657
An empty value "" leaves the notification drivers unconfigured and emitting no notifications at all.
625658
Avoid colocating it with RabbitMqClusterName or other message bus instances used for RPC.
659+
Deprecated: Use NotificationsBus.Cluster instead
626660
type: string
627661
passwordSelectors:
628662
default:
@@ -650,6 +684,7 @@ spec:
650684
description: |-
651685
RabbitMQ instance name
652686
Needed to request a transportURL that is created and used in Watcher
687+
Deprecated: Use MessagingBus.Cluster instead
653688
type: string
654689
secret:
655690
default: osp-secret

api/go.mod

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ go 1.24.4
55
toolchain go1.24.6
66

77
require (
8-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251110170511-c2d4a351a7c3
9-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251103072528-9eb684fef4ef
10-
k8s.io/api v0.31.13
11-
k8s.io/apimachinery v0.31.13
8+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251217131115-0f117a938d4e
9+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251122131503-b76943960b6c
10+
k8s.io/api v0.31.14
11+
k8s.io/apimachinery v0.31.14
1212
k8s.io/utils v0.0.0-20250820121507-0af2bda4dd1d
1313
sigs.k8s.io/controller-runtime v0.19.7
1414
)
@@ -18,7 +18,6 @@ require (
1818
github.com/cespare/xxhash/v2 v2.3.0 // indirect
1919
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
2020
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
21-
github.com/evanphx/json-patch v5.9.11+incompatible // indirect
2221
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
2322
github.com/fsnotify/fsnotify v1.9.0 // indirect
2423
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
@@ -45,10 +44,9 @@ require (
4544
github.com/prometheus/client_model v0.6.2 // indirect
4645
github.com/prometheus/common v0.65.0 // indirect
4746
github.com/prometheus/procfs v0.16.1 // indirect
48-
github.com/rogpeppe/go-internal v1.13.1 // indirect
47+
github.com/rabbitmq/cluster-operator/v2 v2.16.0 // indirect
4948
github.com/spf13/pflag v1.0.7 // indirect
5049
github.com/x448/float16 v0.8.4 // indirect
51-
go.uber.org/zap v1.27.1 // indirect
5250
go.yaml.in/yaml/v2 v2.4.2 // indirect
5351
go.yaml.in/yaml/v3 v3.0.4 // indirect
5452
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 // indirect
@@ -63,7 +61,7 @@ require (
6361
gopkg.in/inf.v0 v0.9.1 // indirect
6462
gopkg.in/yaml.v3 v3.0.1 // indirect
6563
k8s.io/apiextensions-apiserver v0.33.2 // indirect
66-
k8s.io/client-go v0.31.13 // indirect
64+
k8s.io/client-go v0.31.14 // indirect
6765
k8s.io/klog/v2 v2.130.1 // indirect
6866
k8s.io/kube-openapi v0.0.0-20250902184714-7fc278399c7f // indirect
6967
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect

api/go.sum

Lines changed: 7 additions & 4 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=
@@ -78,10 +79,12 @@ github.com/onsi/ginkgo/v2 v2.27.2 h1:LzwLj0b89qtIy6SSASkzlNvX6WktqurSHwkk2ipF/Ns
7879
github.com/onsi/ginkgo/v2 v2.27.2/go.mod h1:ArE1D/XhNXBXCBkKOLkbsb2c81dQHCRcF5zwn/ykDRo=
7980
github.com/onsi/gomega v1.38.2 h1:eZCjf2xjZAqe+LeWvKb5weQ+NcPwX84kqJ0cZNxok2A=
8081
github.com/onsi/gomega v1.38.2/go.mod h1:W2MJcYxRGV63b418Ai34Ud0hEdTVXq9NW9+Sx6uXf3k=
81-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251110170511-c2d4a351a7c3 h1:gKazSLpq0Ytn4OLzNtSKQpLswAdki8u8mXZgpJy83bE=
82-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251110170511-c2d4a351a7c3/go.mod h1:Y9LqOS1wYhn7RT4jFknINdWa+ziYEIOU1jLNxkxiCsw=
83-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251103072528-9eb684fef4ef h1:1j7kk+D4ZdIXm6C/IwEjuTzIuvWUytxO39E/x94JY7k=
84-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251103072528-9eb684fef4ef/go.mod h1:kUT/SyuxZiOcX8ZuvpFN3PaQa2V8uQon8YwY+1RoQWM=
82+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251217131115-0f117a938d4e h1:PIjcXzMMwfvBRFgFpaq/W9tqy0t2cYvcWX+kq6uNtTM=
83+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251217131115-0f117a938d4e/go.mod h1:ex8ou6/3ms6ovR+CMXD6XhTlNakm1GhB6UZgagVRNW8=
84+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251122131503-b76943960b6c h1:wM8qXCB5mQwSosCvtaydzuXitWVVKBHTzH0A2znQ+Jg=
85+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251122131503-b76943960b6c/go.mod h1:+Me0raWPPdz8gRi9D4z1khmvUgS9vIKAVC8ckg1yJZU=
86+
github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20250929174222-a0d328fa4dec h1:saovr368HPAKHN0aRPh8h8n9s9dn3d8Frmfua0UYRlc=
87+
github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20250929174222-a0d328fa4dec/go.mod h1:Nh2NEePLjovUQof2krTAg4JaAoLacqtPTZQXK6izNfg=
8588
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
8689
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
8790
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=

api/v1beta1/common_types.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20-
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
21-
20+
rabbitmqv1 "github.com/openstack-k8s-operators/infra-operator/apis/rabbitmq/v1beta1"
2221
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
22+
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
2323

2424
corev1 "k8s.io/api/core/v1"
2525
)
@@ -83,10 +83,19 @@ type WatcherSpecCore struct {
8383
// Important: Run "make" to regenerate code after modifying this file
8484
WatcherCommon `json:",inline"`
8585

86+
// +kubebuilder:validation:Optional
87+
// MessagingBus configuration (username, vhost, and cluster)
88+
MessagingBus rabbitmqv1.RabbitMqConfig `json:"messagingBus,omitempty"`
89+
90+
// +kubebuilder:validation:Optional
91+
// NotificationsBus configuration (username, vhost, and cluster) for notifications
92+
NotificationsBus *rabbitmqv1.RabbitMqConfig `json:"notificationsBus,omitempty"`
93+
8694
// +kubebuilder:validation:Required
8795
// +kubebuilder:default=rabbitmq
8896
// RabbitMQ instance name
8997
// Needed to request a transportURL that is created and used in Watcher
98+
// Deprecated: Use MessagingBus.Cluster instead
9099
RabbitMqClusterName *string `json:"rabbitMqClusterName"`
91100

92101
// +kubebuilder:validation:Optional
@@ -136,6 +145,7 @@ type WatcherSpecCore struct {
136145
// If undefined, the value will be inherited from OpenStackControlPlane.
137146
// An empty value "" leaves the notification drivers unconfigured and emitting no notifications at all.
138147
// Avoid colocating it with RabbitMqClusterName or other message bus instances used for RPC.
148+
// Deprecated: Use NotificationsBus.Cluster instead
139149
NotificationsBusInstance *string `json:"notificationsBusInstance,omitempty"`
140150
}
141151

api/v1beta1/watcher_webhook.go

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package v1beta1
1919
import (
2020
"fmt"
2121

22+
rabbitmqv1 "github.com/openstack-k8s-operators/infra-operator/apis/rabbitmq/v1beta1"
2223
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
2324
apierrors "k8s.io/apimachinery/pkg/api/errors"
2425
"k8s.io/apimachinery/pkg/runtime"
@@ -59,12 +60,31 @@ func (r *Watcher) Default() {
5960

6061
// Default - set defaults for this WatcherCore spec.
6162
func (spec *WatcherSpec) Default() {
63+
spec.WatcherSpecCore.Default()
6264
spec.WatcherImages.Default(watcherDefaults)
6365
}
6466

6567
// Default - set defaults for this WatcherSpecCore spec.
6668
func (spec *WatcherSpecCore) Default() {
67-
// no validations . Placeholder for defaulting webhook integrated in the OpenStackControlPlane
69+
// Default MessagingBus from deprecated RabbitMqClusterName
70+
if spec.RabbitMqClusterName != nil {
71+
rabbitmqv1.DefaultRabbitMqConfig(&spec.MessagingBus, *spec.RabbitMqClusterName)
72+
}
73+
74+
// Default NotificationsBus if NotificationsBusInstance is specified
75+
if spec.NotificationsBusInstance != nil && *spec.NotificationsBusInstance != "" {
76+
if spec.NotificationsBus == nil {
77+
// Initialize NotificationsBus with MessagingBus values to inherit user/vhost
78+
spec.NotificationsBus = &rabbitmqv1.RabbitMqConfig{
79+
User: spec.MessagingBus.User,
80+
Vhost: spec.MessagingBus.Vhost,
81+
}
82+
}
83+
// Always default the Cluster field from NotificationsBusInstance if it's empty
84+
if spec.NotificationsBus.Cluster == "" {
85+
rabbitmqv1.DefaultRabbitMqConfig(spec.NotificationsBus, *spec.NotificationsBusInstance)
86+
}
87+
}
6888
}
6989

7090
var _ webhook.Validator = &Watcher{}
@@ -95,15 +115,15 @@ func (spec *WatcherSpec) ValidateCreate(basePath *field.Path, namespace string)
95115
func (spec *WatcherSpecCore) ValidateCreate(basePath *field.Path, namespace string) field.ErrorList {
96116
var allErrs field.ErrorList
97117

98-
if *spec.DatabaseInstance == "" || spec.DatabaseInstance == nil {
118+
if spec.DatabaseInstance == nil || *spec.DatabaseInstance == "" {
99119
allErrs = append(
100120
allErrs,
101121
field.Invalid(
102122
basePath.Child("databaseInstance"), "", "databaseInstance field should not be empty"),
103123
)
104124
}
105125

106-
if *spec.RabbitMqClusterName == "" || spec.RabbitMqClusterName == nil {
126+
if spec.RabbitMqClusterName == nil || *spec.RabbitMqClusterName == "" {
107127
allErrs = append(
108128
allErrs,
109129
field.Invalid(
@@ -148,22 +168,38 @@ func (spec *WatcherSpec) ValidateUpdate(old WatcherSpec, basePath *field.Path, n
148168
func (spec *WatcherSpecCore) ValidateUpdate(old WatcherSpecCore, basePath *field.Path, namespace string) field.ErrorList {
149169
var allErrs field.ErrorList
150170

151-
if *spec.DatabaseInstance == "" || spec.DatabaseInstance == nil {
171+
if spec.DatabaseInstance == nil || *spec.DatabaseInstance == "" {
152172
allErrs = append(
153173
allErrs,
154174
field.Invalid(
155175
basePath.Child("databaseInstance"), "", "databaseInstance field should not be empty"),
156176
)
157177
}
158178

159-
if *spec.RabbitMqClusterName == "" || spec.RabbitMqClusterName == nil {
179+
if spec.RabbitMqClusterName == nil || *spec.RabbitMqClusterName == "" {
160180
allErrs = append(
161181
allErrs,
162182
field.Invalid(
163183
basePath.Child("rabbitMqClusterName"), "", "rabbitMqClusterName field should not be empty"),
164184
)
165185
}
166186

187+
// Reject changes to deprecated RabbitMqClusterName field
188+
if spec.RabbitMqClusterName != nil && old.RabbitMqClusterName != nil &&
189+
*spec.RabbitMqClusterName != *old.RabbitMqClusterName {
190+
allErrs = append(allErrs, field.Forbidden(
191+
basePath.Child("rabbitMqClusterName"),
192+
"rabbitMqClusterName is deprecated and cannot be changed. Please use messagingBus.cluster instead"))
193+
}
194+
195+
// Reject changes to deprecated NotificationsBusInstance field
196+
if spec.NotificationsBusInstance != nil && old.NotificationsBusInstance != nil &&
197+
*spec.NotificationsBusInstance != *old.NotificationsBusInstance {
198+
allErrs = append(allErrs, field.Forbidden(
199+
basePath.Child("notificationsBusInstance"),
200+
"notificationsBusInstance is deprecated and cannot be changed. Please use notificationsBus.cluster instead"))
201+
}
202+
167203
allErrs = append(allErrs, spec.ValidateWatcherTopology(basePath, namespace)...)
168204

169205
return allErrs

api/v1beta1/zz_generated.deepcopy.go

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

config/crd/bases/watcher.openstack.org_watchers.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,13 +608,46 @@ spec:
608608
description: MemcachedInstance is the name of the Memcached CR that
609609
all watcher service will use.
610610
type: string
611+
messagingBus:
612+
description: MessagingBus configuration (username, vhost, and cluster)
613+
properties:
614+
cluster:
615+
description: Name of the cluster
616+
minLength: 1
617+
type: string
618+
user:
619+
description: User - RabbitMQ username
620+
type: string
621+
vhost:
622+
description: Vhost - RabbitMQ vhost name
623+
type: string
624+
required:
625+
- cluster
626+
type: object
611627
nodeSelector:
612628
additionalProperties:
613629
type: string
614630
description: |-
615631
NodeSelector to target subset of worker nodes running this component. Setting here overrides
616632
any global NodeSelector settings within the Watcher CR.
617633
type: object
634+
notificationsBus:
635+
description: NotificationsBus configuration (username, vhost, and
636+
cluster) for notifications
637+
properties:
638+
cluster:
639+
description: Name of the cluster
640+
minLength: 1
641+
type: string
642+
user:
643+
description: User - RabbitMQ username
644+
type: string
645+
vhost:
646+
description: Vhost - RabbitMQ vhost name
647+
type: string
648+
required:
649+
- cluster
650+
type: object
618651
notificationsBusInstance:
619652
description: |-
620653
NotificationsBusInstance is the name of the RabbitMqCluster CR to select
@@ -623,6 +656,7 @@ spec:
623656
If undefined, the value will be inherited from OpenStackControlPlane.
624657
An empty value "" leaves the notification drivers unconfigured and emitting no notifications at all.
625658
Avoid colocating it with RabbitMqClusterName or other message bus instances used for RPC.
659+
Deprecated: Use NotificationsBus.Cluster instead
626660
type: string
627661
passwordSelectors:
628662
default:
@@ -650,6 +684,7 @@ spec:
650684
description: |-
651685
RabbitMQ instance name
652686
Needed to request a transportURL that is created and used in Watcher
687+
Deprecated: Use MessagingBus.Cluster instead
653688
type: string
654689
secret:
655690
default: osp-secret

go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ require (
88
github.com/onsi/ginkgo/v2 v2.27.2
99
github.com/onsi/gomega v1.38.2
1010
github.com/openshift/api v3.9.0+incompatible
11-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251110170511-c2d4a351a7c3
11+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251217131115-0f117a938d4e
1212
github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20251027074845-ed8154b20ad1
13-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251103072528-9eb684fef4ef
13+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251122131503-b76943960b6c
1414
github.com/openstack-k8s-operators/lib-common/modules/test v0.6.1-0.20251103072528-9eb684fef4ef
1515
github.com/openstack-k8s-operators/mariadb-operator/api v0.6.1-0.20251110170510-e669472c745c
1616
github.com/openstack-k8s-operators/watcher-operator/api v0.0.0-00010101000000-000000000000
1717
go.uber.org/zap v1.27.1
1818
gopkg.in/yaml.v3 v3.0.1
19-
k8s.io/api v0.31.13
20-
k8s.io/apimachinery v0.31.13
21-
k8s.io/client-go v0.31.13
19+
k8s.io/api v0.31.14
20+
k8s.io/apimachinery v0.31.14
21+
k8s.io/client-go v0.31.14
2222
k8s.io/utils v0.0.0-20250820121507-0af2bda4dd1d
2323
sigs.k8s.io/controller-runtime v0.19.7
2424
)

0 commit comments

Comments
 (0)