diff --git a/api/go.mod b/api/go.mod index aa58d168..13af2a66 100644 --- a/api/go.mod +++ b/api/go.mod @@ -5,11 +5,11 @@ go 1.21 require ( github.com/onsi/ginkgo/v2 v2.20.1 github.com/onsi/gomega v1.34.1 - github.com/openstack-k8s-operators/infra-operator/apis v0.6.0 - github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250228124213-cd63da392f97 - k8s.io/api v0.29.14 - k8s.io/apimachinery v0.29.14 - k8s.io/client-go v0.29.14 + github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250319162810-463dd75a4cc4 + github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250315090821-34e570d2d5fb + k8s.io/api v0.29.15 + k8s.io/apimachinery v0.29.15 + k8s.io/client-go v0.29.15 k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 sigs.k8s.io/controller-runtime v0.17.6 ) @@ -65,8 +65,8 @@ require ( gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - k8s.io/apiextensions-apiserver v0.29.14 // indirect - k8s.io/component-base v0.29.14 // indirect + k8s.io/apiextensions-apiserver v0.29.15 // indirect + k8s.io/component-base v0.29.15 // indirect k8s.io/klog/v2 v2.120.1 // indirect k8s.io/kube-openapi v0.0.0-20240322212309-b815d8309940 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect diff --git a/api/go.sum b/api/go.sum index 2f363f12..0f76f672 100644 --- a/api/go.sum +++ b/api/go.sum @@ -74,10 +74,10 @@ github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k= github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY= github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 h1:J1wuGhVxpsHykZBa6Beb1gQ96Ptej9AE/BvwCBiRj1E= github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4= -github.com/openstack-k8s-operators/infra-operator/apis v0.6.0 h1:28i9Yc3UAdQK8VNzk0ubwq4n+qLuhD0nk6/7iHgD9us= -github.com/openstack-k8s-operators/infra-operator/apis v0.6.0/go.mod h1:JgcmYJyyMKfArK8ulZnbls0L01qt8Dq6s5LH8TZH63A= -github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250228124213-cd63da392f97 h1:3LC66vrXJzGMV/eCdvImosOEL2Cgc2KFJIm2YhfTG3w= -github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250228124213-cd63da392f97/go.mod h1:rgpcv2tLD+/vudXx/gpIQSTuRpk4GOxHx84xwfvQalM= +github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250319162810-463dd75a4cc4 h1:wb2zsr9x9LantNLN/9dmYM42c3yLq3QuzsoOlGpDUxM= +github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250319162810-463dd75a4cc4/go.mod h1:n5DV/lGE9DHryAJ+JLJSgUXI2QHTj+aN4KoeSNC3PfU= +github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250315090821-34e570d2d5fb h1:UAFYEHnbyhO0+yymquFmIqxc9QGji9mzreuYrDS1Ev4= +github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250315090821-34e570d2d5fb/go.mod h1:1CtBP0MQffdjE6buOv5jP2rB3+h7WH0a11lcyrpmxOk= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -180,16 +180,16 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -k8s.io/api v0.29.14 h1:JWFh5ufowH3Y6tCgEzY3URVJHb27f0tEDEej0nCjWDw= -k8s.io/api v0.29.14/go.mod h1:IV8YqKxMm8JGLBLlHM13Npn5lCITH10XYipWEW+YEOQ= -k8s.io/apiextensions-apiserver v0.29.14 h1:gw9WXrZJPu5kpI1UC+Wf8BVe9PWwRUB/UZXU8VzBsq4= -k8s.io/apiextensions-apiserver v0.29.14/go.mod h1:TJ51W+HKW2XqTtAsEFOz1/OohsMtekbKaTXh8ldioL4= -k8s.io/apimachinery v0.29.14 h1:IDhwnGNCp836SLOwW1SoEfFNV77wxIklhxeAHX9vmSo= -k8s.io/apimachinery v0.29.14/go.mod h1:i3FJVwhvSp/6n8Fl4K97PJEP8C+MM+aoDq4+ZJBf70Y= -k8s.io/client-go v0.29.14 h1:OSnzZ9DClaFRgl3zMAY2kGZhNjdGJkEb+RDz+MW2h6k= -k8s.io/client-go v0.29.14/go.mod h1:XtZt5n5UxKfPJ+sCoTPcEavWgZbLFFxMnAFFRQGK1RY= -k8s.io/component-base v0.29.14 h1:SF1DWN7bc2VloJ/ysegGoi/aHnopEo81aw9CslhqXIw= -k8s.io/component-base v0.29.14/go.mod h1:FoK1PHhFTaEQVvQLw29/Uyfd8Ug0qUKHrUcXIXJ1VxI= +k8s.io/api v0.29.15 h1:QxPcAheYujeBwkdiE0vMyKkAtqUq5YNyXVqimT+me44= +k8s.io/api v0.29.15/go.mod h1:16duIp2ez6GiLPq1g8XtZNIkw6hJpIitpxZSvv0dZ6E= +k8s.io/apiextensions-apiserver v0.29.15 h1:XI5axgsWqMlIIgpHbcz5vPjk06i3ibHv5FUdSfdtQLU= +k8s.io/apiextensions-apiserver v0.29.15/go.mod h1:6ZU61z32I8WUwbBTPIANUesTj5G40sZek0ojmeoMJI8= +k8s.io/apimachinery v0.29.15 h1:aLc0wghElkdnTO7TMVTxTrifoXah1lqRL8s6szDHGbg= +k8s.io/apimachinery v0.29.15/go.mod h1:i3FJVwhvSp/6n8Fl4K97PJEP8C+MM+aoDq4+ZJBf70Y= +k8s.io/client-go v0.29.15 h1:zCBOXKCtz9Hl8boKUGs8zbtZEP6pc7O8Ov3ma+gnS6o= +k8s.io/client-go v0.29.15/go.mod h1:xPy0D3p4sonPhZhI3QoYo4m7oLKoPjFf4vYF9oxoxNM= +k8s.io/component-base v0.29.15 h1:CvmXXTDyk43FDaiJ/Rp+yWFjw6hkUI2t7mIJUrK5j00= +k8s.io/component-base v0.29.15/go.mod h1:jH/sbuvmXew2Fz2iIKNMeNw8o/d1KR9tAg6uekQKnVk= k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw= k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= k8s.io/kube-openapi v0.0.0-20240322212309-b815d8309940 h1:qVoMaQV5t62UUvHe16Q3eb2c5HPzLHYzsi0Tu/xLndo= diff --git a/api/v1beta1/common_types.go b/api/v1beta1/common_types.go index 1c20422c..0023e545 100644 --- a/api/v1beta1/common_types.go +++ b/api/v1beta1/common_types.go @@ -19,6 +19,7 @@ package v1beta1 import ( corev1 "k8s.io/api/core/v1" topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1" + "k8s.io/apimachinery/pkg/util/validation/field" ) // IronicServiceTemplate defines the common input parameters for Ironic services @@ -76,3 +77,15 @@ type KeystoneEndpoints struct { // Public endpoint URL Public string `json:"public"` } + +// ValidateTopology - +func (instance *IronicServiceTemplate) ValidateTopology( + basePath *field.Path, + namespace string, +) field.ErrorList { + var allErrs field.ErrorList + allErrs = append(allErrs, topologyv1.ValidateTopologyRef( + instance.TopologyRef, + *basePath.Child("topologyRef"), namespace)...) + return allErrs +} diff --git a/api/v1beta1/ironic_webhook.go b/api/v1beta1/ironic_webhook.go index a5264444..1ff76732 100644 --- a/api/v1beta1/ironic_webhook.go +++ b/api/v1beta1/ironic_webhook.go @@ -612,48 +612,38 @@ func (spec *IronicSpecCore) ValidateIronicTopology(basePath *field.Path, namespa // When a TopologyRef CR is referenced, fail if a different Namespace is // referenced because is not supported - if spec.TopologyRef != nil { - if err := topologyv1.ValidateTopologyNamespace(spec.TopologyRef.Namespace, *basePath, namespace); err != nil { - allErrs = append(allErrs, err) - } - } + allErrs = append(allErrs, topologyv1.ValidateTopologyRef( + spec.TopologyRef, *basePath.Child("topologyRef"), namespace)...) // When a TopologyRef CR is referenced with an override to IronicAPI, fail // if a different Namespace is referenced because not supported - if spec.IronicAPI.TopologyRef != nil { - if err := topologyv1.ValidateTopologyNamespace(spec.IronicAPI.TopologyRef.Namespace, *basePath, namespace); err != nil { - allErrs = append(allErrs, err) - } - } + apiPath := basePath.Child("ironicAPI") + allErrs = append(allErrs, + spec.IronicAPI.ValidateTopology(apiPath, namespace)...) // When a TopologyRef CR is referenced with an override to an instance of // IronicConductor(s), fail if a different Namespace is referenced because // not supported for _, cs := range spec.IronicConductors { - if cs.TopologyRef != nil { - if err := topologyv1.ValidateTopologyNamespace(cs.TopologyRef.Namespace, *basePath, namespace); err != nil { - allErrs = append(allErrs, err) - } - } + path := basePath.Child("ironicConductors") + allErrs = append(allErrs, + cs.ValidateTopology(path, namespace)...) } // When a TopologyRef CR is referenced with an override to an instance of // IronicInspector, fail if a different Namespace is referenced because not // supported - if spec.IronicInspector.TopologyRef != nil { - if err := topologyv1.ValidateTopologyNamespace(spec.IronicInspector.TopologyRef.Namespace, *basePath, namespace); err != nil { - allErrs = append(allErrs, err) - } - } + insPath := basePath.Child("ironicInspector") + allErrs = append(allErrs, + spec.IronicInspector.ValidateTopology(insPath, namespace)...) // When a TopologyRef CR is referenced with an override to an instance of // IronicNeutronAgent, fail if a different Namespace is referenced because // not supported - if spec.IronicNeutronAgent.TopologyRef != nil { - if err := topologyv1.ValidateTopologyNamespace(spec.IronicNeutronAgent.TopologyRef.Namespace, *basePath, namespace); err != nil { - allErrs = append(allErrs, err) - } - } + nagentPath := basePath.Child("ironicNeutronAgent") + allErrs = append(allErrs, + spec.IronicNeutronAgent.ValidateTopology(nagentPath, namespace)...) + return allErrs } diff --git a/api/v1beta1/ironicinspector_types.go b/api/v1beta1/ironicinspector_types.go index 1aac031f..d5466564 100644 --- a/api/v1beta1/ironicinspector_types.go +++ b/api/v1beta1/ironicinspector_types.go @@ -23,6 +23,7 @@ import ( "github.com/openstack-k8s-operators/lib-common/modules/common/tls" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/validation/field" ) // IronicInspectorPasswordSelector to identify the AdminUser password from the Secret @@ -279,3 +280,15 @@ func (instance *IronicInspector) GetLastAppliedTopology() *topologyv1.TopoRef { func (instance *IronicInspector) SetLastAppliedTopology(topologyRef *topologyv1.TopoRef) { instance.Status.LastAppliedTopology = topologyRef } + +// ValidateTopology - +func (instance *IronicInspectorTemplate) ValidateTopology( + basePath *field.Path, + namespace string, +) field.ErrorList { + var allErrs field.ErrorList + allErrs = append(allErrs, topologyv1.ValidateTopologyRef( + instance.TopologyRef, + *basePath.Child("topologyRef"), namespace)...) + return allErrs +} diff --git a/go.mod b/go.mod index eb8d8aa9..dfafae13 100644 --- a/go.mod +++ b/go.mod @@ -8,15 +8,15 @@ require ( github.com/onsi/ginkgo/v2 v2.20.1 github.com/onsi/gomega v1.34.1 github.com/openshift/api v3.9.0+incompatible - github.com/openstack-k8s-operators/infra-operator/apis v0.6.0 + github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250319162810-463dd75a4cc4 github.com/openstack-k8s-operators/ironic-operator/api v0.0.0-00010101000000-000000000000 github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20250309111939-0605fce19482 - github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250228124213-cd63da392f97 + github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250315090821-34e570d2d5fb github.com/openstack-k8s-operators/lib-common/modules/test v0.5.1-0.20250228124213-cd63da392f97 github.com/openstack-k8s-operators/mariadb-operator/api v0.6.0 - k8s.io/api v0.29.14 - k8s.io/apimachinery v0.29.14 - k8s.io/client-go v0.29.14 + k8s.io/api v0.29.15 + k8s.io/apimachinery v0.29.15 + k8s.io/client-go v0.29.15 k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 sigs.k8s.io/controller-runtime v0.17.6 ) @@ -77,8 +77,8 @@ require ( google.golang.org/protobuf v1.34.1 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - k8s.io/apiextensions-apiserver v0.29.14 // indirect - k8s.io/component-base v0.29.14 // indirect + k8s.io/apiextensions-apiserver v0.29.15 // indirect + k8s.io/component-base v0.29.15 // indirect k8s.io/klog/v2 v2.120.1 // indirect k8s.io/kube-openapi v0.0.0-20240322212309-b815d8309940 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect diff --git a/go.sum b/go.sum index 01eef6df..59dd05df 100644 --- a/go.sum +++ b/go.sum @@ -78,12 +78,12 @@ github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k= github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY= github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 h1:J1wuGhVxpsHykZBa6Beb1gQ96Ptej9AE/BvwCBiRj1E= github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4= -github.com/openstack-k8s-operators/infra-operator/apis v0.6.0 h1:28i9Yc3UAdQK8VNzk0ubwq4n+qLuhD0nk6/7iHgD9us= -github.com/openstack-k8s-operators/infra-operator/apis v0.6.0/go.mod h1:JgcmYJyyMKfArK8ulZnbls0L01qt8Dq6s5LH8TZH63A= +github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250319162810-463dd75a4cc4 h1:wb2zsr9x9LantNLN/9dmYM42c3yLq3QuzsoOlGpDUxM= +github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250319162810-463dd75a4cc4/go.mod h1:n5DV/lGE9DHryAJ+JLJSgUXI2QHTj+aN4KoeSNC3PfU= github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20250309111939-0605fce19482 h1:W8PhAs+lX7Scgkr1zUGR9kK+ASTUv7DEFn3Aym1zfEg= github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20250309111939-0605fce19482/go.mod h1:yzzegC4K5/iSWD24stJXfj46WjvPG9LTjLb03XvdZ4I= -github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250228124213-cd63da392f97 h1:3LC66vrXJzGMV/eCdvImosOEL2Cgc2KFJIm2YhfTG3w= -github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250228124213-cd63da392f97/go.mod h1:rgpcv2tLD+/vudXx/gpIQSTuRpk4GOxHx84xwfvQalM= +github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250315090821-34e570d2d5fb h1:UAFYEHnbyhO0+yymquFmIqxc9QGji9mzreuYrDS1Ev4= +github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250315090821-34e570d2d5fb/go.mod h1:1CtBP0MQffdjE6buOv5jP2rB3+h7WH0a11lcyrpmxOk= github.com/openstack-k8s-operators/lib-common/modules/openstack v0.5.1-0.20250228124213-cd63da392f97 h1:2m8xt9k3FWcnzmq5SxplT0t6v8vvH7LZq3UWK17ygak= github.com/openstack-k8s-operators/lib-common/modules/openstack v0.5.1-0.20250228124213-cd63da392f97/go.mod h1:tfMa+ochq7Dyilq9hQr2CEPfPtsj6IUgMmMqi4CWDmo= github.com/openstack-k8s-operators/lib-common/modules/test v0.5.1-0.20250228124213-cd63da392f97 h1:2f6Fl2chkacLkElCtEtCFygtuVhEq3YuUvZbfiEBDZ8= @@ -200,16 +200,16 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -k8s.io/api v0.29.14 h1:JWFh5ufowH3Y6tCgEzY3URVJHb27f0tEDEej0nCjWDw= -k8s.io/api v0.29.14/go.mod h1:IV8YqKxMm8JGLBLlHM13Npn5lCITH10XYipWEW+YEOQ= -k8s.io/apiextensions-apiserver v0.29.14 h1:gw9WXrZJPu5kpI1UC+Wf8BVe9PWwRUB/UZXU8VzBsq4= -k8s.io/apiextensions-apiserver v0.29.14/go.mod h1:TJ51W+HKW2XqTtAsEFOz1/OohsMtekbKaTXh8ldioL4= -k8s.io/apimachinery v0.29.14 h1:IDhwnGNCp836SLOwW1SoEfFNV77wxIklhxeAHX9vmSo= -k8s.io/apimachinery v0.29.14/go.mod h1:i3FJVwhvSp/6n8Fl4K97PJEP8C+MM+aoDq4+ZJBf70Y= -k8s.io/client-go v0.29.14 h1:OSnzZ9DClaFRgl3zMAY2kGZhNjdGJkEb+RDz+MW2h6k= -k8s.io/client-go v0.29.14/go.mod h1:XtZt5n5UxKfPJ+sCoTPcEavWgZbLFFxMnAFFRQGK1RY= -k8s.io/component-base v0.29.14 h1:SF1DWN7bc2VloJ/ysegGoi/aHnopEo81aw9CslhqXIw= -k8s.io/component-base v0.29.14/go.mod h1:FoK1PHhFTaEQVvQLw29/Uyfd8Ug0qUKHrUcXIXJ1VxI= +k8s.io/api v0.29.15 h1:QxPcAheYujeBwkdiE0vMyKkAtqUq5YNyXVqimT+me44= +k8s.io/api v0.29.15/go.mod h1:16duIp2ez6GiLPq1g8XtZNIkw6hJpIitpxZSvv0dZ6E= +k8s.io/apiextensions-apiserver v0.29.15 h1:XI5axgsWqMlIIgpHbcz5vPjk06i3ibHv5FUdSfdtQLU= +k8s.io/apiextensions-apiserver v0.29.15/go.mod h1:6ZU61z32I8WUwbBTPIANUesTj5G40sZek0ojmeoMJI8= +k8s.io/apimachinery v0.29.15 h1:aLc0wghElkdnTO7TMVTxTrifoXah1lqRL8s6szDHGbg= +k8s.io/apimachinery v0.29.15/go.mod h1:i3FJVwhvSp/6n8Fl4K97PJEP8C+MM+aoDq4+ZJBf70Y= +k8s.io/client-go v0.29.15 h1:zCBOXKCtz9Hl8boKUGs8zbtZEP6pc7O8Ov3ma+gnS6o= +k8s.io/client-go v0.29.15/go.mod h1:xPy0D3p4sonPhZhI3QoYo4m7oLKoPjFf4vYF9oxoxNM= +k8s.io/component-base v0.29.15 h1:CvmXXTDyk43FDaiJ/Rp+yWFjw6hkUI2t7mIJUrK5j00= +k8s.io/component-base v0.29.15/go.mod h1:jH/sbuvmXew2Fz2iIKNMeNw8o/d1KR9tAg6uekQKnVk= k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw= k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= k8s.io/kube-openapi v0.0.0-20240322212309-b815d8309940 h1:qVoMaQV5t62UUvHe16Q3eb2c5HPzLHYzsi0Tu/xLndo= diff --git a/tests/functional/ironic_controller_test.go b/tests/functional/ironic_controller_test.go index b6746660..c53e1105 100644 --- a/tests/functional/ironic_controller_test.go +++ b/tests/functional/ironic_controller_test.go @@ -791,29 +791,76 @@ var _ = Describe("Ironic Webhook", func() { ) }) - It("rejects a wrong TopologyRef on a different namespace", func() { - spec := GetDefaultIronicSpec() - // Reference a top-level topology - spec["topologyRef"] = map[string]interface{}{ - "name": ironicNames.IronicTopologies[0].Name, - "namespace": "foo", - } - raw := map[string]interface{}{ - "apiVersion": "ironic.openstack.org/v1beta1", - "kind": "Ironic", - "metadata": map[string]interface{}{ - "name": ironicNames.IronicName.Name, - "namespace": ironicNames.IronicName.Namespace, - }, - "spec": spec, - } - unstructuredObj := &unstructured.Unstructured{Object: raw} - _, err := controllerutil.CreateOrPatch( - th.Ctx, th.K8sClient, unstructuredObj, func() error { return nil }) - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To( - ContainSubstring( - "Invalid value: \"namespace\": Customizing namespace field is not supported"), - ) - }) + DescribeTable("rejects wrong topology for", + func(serviceNameFunc func() (string, string)) { + + component, errorPath := serviceNameFunc() + expectedErrorMessage := fmt.Sprintf("spec.%s.namespace: Invalid value: \"namespace\": Customizing namespace field is not supported", errorPath) + + spec := GetDefaultIronicSpec() + + // API, Inspector, NeutronAgent + if component != "top-level" && component != "ironicConductors" { + spec[component] = map[string]interface{}{ + "topologyRef": map[string]interface{}{ + "name": "bar", + "namespace": "foo", + }, + } + } + // Conductors + if component == "ironicConductors" { + condList := []map[string]interface{}{ + { + "topologyRef": map[string]interface{}{ + "name": "foo", + "namespace": "bar", + }, + }, + } + spec["ironicConductors"] = condList + // top-level topologyRef + } else { + spec["topologyRef"] = map[string]interface{}{ + "name": "bar", + "namespace": "foo", + } + } + // Build the ironic CR + raw := map[string]interface{}{ + "apiVersion": "ironic.openstack.org/v1beta1", + "kind": "Ironic", + "metadata": map[string]interface{}{ + "name": ironicNames.IronicName.Name, + "namespace": ironicNames.IronicName.Namespace, + }, + "spec": spec, + } + unstructuredObj := &unstructured.Unstructured{Object: raw} + _, err := controllerutil.CreateOrPatch( + th.Ctx, th.K8sClient, unstructuredObj, func() error { return nil }) + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To( + ContainSubstring(expectedErrorMessage)) + }, + Entry("top-level topologyRef", func() (string, string) { + return "top-level", "topologyRef" + }), + Entry("ironicAPI topologyRef", func() (string, string) { + component := "ironicAPI" + return component, fmt.Sprintf("%s.topologyRef", component) + }), + Entry("ironicInspector topologyRef", func() (string, string) { + component := "ironicInspector" + return component, fmt.Sprintf("%s.topologyRef", component) + }), + Entry("ironicNeutronAgent topologyRef", func() (string, string) { + component := "ironicNeutronAgent" + return component, fmt.Sprintf("%s.topologyRef", component) + }), + Entry("ironicConductor topologyRef", func() (string, string) { + component := "ironicConductors" + return component, fmt.Sprintf("%s.topologyRef", component) + }), + ) })