@@ -1832,6 +1832,78 @@ var _ = Describe("OpenStackOperator controller", func() {
18321832 })
18331833 })
18341834
1835+ When ("OpenStackControlplane instance is created and an OpenStackVersion already exists with an arbitrary name" , func () {
1836+ BeforeEach (func () {
1837+ DeferCleanup (
1838+ th .DeleteInstance ,
1839+ CreateOpenStackVersion (names .OpenStackVersionName2 , GetDefaultOpenStackVersionSpec ()),
1840+ )
1841+ })
1842+
1843+ It ("rejects the OpenStackControlPlane if its name is not that same as the OpenStackVersion's name" , func () {
1844+ raw := map [string ]interface {}{
1845+ "apiVersion" : "core.openstack.org/v1beta1" ,
1846+ "kind" : "OpenStackControlPlane" ,
1847+ "metadata" : map [string ]interface {}{
1848+ "name" : names .OpenStackControlplaneName .Name ,
1849+ "namespace" : names .Namespace ,
1850+ },
1851+ "spec" : GetDefaultOpenStackControlPlaneSpec (),
1852+ }
1853+
1854+ unstructuredObj := & unstructured.Unstructured {Object : raw }
1855+ _ , err := controllerutil .CreateOrPatch (
1856+ th .Ctx , th .K8sClient , unstructuredObj , func () error { return nil })
1857+ Expect (err ).Should (HaveOccurred ())
1858+ var statusError * k8s_errors.StatusError
1859+ Expect (errors .As (err , & statusError )).To (BeTrue ())
1860+ Expect (statusError .ErrStatus .Details .Kind ).To (Equal ("OpenStackControlPlane" ))
1861+ Expect (statusError .ErrStatus .Message ).To (
1862+ ContainSubstring (
1863+ "must have same name as the existing" ),
1864+ )
1865+
1866+ // we remove the finalizer as this is needed when the OpenStackControlplane
1867+ // does not create the OpenStackVersion itself
1868+ DeferCleanup (
1869+ OpenStackVersionRemoveFinalizer ,
1870+ ctx ,
1871+ names .OpenStackVersionName2 ,
1872+ )
1873+ })
1874+
1875+ It ("accepts the OpenStackControlPlane if its name is the same as the OpenStackVersion's name" , func () {
1876+ raw := map [string ]interface {}{
1877+ "apiVersion" : "core.openstack.org/v1beta1" ,
1878+ "kind" : "OpenStackControlPlane" ,
1879+ "metadata" : map [string ]interface {}{
1880+ "name" : names .OpenStackVersionName2 .Name ,
1881+ "namespace" : names .Namespace ,
1882+ },
1883+ "spec" : GetDefaultOpenStackControlPlaneSpec (),
1884+ }
1885+
1886+ unstructuredObj := & unstructured.Unstructured {Object : raw }
1887+ _ , err := controllerutil .CreateOrPatch (
1888+ th .Ctx , th .K8sClient , unstructuredObj , func () error { return nil })
1889+ Expect (err ).ShouldNot (HaveOccurred ())
1890+
1891+ openStackControlPlane := & corev1.OpenStackControlPlane {}
1892+ openStackControlPlane .ObjectMeta .Namespace = names .Namespace
1893+ openStackControlPlane .Name = names .OpenStackVersionName2 .Name
1894+ err = k8sClient .Delete (ctx , openStackControlPlane )
1895+ Expect (err ).ShouldNot (HaveOccurred ())
1896+
1897+ // we remove the finalizer as this is needed when the OpenStackControlplane
1898+ // does not create the OpenStackVersion itself
1899+ DeferCleanup (
1900+ OpenStackVersionRemoveFinalizer ,
1901+ ctx ,
1902+ names .OpenStackVersionName2 ,
1903+ )
1904+ })
1905+ })
1906+
18351907 When ("An OpenStackControlplane instance is created with nodeSelector" , func () {
18361908 BeforeEach (func () {
18371909 spec := GetDefaultOpenStackControlPlaneSpec ()
0 commit comments