@@ -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" },
@@ -1122,3 +1130,23 @@ func (r *OpenStackControlPlane) ValidateTopology(basePath *field.Path) *field.Er
11221130 }
11231131 return nil
11241132}
1133+
1134+ func (r * OpenStackControlPlane ) ValidateNotificationsBusInstance (basePath * field.Path ) * field.Error {
1135+ notificationsField := basePath .Child ("notificationsBusInstance" )
1136+ // no notificationsBusInstance field set, nothing to validate here
1137+ if r .Spec .NotificationsBusInstance == nil {
1138+ return nil
1139+ }
1140+ // When NotificationsBusInstance is set, fail if it does not represent a valid string
1141+ if len (* r .Spec .NotificationsBusInstance ) == 0 {
1142+ return field .Invalid (notificationsField , "notificationsBusInstance" , "notificationsBusInstance is not a valid string" )
1143+ }
1144+ // NotificationsBusInstance is set and must be equal to an existing
1145+ // deployed rabbitmq instance, otherwise we should fail
1146+ for k := range (* r .Spec .Rabbitmq .Templates ) {
1147+ if * r .Spec .NotificationsBusInstance == k {
1148+ return nil
1149+ }
1150+ }
1151+ return field .Invalid (notificationsField , "notificationsBusInstance" , "notificationsBusInstance must match an existing RabbitMQ instance name" )
1152+ }
0 commit comments