Skip to content

Commit f5abf3f

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 0853487 commit f5abf3f

File tree

20 files changed

+1004
-119
lines changed

20 files changed

+1004
-119
lines changed

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: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ 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.20251223124749-eedb97238c5f
9-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251230215914-6ba873b49a35
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
1010
k8s.io/api v0.31.14
1111
k8s.io/apimachinery v0.31.14
1212
k8s.io/utils v0.0.0-20250820121507-0af2bda4dd1d
@@ -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,16 +44,17 @@ 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
47+
github.com/rabbitmq/cluster-operator/v2 v2.16.0 // indirect
4848
github.com/spf13/pflag v1.0.7 // indirect
4949
github.com/x448/float16 v0.8.4 // indirect
5050
go.yaml.in/yaml/v2 v2.4.2 // indirect
5151
go.yaml.in/yaml/v3 v3.0.4 // indirect
5252
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 // indirect
5353
golang.org/x/net v0.43.0 // indirect
5454
golang.org/x/oauth2 v0.30.0 // indirect
55-
golang.org/x/sys v0.36.0 // indirect
56-
golang.org/x/term v0.35.0 // indirect
57-
golang.org/x/text v0.29.0 // indirect
55+
golang.org/x/sys v0.35.0 // indirect
56+
golang.org/x/term v0.34.0 // indirect
57+
golang.org/x/text v0.28.0 // indirect
5858
golang.org/x/time v0.12.0 // indirect
5959
gomodules.xyz/jsonpatch/v2 v2.5.0 // indirect
6060
google.golang.org/protobuf v1.36.7 // indirect
@@ -71,21 +71,21 @@ require (
7171
)
7272

7373
// pin these to avoid later versions pulled by rabbitmq
74-
replace k8s.io/apimachinery => k8s.io/apimachinery v0.31.14 //allow-merging
74+
replace k8s.io/apimachinery => k8s.io/apimachinery v0.31.13 //allow-merging
7575

76-
replace k8s.io/api => k8s.io/api v0.31.14 //allow-merging
76+
replace k8s.io/api => k8s.io/api v0.31.13 //allow-merging
7777

78-
replace k8s.io/apiserver => k8s.io/apiserver v0.31.14 //allow-merging
78+
replace k8s.io/apiserver => k8s.io/apiserver v0.31.13 //allow-merging
7979

80-
replace k8s.io/client-go => k8s.io/client-go v0.31.14 //allow-merging
80+
replace k8s.io/client-go => k8s.io/client-go v0.31.13 //allow-merging
8181

82-
replace k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.31.14 //allow-merging
82+
replace k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.31.13 //allow-merging
8383

84-
replace k8s.io/cli-runtime => k8s.io/cli-runtime v0.31.14 //allow-merging
84+
replace k8s.io/cli-runtime => k8s.io/cli-runtime v0.31.13 //allow-merging
8585

86-
replace k8s.io/code-generator => k8s.io/code-generator v0.31.14 //allow-merging
86+
replace k8s.io/code-generator => k8s.io/code-generator v0.31.13 //allow-merging
8787

88-
replace k8s.io/component-base => k8s.io/component-base v0.31.14 //allow-merging
88+
replace k8s.io/component-base => k8s.io/component-base v0.31.13 //allow-merging
8989

9090
// custom RabbitmqClusterSpecCore for OpenStackControlplane (v2.16.0_patches)
9191
replace github.com/rabbitmq/cluster-operator/v2 => github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20250929174222-a0d328fa4dec //allow-merging

api/go.sum

