@@ -132,6 +132,10 @@ func (r *OpenStackControlPlane) ValidateCreate() (admission.Warnings, error) {
132132 allErrs = append (allErrs , err )
133133 }
134134
135+ if err := r .ValidateNotificationsBusInstance (basePath ); err != nil {
136+ allErrs = append (allErrs , err )
137+ }
138+
135139 if len (allErrs ) != 0 {
136140 return allWarn , apierrors .NewInvalid (
137141 schema.GroupKind {Group : "core.openstack.org" , Kind : "OpenStackControlPlane" },
@@ -161,6 +165,10 @@ func (r *OpenStackControlPlane) ValidateUpdate(old runtime.Object) (admission.Wa
161165 allErrs = append (allErrs , err )
162166 }
163167
168+ if err := r .ValidateNotificationsBusInstance (basePath ); err != nil {
169+ allErrs = append (allErrs , err )
170+ }
171+
164172 if len (allErrs ) != 0 {
165173 return nil , apierrors .NewInvalid (
166174 schema.GroupKind {Group : "core.openstack.org" , Kind : "OpenStackControlPlane" },
@@ -361,6 +369,13 @@ func (r *OpenStackControlPlane) ValidateCreateServices(basePath *field.Path) (ad
361369 errors = append (errors , validateTLSOverrideSpec (& r .Spec .Watcher .APIOverride .Route , basePath .Child ("watcher" ).Child ("apiOverride" ).Child ("route" ))... )
362370 }
363371
372+ if r .Spec .Telemetry .Enabled {
373+ errors = append (errors , r .Spec .Telemetry .Template .ValidateCreate (basePath .Child ("telemetry" ).Child ("template" ), r .Namespace )... )
374+ errors = append (errors , validateTLSOverrideSpec (& r .Spec .Telemetry .AodhAPIOverride .Route , basePath .Child ("telemetry" ).Child ("aodhApiOverride" ).Child ("route" ))... )
375+ errors = append (errors , validateTLSOverrideSpec (& r .Spec .Telemetry .PrometheusOverride .Route , basePath .Child ("telemetry" ).Child ("prometheusOverride" ).Child ("route" ))... )
376+ errors = append (errors , validateTLSOverrideSpec (& r .Spec .Telemetry .AlertmanagerOverride .Route , basePath .Child ("telemetry" ).Child ("alertmanagerOverride" ).Child ("route" ))... )
377+ }
378+
364379 // Validation for remaining services...
365380 if r .Spec .Galera .Enabled {
366381 for key , s := range * r .Spec .Galera .Templates {
@@ -556,6 +571,15 @@ func (r *OpenStackControlPlane) ValidateUpdateServices(old OpenStackControlPlane
556571 errors = append (errors , r .Spec .Watcher .Template .ValidateUpdate (* old .Watcher .Template , basePath .Child ("watcher" ).Child ("template" ), r .Namespace )... )
557572 errors = append (errors , validateTLSOverrideSpec (& r .Spec .Watcher .APIOverride .Route , basePath .Child ("watcher" ).Child ("apiOverride" ).Child ("route" ))... )
558573 }
574+ if r .Spec .Telemetry .Enabled {
575+ if old .Telemetry .Template == nil {
576+ old .Telemetry .Template = & telemetryv1.TelemetrySpecCore {}
577+ }
578+ errors = append (errors , r .Spec .Telemetry .Template .ValidateUpdate (* old .Telemetry .Template , basePath .Child ("telemetry" ).Child ("template" ), r .Namespace )... )
579+ errors = append (errors , validateTLSOverrideSpec (& r .Spec .Telemetry .AodhAPIOverride .Route , basePath .Child ("telemetry" ).Child ("aodhApiOverride" ).Child ("route" ))... )
580+ errors = append (errors , validateTLSOverrideSpec (& r .Spec .Telemetry .PrometheusOverride .Route , basePath .Child ("telemetry" ).Child ("prometheusOverride" ).Child ("route" ))... )
581+ errors = append (errors , validateTLSOverrideSpec (& r .Spec .Telemetry .AlertmanagerOverride .Route , basePath .Child ("telemetry" ).Child ("alertmanagerOverride" ).Child ("route" ))... )
582+ }
559583
560584 if r .Spec .Memcached .Enabled {
561585 if r .Spec .Memcached .Templates != nil {
@@ -1142,3 +1166,28 @@ func (r *OpenStackControlPlane) ValidateTopology(basePath *field.Path) *field.Er
11421166 }
11431167 return nil
11441168}
1169+
1170+ // ValidateNotificationsBusInstance - returns an error if the notificationsBusInstance
1171+ // parameter is not valid.
1172+ // - nil or empty string must be raised as an error
1173+ // - when notificationsBusInstance does not point to an existing RabbitMQ instance
1174+ func (r * OpenStackControlPlane ) ValidateNotificationsBusInstance (basePath * field.Path ) * field.Error {
1175+ notificationsField := basePath .Child ("notificationsBusInstance" )
1176+ // no notificationsBusInstance field set, nothing to validate here
1177+ if r .Spec .NotificationsBusInstance == nil {
1178+ return nil
1179+ }
1180+ // When NotificationsBusInstance is set, fail if it is an empty string
1181+ if * r .Spec .NotificationsBusInstance == "" {
1182+ return field .Invalid (notificationsField , * r .Spec .NotificationsBusInstance , "notificationsBusInstance is not a valid string" )
1183+ }
1184+ // NotificationsBusInstance is set and must be equal to an existing
1185+ // deployed rabbitmq instance, otherwise we should fail because it
1186+ // does not represent a valid string
1187+ for k := range (* r .Spec .Rabbitmq .Templates ) {
1188+ if * r .Spec .NotificationsBusInstance == k {
1189+ return nil
1190+ }
1191+ }
1192+ return field .Invalid (notificationsField , * r .Spec .NotificationsBusInstance , "notificationsBusInstance must match an existing RabbitMQ instance name" )
1193+ }
0 commit comments