@@ -35,7 +35,6 @@ import (
3535 "k8s.io/apimachinery/pkg/runtime/schema"
3636 "k8s.io/apimachinery/pkg/util/validation/field"
3737 "k8s.io/utils/ptr"
38- ctrl "sigs.k8s.io/controller-runtime"
3938 logf "sigs.k8s.io/controller-runtime/pkg/log"
4039 "sigs.k8s.io/controller-runtime/pkg/webhook"
4140 "sigs.k8s.io/controller-runtime/pkg/webhook/admission"
@@ -60,15 +59,6 @@ func SetupNovaDefaults(defaults NovaDefaults) {
6059 novalog .Info ("Nova defaults initialized" , "defaults" , defaults )
6160}
6261
63- // SetupWebhookWithManager sets up the webhook with the Manager
64- func (r * Nova ) SetupWebhookWithManager (mgr ctrl.Manager ) error {
65- return ctrl .NewWebhookManagedBy (mgr ).
66- For (r ).
67- Complete ()
68- }
69-
70- //+kubebuilder:webhook:path=/mutate-nova-openstack-org-v1beta1-nova,mutating=true,failurePolicy=fail,sideEffects=None,groups=nova.openstack.org,resources=nova,verbs=create;update,versions=v1beta1,name=mnova.kb.io,admissionReviewVersions=v1
71-
7262var _ webhook.Defaulter = & Nova {}
7363
7464// Default implements webhook.Defaulter so a webhook will be registered for the type
@@ -121,15 +111,13 @@ func (spec *NovaSpecCore) Default() {
121111 }
122112}
123113
124- // NOTE: change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
125- //+kubebuilder:webhook:path=/validate-nova-openstack-org-v1beta1-nova,mutating=false,failurePolicy=fail,sideEffects=None,groups=nova.openstack.org,resources=nova,verbs=create;update,versions=v1beta1,name=vnova.kb.io,admissionReviewVersions=v1
126-
127114var _ webhook.Validator = & Nova {}
128115
129- func (r * NovaSpecCore ) ValidateCellTemplates (basePath * field.Path , namespace string ) field.ErrorList {
116+ // ValidateCellTemplates validates cell templates configuration
117+ func (spec * NovaSpecCore ) ValidateCellTemplates (basePath * field.Path , namespace string ) field.ErrorList {
130118 var errors field.ErrorList
131119
132- if _ , ok := r .CellTemplates [Cell0Name ]; ! ok {
120+ if _ , ok := spec .CellTemplates [Cell0Name ]; ! ok {
133121 errors = append (
134122 errors ,
135123 field .Required (basePath .Child ("cellTemplates" ),
@@ -139,7 +127,7 @@ func (r *NovaSpecCore) ValidateCellTemplates(basePath *field.Path, namespace str
139127
140128 cellMessageBusNames := make (map [string ]string )
141129
142- for name , cell := range r .CellTemplates {
130+ for name , cell := range spec .CellTemplates {
143131 cellPath := basePath .Child ("cellTemplates" ).Key (name )
144132 errors = append (
145133 errors ,
@@ -163,7 +151,7 @@ func (r *NovaSpecCore) ValidateCellTemplates(basePath *field.Path, namespace str
163151
164152 cellMessageBusNames [cell .CellMessageBusInstance ] = name
165153 }
166- if * cell .MetadataServiceTemplate .Enabled && * r .MetadataServiceTemplate .Enabled {
154+ if * cell .MetadataServiceTemplate .Enabled && * spec .MetadataServiceTemplate .Enabled {
167155 errors = append (
168156 errors ,
169157 field .Invalid (
@@ -239,67 +227,67 @@ func (r *NovaSpecCore) ValidateCellTemplates(basePath *field.Path, namespace str
239227}
240228
241229// ValidateAPIServiceTemplate -
242- func (r * NovaSpecCore ) ValidateAPIServiceTemplate (basePath * field.Path , namespace string ) field.ErrorList {
230+ func (spec * NovaSpecCore ) ValidateAPIServiceTemplate (basePath * field.Path , namespace string ) field.ErrorList {
243231 errors := field.ErrorList {}
244232
245233 // validate the service override key is valid
246234 errors = append (errors ,
247235 service .ValidateRoutedOverrides (
248236 basePath .Child ("apiServiceTemplate" ).Child ("override" ).Child ("service" ),
249- r .APIServiceTemplate .Override .Service )... )
237+ spec .APIServiceTemplate .Override .Service )... )
250238
251239 errors = append (errors ,
252240 ValidateAPIDefaultConfigOverwrite (
253241 basePath .Child ("apiServiceTemplate" ).Child ("defaultConfigOverwrite" ),
254- r .APIServiceTemplate .DefaultConfigOverwrite )... )
242+ spec .APIServiceTemplate .DefaultConfigOverwrite )... )
255243
256244 errors = append (errors ,
257- r .APIServiceTemplate .ValidateTopology (
245+ spec .APIServiceTemplate .ValidateTopology (
258246 basePath .Child ("apiServiceTemplate" ),
259247 namespace )... )
260248
261249 return errors
262250}
263251
264252// ValidateSchedulerServiceTemplate -
265- func (r * NovaSpecCore ) ValidateSchedulerServiceTemplate (basePath * field.Path , namespace string ) field.ErrorList {
253+ func (spec * NovaSpecCore ) ValidateSchedulerServiceTemplate (basePath * field.Path , namespace string ) field.ErrorList {
266254 errors := field.ErrorList {}
267255 // validate the referenced TopologyRef
268256 errors = append (errors ,
269- r .SchedulerServiceTemplate .ValidateTopology (
257+ spec .SchedulerServiceTemplate .ValidateTopology (
270258 basePath .Child ("schedulerServiceTemplate" ),
271259 namespace )... )
272260 return errors
273261}
274262
275263// ValidateCreate validates the NovaSpec during the webhook invocation.
276- func (r * NovaSpec ) ValidateCreate (basePath * field.Path , namespace string ) field.ErrorList {
277- return r .NovaSpecCore .ValidateCreate (basePath , namespace )
264+ func (spec * NovaSpec ) ValidateCreate (basePath * field.Path , namespace string ) field.ErrorList {
265+ return spec .NovaSpecCore .ValidateCreate (basePath , namespace )
278266}
279267
280268// ValidateCreate validates the NovaSpecCore during the webhook invocation. It is
281269// expected to be called by the validation webhook in the higher level meta
282270// operator
283- func (r * NovaSpecCore ) ValidateCreate (basePath * field.Path , namespace string ) field.ErrorList {
284- errors := r .ValidateCellTemplates (basePath , namespace )
285- errors = append (errors , r .ValidateAPIServiceTemplate (basePath , namespace )... )
286- errors = append (errors , r .ValidateSchedulerServiceTemplate (basePath , namespace )... )
271+ func (spec * NovaSpecCore ) ValidateCreate (basePath * field.Path , namespace string ) field.ErrorList {
272+ errors := spec .ValidateCellTemplates (basePath , namespace )
273+ errors = append (errors , spec .ValidateAPIServiceTemplate (basePath , namespace )... )
274+ errors = append (errors , spec .ValidateSchedulerServiceTemplate (basePath , namespace )... )
287275
288276 // validate TopologyRef override for top-level MetadataServiceTemplate
289277 errors = append (errors ,
290- r .MetadataServiceTemplate .ValidateTopology (
278+ spec .MetadataServiceTemplate .ValidateTopology (
291279 basePath .Child ("metadataServiceTemplate" ),
292280 namespace )... )
293281
294282 errors = append (
295283 errors ,
296- r .MetadataServiceTemplate .ValidateDefaultConfigOverwrite (
284+ spec .MetadataServiceTemplate .ValidateDefaultConfigOverwrite (
297285 basePath .Child ("metadataServiceTemplate" ))... )
298286
299287 // validate top-level topology
300288 errors = append (errors ,
301289 topologyv1 .ValidateTopologyRef (
302- r .TopologyRef , * basePath .Child ("topologyRef" ), namespace )... )
290+ spec .TopologyRef , * basePath .Child ("topologyRef" ), namespace )... )
303291
304292 return errors
305293}
@@ -319,31 +307,31 @@ func (r *Nova) ValidateCreate() (admission.Warnings, error) {
319307}
320308
321309// ValidateUpdate validates the NovaSpec during the webhook invocation.
322- func (r * NovaSpec ) ValidateUpdate (old NovaSpec , basePath * field.Path , namespace string ) field.ErrorList {
323- return r .NovaSpecCore .ValidateUpdate (old .NovaSpecCore , basePath , namespace )
310+ func (spec * NovaSpec ) ValidateUpdate (old NovaSpec , basePath * field.Path , namespace string ) field.ErrorList {
311+ return spec .NovaSpecCore .ValidateUpdate (old .NovaSpecCore , basePath , namespace )
324312}
325313
326314// ValidateUpdate validates the NovaSpecCore during the webhook invocation. It is
327315// expected to be called by the validation webhook in the higher level meta
328316// operator
329- func (r * NovaSpecCore ) ValidateUpdate (old NovaSpecCore , basePath * field.Path , namespace string ) field.ErrorList {
330- errors := r .ValidateCellTemplates (basePath , namespace )
317+ func (spec * NovaSpecCore ) ValidateUpdate (old NovaSpecCore , basePath * field.Path , namespace string ) field.ErrorList {
318+ errors := spec .ValidateCellTemplates (basePath , namespace )
331319 // Validate top-level TopologyRef
332320 errors = append (errors , topologyv1 .ValidateTopologyRef (
333- r .TopologyRef , * basePath .Child ("topologyRef" ), namespace )... )
321+ spec .TopologyRef , * basePath .Child ("topologyRef" ), namespace )... )
334322
335- errors = append (errors , r .ValidateAPIServiceTemplate (basePath , namespace )... )
336- errors = append (errors , r .ValidateSchedulerServiceTemplate (basePath , namespace )... )
323+ errors = append (errors , spec .ValidateAPIServiceTemplate (basePath , namespace )... )
324+ errors = append (errors , spec .ValidateSchedulerServiceTemplate (basePath , namespace )... )
337325
338326 // validate TopologyRef override for top-level MetadataServiceTemplate
339327 errors = append (errors ,
340- r .MetadataServiceTemplate .ValidateTopology (
328+ spec .MetadataServiceTemplate .ValidateTopology (
341329 basePath .Child ("metadataServiceTemplate" ),
342330 namespace )... )
343331
344332 errors = append (
345333 errors ,
346- r .MetadataServiceTemplate .ValidateDefaultConfigOverwrite (
334+ spec .MetadataServiceTemplate .ValidateDefaultConfigOverwrite (
347335 basePath .Child ("metadataServiceTemplate" ))... )
348336
349337 return errors
@@ -379,7 +367,7 @@ func (r *Nova) ValidateDelete() (admission.Warnings, error) {
379367
380368// SetDefaultRouteAnnotations sets HAProxy timeout values of the route
381369// NOTE: it is used by ctlplane webhook on openstack-operator
382- func (r * NovaSpecCore ) SetDefaultRouteAnnotations (annotations map [string ]string ) {
370+ func (spec * NovaSpecCore ) SetDefaultRouteAnnotations (annotations map [string ]string ) {
383371 const haProxyAnno = "haproxy.router.openshift.io/timeout"
384372 // Use a custom annotation to flag when the operator has set the default HAProxy timeout
385373 // With the annotation func determines when to overwrite existing HAProxy timeout with the APITimeout
@@ -399,7 +387,7 @@ func (r *NovaSpecCore) SetDefaultRouteAnnotations(annotations map[string]string)
399387 return
400388 }
401389
402- timeout := fmt .Sprintf ("%ds" , r .APITimeout )
390+ timeout := fmt .Sprintf ("%ds" , spec .APITimeout )
403391 annotations [novaAnno ] = timeout
404392 annotations [haProxyAnno ] = timeout
405393}
0 commit comments