Lines changed: 27 additions & 24 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=
@@ -74,14 +75,16 @@ github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee h1:W5t00kpgFd
7475
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
7576
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
7677
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
77-
github.com/onsi/ginkgo/v2 v2.27.3 h1:ICsZJ8JoYafeXFFlFAG75a7CxMsJHwgKwtO+82SE9L8=
78-
github.com/onsi/ginkgo/v2 v2.27.3/go.mod h1:ArE1D/XhNXBXCBkKOLkbsb2c81dQHCRcF5zwn/ykDRo=
79-
github.com/onsi/gomega v1.38.3 h1:eTX+W6dobAYfFeGC2PV6RwXRu/MyT+cQguijutvkpSM=
80-
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.20251223124749-eedb97238c5f h1:xcCGJ/g5vvbWhtEJCbv8UeBneI5yrMawm+CXRsJrJZo=
82-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20251223124749-eedb97238c5f/go.mod h1:ex8ou6/3ms6ovR+CMXD6XhTlNakm1GhB6UZgagVRNW8=
83-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251230215914-6ba873b49a35 h1:pF3mJ3nwq6r4qwom+rEWZNquZpcQW/iftHlJ1KPIDsk=
84-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251230215914-6ba873b49a35/go.mod h1:kycZyoe7OZdW1HUghr2nI3N7wSJtNahXf6b/ypD14f4=
78+
github.com/onsi/ginkgo/v2 v2.27.2 h1:LzwLj0b89qtIy6SSASkzlNvX6WktqurSHwkk2ipF/Ns=
79+
github.com/onsi/ginkgo/v2 v2.27.2/go.mod h1:ArE1D/XhNXBXCBkKOLkbsb2c81dQHCRcF5zwn/ykDRo=
80+
github.com/onsi/gomega v1.38.2 h1:eZCjf2xjZAqe+LeWvKb5weQ+NcPwX84kqJ0cZNxok2A=
81+
github.com/onsi/gomega v1.38.2/go.mod h1:W2MJcYxRGV63b418Ai34Ud0hEdTVXq9NW9+Sx6uXf3k=
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=
@@ -137,19 +140,19 @@ golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKl
137140
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
138141
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
139142
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
140-
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
141-
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
143+
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
144+
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
142145
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
143146
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
144147
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
145-
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
146-
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
147-
golang.org/x/term v0.35.0 h1:bZBVKBudEyhRcajGcNc3jIfWPqV4y/Kt2XcoigOWtDQ=
148-
golang.org/x/term v0.35.0/go.mod h1:TPGtkTLesOwf2DE8CgVYiZinHAOuy5AYUYT1lENIZnA=
148+
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
149+
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
150+
golang.org/x/term v0.34.0 h1:O/2T7POpk0ZZ7MAzMeWFSg6S5IpWd/RXDlM9hgM3DR4=
151+
golang.org/x/term v0.34.0/go.mod h1:5jC53AEywhIVebHgPVeg0mj8OD3VO9OzclacVrqpaAw=
149152
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
150153
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
151-
golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
152-
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
154+
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
155+
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
153156
golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
154157
golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
155158
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@@ -175,14 +178,14 @@ gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
175178
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
176179
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
177180
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
178-
k8s.io/api v0.31.14 h1:xYn/S/WFJsksI7dk/5uBRd3Umm/D8W5g7sRnd4csotA=
179-
k8s.io/api v0.31.14/go.mod h1:K8fvRey4z73RAuxBZCma7WtY8WFvkViYhfFLCMT4xgA=
180-
k8s.io/apiextensions-apiserver v0.31.14 h1:1KupD0PyU7CgiT/PiZPSgZhTCL2KGwvXd1ejGcxjEfg=
181-
k8s.io/apiextensions-apiserver v0.31.14/go.mod h1:Odk14fSl/zaciI8DRUSPMSH74UXtz4gfinw7zY7YHvE=
182-
k8s.io/apimachinery v0.31.14 h1:/eMIwjv+GFm6A/sSGlB1NupBU6wTDPhEWsju0Fj69kY=
183-
k8s.io/apimachinery v0.31.14/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
184-
k8s.io/client-go v0.31.14 h1:d4/G0xfksNIbMWH7ghjzOwC5bTAwQ20gABTjZw7fLlQ=
185-
k8s.io/client-go v0.31.14/go.mod h1:0uRpRB7r5QwtsbxEngZPkbcIVoNdAQAPIcopgiXjhQc=
181+
k8s.io/api v0.31.13 h1:sco9Cq2pY4Ysv9qZiWzcR97MmA/35nwYQ/VCTzOcWmc=
182+
k8s.io/api v0.31.13/go.mod h1:4D8Ry8RqqLDemNLwGYC6v5wOy51N7hitr4WQ6oSWfLY=
183+
k8s.io/apiextensions-apiserver v0.31.13 h1:8xtWKVpV/YbYX0UX2k6w+cgxfxKhX0UNGuo/VXAdg8g=
184+
k8s.io/apiextensions-apiserver v0.31.13/go.mod h1:zxpMLWXBxnJqKUIruJ+ulP+Xlfe5lPZPxq1z0cLwA2U=
185+
k8s.io/apimachinery v0.31.13 h1:rkG0EiBkBkEzURo/8dKGx/oBF202Z2LqHuSD8Cm3bG4=
186+
k8s.io/apimachinery v0.31.13/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
187+
k8s.io/client-go v0.31.13 h1:Q0LG51uFbzNd9fzIj5ilA0Sm1wUholHvDaNwVKzqdCA=
188+
k8s.io/client-go v0.31.13/go.mod h1:UB4yTzQeRAv+vULOKp2jdqA5LSwV55bvc3RQ5tM48LM=
186189
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
187190
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
188191
k8s.io/kube-openapi v0.0.0-20250627150254-e9823e99808e h1:UGI9rv1A2cV87NhXr4s+AUBxIuoo/SME/IyJ3b6KztE=

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: 48 additions & 7 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,34 @@ 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+
// Apply kubebuilder default for RabbitMqClusterName if not set
70+
if spec.RabbitMqClusterName == nil {
71+
spec.RabbitMqClusterName = ptr.To("rabbitmq")
72+
}
73+
74+
// Default MessagingBus.Cluster from RabbitMqClusterName if not already set
75+
if spec.MessagingBus.Cluster == "" {
76+
rabbitmqv1.DefaultRabbitMqConfig(&spec.MessagingBus, *spec.RabbitMqClusterName)
77+
}
78+
79+
// Default NotificationsBus if NotificationsBusInstance is specified
80+
if spec.NotificationsBusInstance != nil && *spec.NotificationsBusInstance != "" {
81+
if spec.NotificationsBus == nil {
82+
// Initialize empty NotificationsBus - credentials will be created dynamically
83+
// to ensure separation from MessagingBus (RPC and notifications should never share credentials)
84+
spec.NotificationsBus = &rabbitmqv1.RabbitMqConfig{}
85+
}
86+
// Always default the Cluster field from NotificationsBusInstance if it's empty
87+
if spec.NotificationsBus.Cluster == "" {
88+
rabbitmqv1.DefaultRabbitMqConfig(spec.NotificationsBus, *spec.NotificationsBusInstance)
89+
}
90+
}
6891
}
6992

