@@ -26,6 +26,7 @@ import (
2626 "fmt"
2727
2828 "github.com/google/go-cmp/cmp"
29+ rabbitmqv1 "github.com/openstack-k8s-operators/infra-operator/apis/rabbitmq/v1beta1"
2930 service "github.com/openstack-k8s-operators/lib-common/modules/common/service"
3031 "github.com/robfig/cron/v3"
3132
@@ -88,6 +89,26 @@ func (spec *NovaSpecCore) Default() {
8889 spec .APITimeout = novaDefaults .APITimeout
8990 }
9091
92+ // Default MessagingBus.Cluster from APIMessageBusInstance if not already set
93+ if spec .MessagingBus .Cluster == "" {
94+ spec .MessagingBus .Cluster = spec .APIMessageBusInstance
95+ }
96+
97+ // Default NotificationsBus if NotificationsBusInstance is specified
98+ if spec .NotificationsBusInstance != nil && * spec .NotificationsBusInstance != "" {
99+ if spec .NotificationsBus == nil {
100+ // Initialize NotificationsBus with MessagingBus values to inherit user/vhost
101+ spec .NotificationsBus = & rabbitmqv1.RabbitMqConfig {
102+ User : spec .MessagingBus .User ,
103+ Vhost : spec .MessagingBus .Vhost ,
104+ }
105+ }
106+ // Default cluster name if not already set
107+ if spec .NotificationsBus .Cluster == "" {
108+ spec .NotificationsBus .Cluster = * spec .NotificationsBusInstance
109+ }
110+ }
111+
91112 for cellName , cellTemplate := range spec .CellTemplates {
92113
93114 if cellTemplate .MetadataServiceTemplate .Enabled == nil {
@@ -106,6 +127,11 @@ func (spec *NovaSpecCore) Default() {
106127 }
107128 }
108129
130+ // Default MessagingBus.Cluster from CellMessageBusInstance if not already set
131+ if cellTemplate .MessagingBus .Cluster == "" {
132+ cellTemplate .MessagingBus .Cluster = cellTemplate .CellMessageBusInstance
133+ }
134+
109135 // "cellTemplate" is a by-value copy, so we need to re-inject the updated version of it into the map
110136 spec .CellTemplates [cellName ] = cellTemplate
111137 }
@@ -315,7 +341,34 @@ func (spec *NovaSpec) ValidateUpdate(old NovaSpec, basePath *field.Path, namespa
315341// expected to be called by the validation webhook in the higher level meta
316342// operator
317343func (spec * NovaSpecCore ) ValidateUpdate (old NovaSpecCore , basePath * field.Path , namespace string ) field.ErrorList {
318- errors := spec .ValidateCellTemplates (basePath , namespace )
344+ var errors field.ErrorList
345+
346+ // Reject changes to deprecated messagingBusInstance fields - users should use the new messagingBus fields instead
347+ if spec .APIMessageBusInstance != old .APIMessageBusInstance {
348+ errors = append (errors , field .Forbidden (
349+ basePath .Child ("apiMessageBusInstance" ),
350+ "apiMessageBusInstance is deprecated and cannot be changed. Please use messagingBus.cluster instead" ))
351+ }
352+
353+ if spec .NotificationsBusInstance != nil && old .NotificationsBusInstance != nil &&
354+ * spec .NotificationsBusInstance != * old .NotificationsBusInstance {
355+ errors = append (errors , field .Forbidden (
356+ basePath .Child ("notificationsBusInstance" ),
357+ "notificationsBusInstance is deprecated and cannot be changed. Please use notificationsBus.cluster instead" ))
358+ }
359+
360+ // Check cell template changes
361+ for cellName , cellTemplate := range spec .CellTemplates {
362+ if oldCell , exists := old .CellTemplates [cellName ]; exists {
363+ if cellTemplate .CellMessageBusInstance != oldCell .CellMessageBusInstance {
364+ errors = append (errors , field .Forbidden (
365+ basePath .Child ("cellTemplates" ).Key (cellName ).Child ("cellMessageBusInstance" ),
366+ "cellMessageBusInstance is deprecated and cannot be changed. Please use messagingBus.cluster instead" ))
367+ }
368+ }
369+ }
370+
371+ errors = append (errors , spec .ValidateCellTemplates (basePath , namespace )... )
319372 // Validate top-level TopologyRef
320373 errors = append (errors , topologyv1 .ValidateTopologyRef (
321374 spec .TopologyRef , * basePath .Child ("topologyRef" ), namespace )... )
0 commit comments