@@ -132,6 +132,10 @@ func (r *OpenStackControlPlane) ValidateCreate() (admission.Warnings, error) {
132
132
allErrs = append (allErrs , err )
133
133
}
134
134
135
+ if err := r .ValidateNotificationsBusInstance (basePath ); err != nil {
136
+ allErrs = append (allErrs , err )
137
+ }
138
+
135
139
if len (allErrs ) != 0 {
136
140
return allWarn , apierrors .NewInvalid (
137
141
schema.GroupKind {Group : "core.openstack.org" , Kind : "OpenStackControlPlane" },
@@ -161,6 +165,10 @@ func (r *OpenStackControlPlane) ValidateUpdate(old runtime.Object) (admission.Wa
161
165
allErrs = append (allErrs , err )
162
166
}
163
167
168
+ if err := r .ValidateNotificationsBusInstance (basePath ); err != nil {
169
+ allErrs = append (allErrs , err )
170
+ }
171
+
164
172
if len (allErrs ) != 0 {
165
173
return nil , apierrors .NewInvalid (
166
174
schema.GroupKind {Group : "core.openstack.org" , Kind : "OpenStackControlPlane" },
@@ -1122,3 +1130,28 @@ func (r *OpenStackControlPlane) ValidateTopology(basePath *field.Path) *field.Er
1122
1130
}
1123
1131
return nil
1124
1132
}
1133
+
1134
+ // ValidateNotificationsBusInstance - returns an error if the notificationsBusInstance
1135
+ // parameter is not valid.
1136
+ // - nil or empty string must be raised as an error
1137
+ // - when notificationsBusInstance does not point to an existing RabbitMQ instance
1138
+ func (r * OpenStackControlPlane ) ValidateNotificationsBusInstance (basePath * field.Path ) * field.Error {
1139
+ notificationsField := basePath .Child ("notificationsBusInstance" )
1140
+ // no notificationsBusInstance field set, nothing to validate here
1141
+ if r .Spec .NotificationsBusInstance == nil {
1142
+ return nil
1143
+ }
1144
+ // When NotificationsBusInstance is set, fail if it is an empty string
1145
+ if * r .Spec .NotificationsBusInstance == "" {
1146
+ return field .Invalid (notificationsField , * r .Spec .NotificationsBusInstance , "notificationsBusInstance is not a valid string" )
1147
+ }
1148
+ // NotificationsBusInstance is set and must be equal to an existing
1149
+ // deployed rabbitmq instance, otherwise we should fail because it
1150
+ // does not represent a valid string
1151
+ for k := range (* r .Spec .Rabbitmq .Templates ) {
1152
+ if * r .Spec .NotificationsBusInstance == k {
1153
+ return nil
1154
+ }
1155
+ }
1156
+ return field .Invalid (notificationsField , * r .Spec .NotificationsBusInstance , "notificationsBusInstance must match an existing RabbitMQ instance name" )
1157
+ }
0 commit comments