7093
var _ webhook.Validator = &Watcher{}
@@ -95,19 +118,20 @@ func (spec *WatcherSpec) ValidateCreate(basePath *field.Path, namespace string)
95118
func (spec *WatcherSpecCore) ValidateCreate(basePath *field.Path, namespace string) field.ErrorList {
96119
var allErrs field.ErrorList
97120

98-
if *spec.DatabaseInstance == "" || spec.DatabaseInstance == nil {
121+
if spec.DatabaseInstance == nil || *spec.DatabaseInstance == "" {
99122
allErrs = append(
100123
allErrs,
101124
field.Invalid(
102125
basePath.Child("databaseInstance"), "", "databaseInstance field should not be empty"),
103126
)
104127
}
105128

106-
if *spec.RabbitMqClusterName == "" || spec.RabbitMqClusterName == nil {
129+
// Validate messagingBus.cluster instead of deprecated rabbitMqClusterName
130+
if spec.MessagingBus.Cluster == "" {
107131
allErrs = append(
108132
allErrs,
109133
field.Invalid(
110-
basePath.Child("rabbitMqClusterName"), "", "rabbitMqClusterName field should not be empty"),
134+
basePath.Child("messagingBus").Child("cluster"), "", "messagingBus.cluster field should not be empty"),
111135
)
112136
}
113137

@@ -148,22 +172,39 @@ func (spec *WatcherSpec) ValidateUpdate(old WatcherSpec, basePath *field.Path, n
148172
func (spec *WatcherSpecCore) ValidateUpdate(old WatcherSpecCore, basePath *field.Path, namespace string) field.ErrorList {
149173
var allErrs field.ErrorList
150174

151-
if *spec.DatabaseInstance == "" || spec.DatabaseInstance == nil {
175+
if spec.DatabaseInstance == nil || *spec.DatabaseInstance == "" {
152176
allErrs = append(
153177
allErrs,
154178
field.Invalid(
155179
basePath.Child("databaseInstance"), "", "databaseInstance field should not be empty"),
156180
)
157181
}
158182

159-
if *spec.RabbitMqClusterName == "" || spec.RabbitMqClusterName == nil {
183+
// Validate messagingBus.cluster instead of deprecated rabbitMqClusterName
184+
if spec.MessagingBus.Cluster == "" {
160185
allErrs = append(
161186
allErrs,
162187
field.Invalid(
163-
basePath.Child("rabbitMqClusterName"), "", "rabbitMqClusterName field should not be empty"),
188+
basePath.Child("messagingBus").Child("cluster"), "", "messagingBus.cluster field should not be empty"),
164189
)
165190
}
166191

192+
// Reject changes to deprecated RabbitMqClusterName field
193+
if spec.RabbitMqClusterName != nil && old.RabbitMqClusterName != nil &&
194+
*spec.RabbitMqClusterName != *old.RabbitMqClusterName {
195+
allErrs = append(allErrs, field.Forbidden(
196+
basePath.Child("rabbitMqClusterName"),
197+
"rabbitMqClusterName is deprecated and cannot be changed. Please use messagingBus.cluster instead"))
198+
}
199+
200+
// Reject changes to deprecated NotificationsBusInstance field
201+
if spec.NotificationsBusInstance != nil && old.NotificationsBusInstance != nil &&
202+
*spec.NotificationsBusInstance != *old.NotificationsBusInstance {
203+
allErrs = append(allErrs, field.Forbidden(
204+
basePath.Child("notificationsBusInstance"),
205+
"notificationsBusInstance is deprecated and cannot be changed. Please use notificationsBus.cluster instead"))
206+
}
207+
167208
allErrs = append(allErrs, spec.ValidateWatcherTopology(basePath, namespace)...)
168209

169210
return allErrs

0 commit comments

Comments
 (0)