@@ -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" },
@@ -1138,3 +1146,28 @@ func (r *OpenStackControlPlane) ValidateTopology(basePath *field.Path) *field.Er
11381146 }
11391147 return nil
11401148}
1149+
1150+ // ValidateNotificationsBusInstance - returns an error if the notificationsBusInstance
1151+ // parameter is not valid.
1152+ // - nil or empty string must be raised as an error
1153+ // - when notificationsBusInstance does not point to an existing RabbitMQ instance
1154+ func (r * OpenStackControlPlane ) ValidateNotificationsBusInstance (basePath * field.Path ) * field.Error {
1155+ notificationsField := basePath .Child ("notificationsBusInstance" )
1156+ // no notificationsBusInstance field set, nothing to validate here
1157+ if r .Spec .NotificationsBusInstance == nil {
1158+ return nil
1159+ }
1160+ // When NotificationsBusInstance is set, fail if it is an empty string
1161+ if * r .Spec .NotificationsBusInstance == "" {
1162+ return field .Invalid (notificationsField , * r .Spec .NotificationsBusInstance , "notificationsBusInstance is not a valid string" )
1163+ }
1164+ // NotificationsBusInstance is set and must be equal to an existing
1165+ // deployed rabbitmq instance, otherwise we should fail because it
1166+ // does not represent a valid string
1167+ for k := range (* r .Spec .Rabbitmq .Templates ) {
1168+ if * r .Spec .NotificationsBusInstance == k {
1169+ return nil
1170+ }
1171+ }
1172+ return field .Invalid (notificationsField , * r .Spec .NotificationsBusInstance , "notificationsBusInstance must match an existing RabbitMQ instance name" )
1173+ }
0 commit comments