@@ -124,8 +124,7 @@ func (r *Designate) ValidateCreate() (admission.Warnings, error) {
124124 var allErrs field.ErrorList
125125 basePath := field .NewPath ("spec" )
126126
127- allErrs = r .Spec .ValidateDesignateTopology (basePath , r .Namespace )
128- if err := r .Spec .ValidateCreate (basePath ); err != nil {
127+ if err := r .Spec .ValidateCreate (basePath , r .Namespace ); err != nil {
129128 allErrs = append (allErrs , err ... )
130129 }
131130
@@ -140,9 +139,11 @@ func (r *Designate) ValidateCreate() (admission.Warnings, error) {
140139
141140// ValidateCreate - Exported function wrapping non-exported validate functions,
142141// this function can be called externally to validate an designate spec.
143- func (r * DesignateSpec ) ValidateCreate (basePath * field.Path ) field.ErrorList {
142+ func (r * DesignateSpec ) ValidateCreate (basePath * field.Path , namespace string ) field.ErrorList {
144143 var allErrs field.ErrorList
145144
145+ allErrs = r .ValidateDesignateTopology (basePath , namespace )
146+
146147 // validate the service override key is valid
147148 allErrs = append (allErrs , service .ValidateRoutedOverrides (
148149 basePath .Child ("designateAPI" ).Child ("override" ).Child ("service" ),
@@ -151,9 +152,11 @@ func (r *DesignateSpec) ValidateCreate(basePath *field.Path) field.ErrorList {
151152 return allErrs
152153}
153154
154- func (r * DesignateSpecCore ) ValidateCreate (basePath * field.Path ) field.ErrorList {
155+ func (r * DesignateSpecCore ) ValidateCreate (basePath * field.Path , namespace string ) field.ErrorList {
155156 var allErrs field.ErrorList
156157
158+ allErrs = r .ValidateDesignateTopology (basePath , namespace )
159+
157160 // validate the service override key is valid
158161 allErrs = append (allErrs , service .ValidateRoutedOverrides (
159162 basePath .Child ("designateAPI" ).Child ("override" ).Child ("service" ),
@@ -174,8 +177,7 @@ func (r *Designate) ValidateUpdate(old runtime.Object) (admission.Warnings, erro
174177 var allErrs field.ErrorList
175178 basePath := field .NewPath ("spec" )
176179
177- allErrs = r .Spec .ValidateDesignateTopology (basePath , r .Namespace )
178- if err := r .Spec .ValidateUpdate (oldDesignate .Spec , basePath ); err != nil {
180+ if err := r .Spec .ValidateUpdate (oldDesignate .Spec , basePath , r .Namespace ); err != nil {
179181 allErrs = append (allErrs , err ... )
180182 }
181183
@@ -190,9 +192,10 @@ func (r *Designate) ValidateUpdate(old runtime.Object) (admission.Warnings, erro
190192
191193// ValidateUpdate - Exported function wrapping non-exported validate functions,
192194// this function can be called externally to validate an designate spec.
193- func (r * DesignateSpec ) ValidateUpdate (old DesignateSpec , basePath * field.Path ) field.ErrorList {
195+ func (r * DesignateSpec ) ValidateUpdate (old DesignateSpec , basePath * field.Path , namespace string ) field.ErrorList {
194196 var allErrs field.ErrorList
195197
198+ allErrs = r .ValidateDesignateTopology (basePath , namespace )
196199 // validate the service override key is valid
197200 allErrs = append (allErrs , service .ValidateRoutedOverrides (
198201 basePath .Child ("designateAPI" ).Child ("override" ).Child ("service" ),
@@ -201,9 +204,10 @@ func (r *DesignateSpec) ValidateUpdate(old DesignateSpec, basePath *field.Path)
201204 return allErrs
202205}
203206
204- func (r * DesignateSpecCore ) ValidateUpdate (old DesignateSpecCore , basePath * field.Path ) field.ErrorList {
207+ func (r * DesignateSpecCore ) ValidateUpdate (old DesignateSpecCore , basePath * field.Path , namespace string ) field.ErrorList {
205208 var allErrs field.ErrorList
206209
210+ allErrs = r .ValidateDesignateTopology (basePath , namespace )
207211 // validate the service override key is valid
208212 allErrs = append (allErrs , service .ValidateRoutedOverrides (
209213 basePath .Child ("designateAPI" ).Child ("override" ).Child ("service" ),
@@ -328,3 +332,80 @@ func (spec *DesignateSpec) ValidateDesignateTopology(basePath *field.Path, names
328332
329333 return allErrs
330334}
335+
336+ // ValidateDesignateTopology - Returns an ErrorList if the Topology is referenced
337+ // on a different namespace
338+ func (spec * DesignateSpecCore ) ValidateDesignateTopology (basePath * field.Path , namespace string ) field.ErrorList {
339+ var allErrs field.ErrorList
340+
341+ // When a TopologyRef CR is referenced, fail if a different Namespace is
342+ // 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+ }
348+
349+ // When a TopologyRef CR is referenced with an override to DesignateAPI, fail
350+ // 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+ }
356+
357+ // When a TopologyRef CR is referenced with an override to DesignateBackendbind9
358+ // 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+ }
364+
365+ // When a TopologyRef CR is referenced with an override to an instance of
366+ // DesignateCentral, fail if a different Namespace is referenced because not
367+ // 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+ }
373+
374+ // When a TopologyRef CR is referenced with an override to an instance of
375+ // DesignateMDNS, fail if a different Namespace is referenced because not
376+ // 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+ }
382+
383+ // When a TopologyRef CR is referenced with an override to an instance of
384+ // DesignateProducer, fail if a different Namespace is referenced because not
385+ // 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+ }
391+
392+ // When a TopologyRef CR is referenced with an override to an instance of
393+ // DesignateUnbound, fail if a different Namespace is referenced because not
394+ // 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+ }
400+
401+ // When a TopologyRef CR is referenced with an override to an instance of
402+ // DesignateWorker, fail if a different Namespace is referenced because not
403+ // 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+ }
409+
410+ return allErrs
411+ }
0 commit comments