@@ -263,72 +263,55 @@ func (spec *DesignateSpec) ValidateDesignateTopology(basePath *field.Path, names
263263
264264 // When a TopologyRef CR is referenced, fail if a different Namespace is
265265 // referenced because is not supported
266- if spec .TopologyRef != nil {
267- if err := topologyv1 .ValidateTopologyNamespace (spec .TopologyRef .Namespace , * basePath , namespace ); err != nil {
268- allErrs = append (allErrs , err )
269- }
270- }
266+ allErrs = append (allErrs , topologyv1 .ValidateTopologyRef (
267+ spec .TopologyRef , * basePath .Child ("topologyRef" ), namespace )... )
271268
272269 // When a TopologyRef CR is referenced with an override to DesignateAPI, fail
273270 // if a different Namespace is referenced because not supported
274- if spec .DesignateAPI .TopologyRef != nil {
275- if err := topologyv1 .ValidateTopologyNamespace (spec .DesignateAPI .TopologyRef .Namespace , * basePath , namespace ); err != nil {
276- allErrs = append (allErrs , err )
277- }
278- }
271+ apiPath := basePath .Child ("designateAPI" )
272+ allErrs = append (allErrs ,
273+ spec .DesignateAPI .ValidateTopology (apiPath , namespace )... )
279274
280275 // When a TopologyRef CR is referenced with an override to DesignateBackendbind9
281276 // fail if a different Namespace is referenced because not supported
282- if spec .DesignateBackendbind9 .TopologyRef != nil {
283- if err := topologyv1 .ValidateTopologyNamespace (spec .DesignateBackendbind9 .TopologyRef .Namespace , * basePath , namespace ); err != nil {
284- allErrs = append (allErrs , err )
285- }
286- }
277+ bind9Path := basePath .Child ("designateBackendBind9" )
278+ allErrs = append (allErrs ,
279+ spec .DesignateBackendbind9 .ValidateTopology (bind9Path , namespace )... )
287280
288281 // When a TopologyRef CR is referenced with an override to an instance of
289282 // DesignateCentral, fail if a different Namespace is referenced because not
290283 // supported
291- if spec .DesignateCentral .TopologyRef != nil {
292- if err := topologyv1 .ValidateTopologyNamespace (spec .DesignateCentral .TopologyRef .Namespace , * basePath , namespace ); err != nil {
293- allErrs = append (allErrs , err )
294- }
295- }
284+ centralPath := basePath .Child ("designateCentral" )
285+ allErrs = append (allErrs ,
286+ spec .DesignateCentral .ValidateTopology (centralPath , namespace )... )
296287
297288 // When a TopologyRef CR is referenced with an override to an instance of
298289 // DesignateMDNS, fail if a different Namespace is referenced because not
299290 // supported
300- if spec .DesignateMdns .TopologyRef != nil {
301- if err := topologyv1 .ValidateTopologyNamespace (spec .DesignateMdns .TopologyRef .Namespace , * basePath , namespace ); err != nil {
302- allErrs = append (allErrs , err )
303- }
304- }
291+ mdnsPath := basePath .Child ("designateMdns" )
292+ allErrs = append (allErrs ,
293+ spec .DesignateMdns .ValidateTopology (mdnsPath , namespace )... )
305294
306295 // When a TopologyRef CR is referenced with an override to an instance of
307296 // DesignateProducer, fail if a different Namespace is referenced because not
308297 // supported
309- if spec .DesignateProducer .TopologyRef != nil {
310- if err := topologyv1 .ValidateTopologyNamespace (spec .DesignateProducer .TopologyRef .Namespace , * basePath , namespace ); err != nil {
311- allErrs = append (allErrs , err )
312- }
313- }
298+ prodPath := basePath .Child ("designateProducer" )
299+ allErrs = append (allErrs ,
300+ spec .DesignateProducer .ValidateTopology (prodPath , namespace )... )
314301
315302 // When a TopologyRef CR is referenced with an override to an instance of
316303 // DesignateUnbound, fail if a different Namespace is referenced because not
317304 // supported
318- if spec .DesignateUnbound .TopologyRef != nil {
319- if err := topologyv1 .ValidateTopologyNamespace (spec .DesignateUnbound .TopologyRef .Namespace , * basePath , namespace ); err != nil {
320- allErrs = append (allErrs , err )
321- }
322- }
305+ unboundPath := basePath .Child ("designateUnbound" )
306+ allErrs = append (allErrs ,
307+ spec .DesignateUnbound .ValidateTopology (unboundPath , namespace )... )
323308
324309 // When a TopologyRef CR is referenced with an override to an instance of
325310 // DesignateWorker, fail if a different Namespace is referenced because not
326311 // supported
327- if spec .DesignateWorker .TopologyRef != nil {
328- if err := topologyv1 .ValidateTopologyNamespace (spec .DesignateWorker .TopologyRef .Namespace , * basePath , namespace ); err != nil {
329- allErrs = append (allErrs , err )
330- }
331- }
312+ workerPath := basePath .Child ("designateWorker" )
313+ allErrs = append (allErrs ,
314+ spec .DesignateWorker .ValidateTopology (workerPath , namespace )... )
332315
333316 return allErrs
334317}
@@ -340,72 +323,55 @@ func (spec *DesignateSpecCore) ValidateDesignateTopology(basePath *field.Path, n
340323
341324 // When a TopologyRef CR is referenced, fail if a different Namespace is
342325 // referenced because is not supported
343- if spec .TopologyRef != nil {
344- if err := topologyv1 .ValidateTopologyNamespace (spec .TopologyRef .Namespace , * basePath , namespace ); err != nil {
345- allErrs = append (allErrs , err )
346- }
347- }
326+ allErrs = append (allErrs , topologyv1 .ValidateTopologyRef (
327+ spec .TopologyRef , * basePath .Child ("topologyRef" ), namespace )... )
348328
349329 // When a TopologyRef CR is referenced with an override to DesignateAPI, fail
350330 // if a different Namespace is referenced because not supported
351- if spec .DesignateAPI .TopologyRef != nil {
352- if err := topologyv1 .ValidateTopologyNamespace (spec .DesignateAPI .TopologyRef .Namespace , * basePath , namespace ); err != nil {
353- allErrs = append (allErrs , err )
354- }
355- }
331+ apiPath := basePath .Child ("designateAPI" )
332+ allErrs = append (allErrs ,
333+ spec .DesignateAPI .ValidateTopology (apiPath , namespace )... )
356334
357335 // When a TopologyRef CR is referenced with an override to DesignateBackendbind9
358336 // fail if a different Namespace is referenced because not supported
359- if spec .DesignateBackendbind9 .TopologyRef != nil {
360- if err := topologyv1 .ValidateTopologyNamespace (spec .DesignateBackendbind9 .TopologyRef .Namespace , * basePath , namespace ); err != nil {
361- allErrs = append (allErrs , err )
362- }
363- }
337+ bind9Path := basePath .Child ("designateBackendBind9" )
338+ allErrs = append (allErrs ,
339+ spec .DesignateBackendbind9 .ValidateTopology (bind9Path , namespace )... )
364340
365341 // When a TopologyRef CR is referenced with an override to an instance of
366342 // DesignateCentral, fail if a different Namespace is referenced because not
367343 // supported
368- if spec .DesignateCentral .TopologyRef != nil {
369- if err := topologyv1 .ValidateTopologyNamespace (spec .DesignateCentral .TopologyRef .Namespace , * basePath , namespace ); err != nil {
370- allErrs = append (allErrs , err )
371- }
372- }
344+ centralPath := basePath .Child ("designateCentral" )
345+ allErrs = append (allErrs ,
346+ spec .DesignateCentral .ValidateTopology (centralPath , namespace )... )
373347
374348 // When a TopologyRef CR is referenced with an override to an instance of
375349 // DesignateMDNS, fail if a different Namespace is referenced because not
376350 // supported
377- if spec .DesignateMdns .TopologyRef != nil {
378- if err := topologyv1 .ValidateTopologyNamespace (spec .DesignateMdns .TopologyRef .Namespace , * basePath , namespace ); err != nil {
379- allErrs = append (allErrs , err )
380- }
381- }
351+ mdnsPath := basePath .Child ("designateMdns" )
352+ allErrs = append (allErrs ,
353+ spec .DesignateMdns .ValidateTopology (mdnsPath , namespace )... )
382354
383355 // When a TopologyRef CR is referenced with an override to an instance of
384356 // DesignateProducer, fail if a different Namespace is referenced because not
385357 // supported
386- if spec .DesignateProducer .TopologyRef != nil {
387- if err := topologyv1 .ValidateTopologyNamespace (spec .DesignateProducer .TopologyRef .Namespace , * basePath , namespace ); err != nil {
388- allErrs = append (allErrs , err )
389- }
390- }
358+ prodPath := basePath .Child ("designateProducer" )
359+ allErrs = append (allErrs ,
360+ spec .DesignateProducer .ValidateTopology (prodPath , namespace )... )
391361
392362 // When a TopologyRef CR is referenced with an override to an instance of
393363 // DesignateUnbound, fail if a different Namespace is referenced because not
394364 // supported
395- if spec .DesignateUnbound .TopologyRef != nil {
396- if err := topologyv1 .ValidateTopologyNamespace (spec .DesignateUnbound .TopologyRef .Namespace , * basePath , namespace ); err != nil {
397- allErrs = append (allErrs , err )
398- }
399- }
365+ unboundPath := basePath .Child ("designateUnbound" )
366+ allErrs = append (allErrs ,
367+ spec .DesignateUnbound .ValidateTopology (unboundPath , namespace )... )
400368
401369 // When a TopologyRef CR is referenced with an override to an instance of
402370 // DesignateWorker, fail if a different Namespace is referenced because not
403371 // supported
404- if spec .DesignateWorker .TopologyRef != nil {
405- if err := topologyv1 .ValidateTopologyNamespace (spec .DesignateWorker .TopologyRef .Namespace , * basePath , namespace ); err != nil {
406- allErrs = append (allErrs , err )
407- }
408- }
372+ workerPath := basePath .Child ("designateWorker" )
373+ allErrs = append (allErrs ,
374+ spec .DesignateWorker .ValidateTopology (workerPath , namespace )... )
409375
410376 return allErrs
411377}
0 commit comments