Skip to content

Commit 41a7ff7

Browse files
Merge pull request #308 from fmount/topologyref_webhook
Complete webhook validation for topology references
2 parents 1ec26c3 + b5ed36d commit 41a7ff7

File tree

7 files changed

+169
-154
lines changed

7 files changed

+169
-154
lines changed

api/go.mod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ go 1.21
44

55
require (
66
github.com/onsi/ginkgo/v2 v2.20.1
7-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250228124213-cd63da392f97
7+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250315090821-34e570d2d5fb
88
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20250228124213-cd63da392f97
9-
k8s.io/api v0.29.14
10-
k8s.io/apimachinery v0.29.14
11-
k8s.io/client-go v0.29.14
9+
k8s.io/api v0.29.15
10+
k8s.io/apimachinery v0.29.15
11+
k8s.io/client-go v0.29.15
1212
sigs.k8s.io/controller-runtime v0.17.6
1313
)
1414

1515
require (
1616
github.com/onsi/gomega v1.34.1
17-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.0
17+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250319162810-463dd75a4cc4
1818
)
1919

2020
require (
@@ -67,8 +67,8 @@ require (
6767
gopkg.in/inf.v0 v0.9.1 // indirect
6868
gopkg.in/yaml.v2 v2.4.0 // indirect
6969
gopkg.in/yaml.v3 v3.0.1 // indirect
70-
k8s.io/apiextensions-apiserver v0.29.14 // indirect
71-
k8s.io/component-base v0.29.14 // indirect
70+
k8s.io/apiextensions-apiserver v0.29.15 // indirect
71+
k8s.io/component-base v0.29.15 // indirect
7272
k8s.io/klog/v2 v2.120.1 // indirect
7373
k8s.io/kube-openapi v0.0.0-20240322212309-b815d8309940 // indirect
7474
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect

api/go.sum

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ github.com/onsi/ginkgo/v2 v2.20.1 h1:YlVIbqct+ZmnEph770q9Q7NVAz4wwIiVNahee6JyUzo
7272
github.com/onsi/ginkgo/v2 v2.20.1/go.mod h1:lG9ey2Z29hR41WMVthyJBGUBcBhGOtoPF2VFMvBXFCI=
7373
github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
7474
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
75-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.0 h1:28i9Yc3UAdQK8VNzk0ubwq4n+qLuhD0nk6/7iHgD9us=
76-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.0/go.mod h1:JgcmYJyyMKfArK8ulZnbls0L01qt8Dq6s5LH8TZH63A=
77-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250228124213-cd63da392f97 h1:3LC66vrXJzGMV/eCdvImosOEL2Cgc2KFJIm2YhfTG3w=
78-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250228124213-cd63da392f97/go.mod h1:rgpcv2tLD+/vudXx/gpIQSTuRpk4GOxHx84xwfvQalM=
75+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250319162810-463dd75a4cc4 h1:wb2zsr9x9LantNLN/9dmYM42c3yLq3QuzsoOlGpDUxM=
76+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250319162810-463dd75a4cc4/go.mod h1:n5DV/lGE9DHryAJ+JLJSgUXI2QHTj+aN4KoeSNC3PfU=
77+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250315090821-34e570d2d5fb h1:UAFYEHnbyhO0+yymquFmIqxc9QGji9mzreuYrDS1Ev4=
78+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250315090821-34e570d2d5fb/go.mod h1:1CtBP0MQffdjE6buOv5jP2rB3+h7WH0a11lcyrpmxOk=
7979
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20250228124213-cd63da392f97 h1:xQ7/UNSPVRzwQq7wYG9i87dCCQztgmz1kqn2sy6HhlQ=
8080
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20250228124213-cd63da392f97/go.mod h1:u7Zqmyt1WB96KSz8apYltrZV9xlL0tTVYwOk9+6G57k=
8181
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
@@ -180,16 +180,16 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
180180
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
181181
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
182182
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
183-
k8s.io/api v0.29.14 h1:JWFh5ufowH3Y6tCgEzY3URVJHb27f0tEDEej0nCjWDw=
184-
k8s.io/api v0.29.14/go.mod h1:IV8YqKxMm8JGLBLlHM13Npn5lCITH10XYipWEW+YEOQ=
185-
k8s.io/apiextensions-apiserver v0.29.14 h1:gw9WXrZJPu5kpI1UC+Wf8BVe9PWwRUB/UZXU8VzBsq4=
186-
k8s.io/apiextensions-apiserver v0.29.14/go.mod h1:TJ51W+HKW2XqTtAsEFOz1/OohsMtekbKaTXh8ldioL4=
187-
k8s.io/apimachinery v0.29.14 h1:IDhwnGNCp836SLOwW1SoEfFNV77wxIklhxeAHX9vmSo=
188-
k8s.io/apimachinery v0.29.14/go.mod h1:i3FJVwhvSp/6n8Fl4K97PJEP8C+MM+aoDq4+ZJBf70Y=
189-
k8s.io/client-go v0.29.14 h1:OSnzZ9DClaFRgl3zMAY2kGZhNjdGJkEb+RDz+MW2h6k=
190-
k8s.io/client-go v0.29.14/go.mod h1:XtZt5n5UxKfPJ+sCoTPcEavWgZbLFFxMnAFFRQGK1RY=
191-
k8s.io/component-base v0.29.14 h1:SF1DWN7bc2VloJ/ysegGoi/aHnopEo81aw9CslhqXIw=
192-
k8s.io/component-base v0.29.14/go.mod h1:FoK1PHhFTaEQVvQLw29/Uyfd8Ug0qUKHrUcXIXJ1VxI=
183+
k8s.io/api v0.29.15 h1:QxPcAheYujeBwkdiE0vMyKkAtqUq5YNyXVqimT+me44=
184+
k8s.io/api v0.29.15/go.mod h1:16duIp2ez6GiLPq1g8XtZNIkw6hJpIitpxZSvv0dZ6E=
185+
k8s.io/apiextensions-apiserver v0.29.15 h1:XI5axgsWqMlIIgpHbcz5vPjk06i3ibHv5FUdSfdtQLU=
186+
k8s.io/apiextensions-apiserver v0.29.15/go.mod h1:6ZU61z32I8WUwbBTPIANUesTj5G40sZek0ojmeoMJI8=
187+
k8s.io/apimachinery v0.29.15 h1:aLc0wghElkdnTO7TMVTxTrifoXah1lqRL8s6szDHGbg=
188+
k8s.io/apimachinery v0.29.15/go.mod h1:i3FJVwhvSp/6n8Fl4K97PJEP8C+MM+aoDq4+ZJBf70Y=
189+
k8s.io/client-go v0.29.15 h1:zCBOXKCtz9Hl8boKUGs8zbtZEP6pc7O8Ov3ma+gnS6o=
190+
k8s.io/client-go v0.29.15/go.mod h1:xPy0D3p4sonPhZhI3QoYo4m7oLKoPjFf4vYF9oxoxNM=
191+
k8s.io/component-base v0.29.15 h1:CvmXXTDyk43FDaiJ/Rp+yWFjw6hkUI2t7mIJUrK5j00=
192+
k8s.io/component-base v0.29.15/go.mod h1:jH/sbuvmXew2Fz2iIKNMeNw8o/d1KR9tAg6uekQKnVk=
193193
k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw=
194194
k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
195195
k8s.io/kube-openapi v0.0.0-20240322212309-b815d8309940 h1:qVoMaQV5t62UUvHe16Q3eb2c5HPzLHYzsi0Tu/xLndo=

api/v1beta1/common_types.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package v1beta1
1919
import (
2020
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
2121
corev1 "k8s.io/api/core/v1"
22+
"k8s.io/apimachinery/pkg/util/validation/field"
2223
)
2324

2425
const (
@@ -140,3 +141,15 @@ type PasswordSelector struct {
140141
// Service - Selector to get the designate service password from the Secret
141142
Service string `json:"service"`
142143
}
144+
145+
// ValidateTopology -
146+
func (instance *DesignateServiceTemplateCore) ValidateTopology(
147+
basePath *field.Path,
148+
namespace string,
149+
) field.ErrorList {
150+
var allErrs field.ErrorList
151+
allErrs = append(allErrs, topologyv1.ValidateTopologyRef(
152+
instance.TopologyRef,
153+
*basePath.Child("topologyRef"), namespace)...)
154+
return allErrs
155+
}

api/v1beta1/designate_webhook.go

Lines changed: 46 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

go.mod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ require (
1111
github.com/onsi/ginkgo/v2 v2.20.1
1212
github.com/onsi/gomega v1.34.1
1313
github.com/openstack-k8s-operators/designate-operator/api v0.1.1-0.20240807132522-6c2eca7c6bbb
14-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.0
14+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250319162810-463dd75a4cc4
1515
github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20250309111939-0605fce19482
16-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250228124213-cd63da392f97
16+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250315090821-34e570d2d5fb
1717
github.com/openstack-k8s-operators/lib-common/modules/test v0.5.1-0.20250228124213-cd63da392f97
1818
github.com/openstack-k8s-operators/mariadb-operator/api v0.6.0
1919
gopkg.in/yaml.v2 v2.4.0
20-
k8s.io/api v0.29.14
21-
k8s.io/apimachinery v0.29.14
22-
k8s.io/client-go v0.29.14
20+
k8s.io/api v0.29.15
21+
k8s.io/apimachinery v0.29.15
22+
k8s.io/client-go v0.29.15
2323
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
2424
sigs.k8s.io/controller-runtime v0.17.6
2525
)
@@ -81,8 +81,8 @@ require (
8181
google.golang.org/protobuf v1.34.1 // indirect
8282
gopkg.in/inf.v0 v0.9.1 // indirect
8383
gopkg.in/yaml.v3 v3.0.1 // indirect
84-
k8s.io/apiextensions-apiserver v0.29.14 // indirect
85-
k8s.io/component-base v0.29.14 // indirect
84+
k8s.io/apiextensions-apiserver v0.29.15 // indirect
85+
k8s.io/component-base v0.29.15 // indirect
8686
k8s.io/klog/v2 v2.120.1 // indirect
8787
k8s.io/kube-openapi v0.0.0-20240322212309-b815d8309940 // indirect
8888
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect

0 commit comments

Comments
 (0)