Skip to content

Commit 32c9f26

Browse files
committed
Update SpecCore webhook interface
This patch updates the SpecCore webhook interface to accept the Namespace as parameter. This change ensures that we properly validate the referenced topology from openstack-operator, rejecting requests with a different namespace. Signed-off-by: Francesco Pantano <fpantano@redhat.com>
1 parent ae9a664 commit 32c9f26

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

api/v1beta1/ironic_webhook.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ func (r *Ironic) ValidateCreate() (admission.Warnings, error) {
106106
var allErrs field.ErrorList
107107
basePath := field.NewPath("spec")
108108

109-
allErrs = r.Spec.ValidateIronicTopology(basePath, r.Namespace)
110-
if err := r.Spec.ValidateCreate(basePath); err != nil {
109+
if err := r.Spec.ValidateCreate(basePath, r.Namespace); err != nil {
111110
allErrs = append(allErrs, err...)
112111
}
113112

@@ -122,11 +121,11 @@ func (r *Ironic) ValidateCreate() (admission.Warnings, error) {
122121

123122
// ValidateCreate - Exported function wrapping non-exported validate functions,
124123
// this function can be called externally to validate an ironic spec.
125-
func (spec *IronicSpec) ValidateCreate(basePath *field.Path) field.ErrorList {
126-
return spec.IronicSpecCore.ValidateCreate(basePath)
124+
func (spec *IronicSpec) ValidateCreate(basePath *field.Path, namespace string) field.ErrorList {
125+
return spec.IronicSpecCore.ValidateCreate(basePath, namespace)
127126
}
128127

129-
func (spec *IronicSpecCore) ValidateCreate(basePath *field.Path) field.ErrorList {
128+
func (spec *IronicSpecCore) ValidateCreate(basePath *field.Path, namespace string) field.ErrorList {
130129
var allErrs field.ErrorList
131130

132131
if err := validateRPCTransport(spec, basePath); err != nil {
@@ -157,6 +156,7 @@ func (spec *IronicSpecCore) ValidateCreate(basePath *field.Path) field.ErrorList
157156
allErrs = append(allErrs, err...)
158157
}
159158

159+
allErrs = append(allErrs, spec.ValidateIronicTopology(basePath, namespace)...)
160160
return allErrs
161161
}
162162

@@ -172,8 +172,7 @@ func (r *Ironic) ValidateUpdate(old runtime.Object) (admission.Warnings, error)
172172
var allErrs field.ErrorList
173173
basePath := field.NewPath("spec")
174174

175-
allErrs = r.Spec.ValidateIronicTopology(basePath, r.Namespace)
176-
if err := r.Spec.ValidateUpdate(oldIronic.Spec, basePath); err != nil {
175+
if err := r.Spec.ValidateUpdate(oldIronic.Spec, basePath, r.Namespace); err != nil {
177176
allErrs = append(allErrs, err...)
178177
}
179178

@@ -188,11 +187,11 @@ func (r *Ironic) ValidateUpdate(old runtime.Object) (admission.Warnings, error)
188187

189188
// ValidateUpdate - Exported function wrapping non-exported validate functions,
190189
// this function can be called externally to validate an ironic spec.
191-
func (spec *IronicSpec) ValidateUpdate(old IronicSpec, basePath *field.Path) field.ErrorList {
192-
return spec.IronicSpecCore.ValidateUpdate(old.IronicSpecCore, basePath)
190+
func (spec *IronicSpec) ValidateUpdate(old IronicSpec, basePath *field.Path, namespace string) field.ErrorList {
191+
return spec.IronicSpecCore.ValidateUpdate(old.IronicSpecCore, basePath, namespace)
193192
}
194193

195-
func (spec *IronicSpecCore) ValidateUpdate(old IronicSpecCore, basePath *field.Path) field.ErrorList {
194+
func (spec *IronicSpecCore) ValidateUpdate(old IronicSpecCore, basePath *field.Path, namespace string) field.ErrorList {
196195
var allErrs field.ErrorList
197196

198197
if err := validateRPCTransport(spec, basePath); err != nil {
@@ -223,6 +222,7 @@ func (spec *IronicSpecCore) ValidateUpdate(old IronicSpecCore, basePath *field.P
223222
allErrs = append(allErrs, err...)
224223
}
225224

225+
allErrs = append(allErrs, spec.ValidateIronicTopology(basePath, namespace)...)
226226
return allErrs
227227
}
228228

@@ -607,7 +607,7 @@ func (spec *IronicSpecCore) Default() {
607607

608608
// ValidateIronicTopology - Returns an ErrorList if the Topology is referenced
609609
// on a different namespace
610-
func (spec *IronicSpec) ValidateIronicTopology(basePath *field.Path, namespace string) field.ErrorList {
610+
func (spec *IronicSpecCore) ValidateIronicTopology(basePath *field.Path, namespace string) field.ErrorList {
611611
var allErrs field.ErrorList
612612

613613
// When a TopologyRef CR is referenced, fail if a different Namespace is

0 commit comments

Comments
 (0)