@@ -130,7 +130,11 @@ var _ = Describe("DataplaneNodeSet Webhook", func() {
130130 nodeSetSpec ["preProvisioned" ] = true
131131 nodeSetSpec ["nodes" ] = map [string ]interface {}{
132132 "compute-0" : map [string ]interface {}{
133- "hostName" : "compute-0" },
133+ "hostName" : "compute-0" ,
134+ "ansible" : map [string ]interface {}{
135+ "ansibleHost" : "192.168.122.100" ,
136+ },
137+ },
134138 }
135139 DeferCleanup (th .DeleteInstance , CreateDataplaneNodeSet (dataplaneNodeSetName , nodeSetSpec ))
136140 })
@@ -141,7 +145,11 @@ var _ = Describe("DataplaneNodeSet Webhook", func() {
141145 newNodeSetSpec ["preProvisioned" ] = true
142146 newNodeSetSpec ["nodes" ] = map [string ]interface {}{
143147 "compute-0" : map [string ]interface {}{
144- "hostName" : "compute-0" },
148+ "hostName" : "compute-0" ,
149+ "ansible" : map [string ]interface {}{
150+ "ansibleHost" : "192.168.122.100" ,
151+ },
152+ },
145153 }
146154 newInstance := DefaultDataplaneNodeSetTemplate (types.NamespacedName {Name : "test-duplicate-node" , Namespace : namespace }, newNodeSetSpec )
147155 unstructuredObj := & unstructured.Unstructured {Object : newInstance }
@@ -159,16 +167,24 @@ var _ = Describe("DataplaneNodeSet Webhook", func() {
159167 "compute-3" : map [string ]interface {}{
160168 "hostName" : "compute-3" ,
161169 "ansible" : map [string ]interface {}{
162- "ansibleHost" : "compute-3 " ,
170+ "ansibleHost" : "192.168.122.103 " ,
163171 },
164172 },
165173 "compute-2" : map [string ]interface {}{
166- "hostName" : "compute-2" },
174+ "hostName" : "compute-2" ,
175+ "ansible" : map [string ]interface {}{
176+ "ansibleHost" : "192.168.122.102" ,
177+ },
178+ },
167179 "compute-8" : map [string ]interface {}{
168- "hostName" : "compute-8" },
180+ "hostName" : "compute-8" ,
181+ "ansible" : map [string ]interface {}{
182+ "ansibleHost" : "192.168.122.108" ,
183+ },
184+ },
169185 "compute-0" : map [string ]interface {}{
170186 "ansible" : map [string ]interface {}{
171- "ansibleHost" : "compute-0 " ,
187+ "ansibleHost" : "192.168.122.100 " ,
172188 },
173189 },
174190 }
@@ -180,13 +196,43 @@ var _ = Describe("DataplaneNodeSet Webhook", func() {
180196 }).Should (ContainSubstring ("already exists in another cluster" ))
181197 })
182198 })
199+
200+ When ("A pre-provisioned NodeSet is created without a valid IP as ansibleHost" , func () {
201+ It ("Should block creation" , func () {
202+ Eventually (func (_ Gomega ) string {
203+ spec := DefaultDataPlaneNoNodeSetSpec (false )
204+ spec ["nodes" ] = map [string ]interface {}{
205+ "compute-0" : map [string ]interface {}{
206+ "hostName" : "compute-0" ,
207+ "ansible" : map [string ]interface {}{
208+ "ansibleHost" : "compute-0.example.com" ,
209+ },
210+ },
211+ }
212+ name := types.NamespacedName {
213+ Name : "test-hostname-ansiblehost" , Namespace : namespace }
214+ obj := DefaultDataplaneNodeSetTemplate (name , spec )
215+ unstructuredObj := & unstructured.Unstructured {Object : obj }
216+ _ , err := controllerutil .CreateOrPatch (
217+ th .Ctx , th .K8sClient , unstructuredObj ,
218+ func () error { return nil })
219+ return fmt .Sprintf ("%s" , err )
220+ }).Should (ContainSubstring (
221+ "ansibleHost must be a valid IP address" ))
222+ })
223+ })
224+
183225 When ("A NodeSet is updated with a OpenStackDataPlaneDeployment" , func () {
184226 BeforeEach (func () {
185227 nodeSetSpec := DefaultDataPlaneNoNodeSetSpec (false )
186228 nodeSetSpec ["preProvisioned" ] = true
187229 nodeSetSpec ["nodes" ] = map [string ]interface {}{
188230 "compute-0" : map [string ]interface {}{
189- "hostName" : "compute-0" },
231+ "hostName" : "compute-0" ,
232+ "ansible" : map [string ]interface {}{
233+ "ansibleHost" : "192.168.122.100" ,
234+ },
235+ },
190236 }
191237
192238 DeferCleanup (th .DeleteInstance , CreateDataplaneNodeSet (dataplaneNodeSetName , nodeSetSpec ))
0 commit comments