@@ -85,24 +85,33 @@ var _ webhook.Validator = &OVNController{}
8585// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
8686func (r * OVNController ) ValidateCreate () (admission.Warnings , error ) {
8787 ovncontrollerlog .Info ("validate create" , "name" , r .Name )
88+ errors := field.ErrorList {}
89+
90+ errors = r .Spec .ValidateCreate (field .NewPath ("spec" ), r .Namespace )
91+ if len (errors ) != 0 {
92+ ovncontrollerlog .Info ("validation failed" , "name" , r .Name )
93+ return nil , apierrors .NewInvalid (
94+ schema.GroupKind {Group : "ovn.openstack.org" , Kind : "OVNController" },
95+ r .Name , errors )
96+ }
97+ return nil , nil
98+ }
8899
100+ func (r OVNControllerSpec ) ValidateCreate (basePath * field.Path , namespace string ) field.ErrorList {
101+ return r .OVNControllerSpecCore .ValidateCreate (basePath , namespace )
102+ }
103+
104+ func (r * OVNControllerSpecCore ) ValidateCreate (basePath * field.Path , namespace string ) field.ErrorList {
89105 errors := field.ErrorList {}
90- basePath := field .NewPath ("spec" )
91106
92107 // When a TopologyRef CR is referenced, fail if a different Namespace is
93108 // referenced because is not supported
94- if r .Spec . TopologyRef != nil {
95- if err := topologyv1 .ValidateTopologyNamespace (r .Spec . TopologyRef .Namespace , * basePath , r . Namespace ); err != nil {
109+ if r .TopologyRef != nil {
110+ if err := topologyv1 .ValidateTopologyNamespace (r .TopologyRef .Namespace , * basePath , namespace ); err != nil {
96111 errors = append (errors , err )
97112 }
98113 }
99- if len (errors ) != 0 {
100- return nil , apierrors .NewInvalid (
101- schema.GroupKind {Group : "manila.openstack.org" , Kind : "Manila" },
102- r .Name , errors )
103- }
104-
105- return nil , nil
114+ return errors
106115}
107116
108117// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
@@ -121,12 +130,29 @@ func (r *OVNController) ValidateUpdate(old runtime.Object) (admission.Warnings,
121130 }
122131 if len (errors ) != 0 {
123132 return nil , apierrors .NewInvalid (
124- schema.GroupKind {Group : "manila .openstack.org" , Kind : "Manila " },
133+ schema.GroupKind {Group : "ovn .openstack.org" , Kind : "OVNController " },
125134 r .Name , errors )
126135 }
127136 return nil , nil
128137}
129138
139+ func (r OVNControllerSpec ) ValidateUpdate (old OVNControllerSpec , basePath * field.Path , namespace string ) field.ErrorList {
140+ return r .OVNControllerSpecCore .ValidateCreate (basePath , namespace )
141+ }
142+
143+ func (r * OVNControllerSpecCore ) ValidateUpdate (old OVNControllerSpec , basePath * field.Path , namespace string ) field.ErrorList {
144+ errors := field.ErrorList {}
145+
146+ // When a TopologyRef CR is referenced, fail if a different Namespace is
147+ // referenced because is not supported
148+ if r .TopologyRef != nil {
149+ if err := topologyv1 .ValidateTopologyNamespace (r .TopologyRef .Namespace , * basePath , namespace ); err != nil {
150+ errors = append (errors , err )
151+ }
152+ }
153+ return errors
154+ }
155+
130156// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
131157func (r * OVNController ) ValidateDelete () (admission.Warnings , error ) {
132158 ovncontrollerlog .Info ("validate delete" , "name" , r .Name )
0 commit comments