@@ -280,6 +280,148 @@ var _ = Describe("Barbican controller", func() {
280280 })
281281 })
282282
283+ When ("A Barbican with nodeSelector is created" , func () {
284+ BeforeEach (func () {
285+ spec := GetDefaultBarbicanSpec ()
286+ spec ["nodeSelector" ] = map [string ]interface {}{
287+ "foo" : "bar" ,
288+ }
289+ spec ["barbicanAPI" ] = GetDefaultBarbicanAPISpec ()
290+ DeferCleanup (k8sClient .Delete , ctx , CreateBarbicanMessageBusSecret (barbicanTest .Instance .Namespace , "rabbitmq-secret" ))
291+ DeferCleanup (th .DeleteInstance , CreateBarbican (barbicanTest .Instance , spec ))
292+ DeferCleanup (k8sClient .Delete , ctx , CreateKeystoneAPISecret (barbicanTest .Instance .Namespace , SecretName ))
293+
294+ DeferCleanup (
295+ k8sClient .Delete , ctx , CreateBarbicanSecret (barbicanTest .Instance .Namespace , "test-osp-secret-barbican" ))
296+
297+ DeferCleanup (
298+ mariadb .DeleteDBService ,
299+ mariadb .CreateDBService (
300+ barbicanTest .Instance .Namespace ,
301+ GetBarbican (barbicanTest .Instance ).Spec .DatabaseInstance ,
302+ corev1.ServiceSpec {
303+ Ports : []corev1.ServicePort {{Port : 3306 }},
304+ },
305+ ),
306+ )
307+ infra .SimulateTransportURLReady (barbicanTest .BarbicanTransportURL )
308+ DeferCleanup (keystone .DeleteKeystoneAPI , keystone .CreateKeystoneAPI (barbicanTest .Instance .Namespace ))
309+ mariadb .SimulateMariaDBAccountCompleted (barbicanTest .BarbicanDatabaseAccount )
310+ mariadb .SimulateMariaDBDatabaseCompleted (barbicanTest .BarbicanDatabaseName )
311+ th .SimulateJobSuccess (barbicanTest .BarbicanDBSync )
312+ })
313+
314+ It ("sets nodeSelector in resource specs" , func () {
315+ Eventually (func (g Gomega ) {
316+ g .Expect (th .GetJob (barbicanTest .BarbicanDBSync ).Spec .Template .Spec .NodeSelector ).To (Equal (map [string ]string {"foo" : "bar" }))
317+ g .Expect (th .GetDeployment (barbicanTest .BarbicanAPI ).Spec .Template .Spec .NodeSelector ).To (Equal (map [string ]string {"foo" : "bar" }))
318+ }, timeout , interval ).Should (Succeed ())
319+ })
320+
321+ It ("updates nodeSelector in resource specs when changed" , func () {
322+ Eventually (func (g Gomega ) {
323+ g .Expect (th .GetJob (barbicanTest .BarbicanDBSync ).Spec .Template .Spec .NodeSelector ).To (Equal (map [string ]string {"foo" : "bar" }))
324+ g .Expect (th .GetDeployment (barbicanTest .BarbicanAPI ).Spec .Template .Spec .NodeSelector ).To (Equal (map [string ]string {"foo" : "bar" }))
325+ }, timeout , interval ).Should (Succeed ())
326+
327+ Eventually (func (g Gomega ) {
328+ barbican := GetBarbican (barbicanName )
329+ newNodeSelector := map [string ]string {
330+ "foo2" : "bar2" ,
331+ }
332+ barbican .Spec .NodeSelector = & newNodeSelector
333+ g .Expect (k8sClient .Update (ctx , barbican )).Should (Succeed ())
334+ }, timeout , interval ).Should (Succeed ())
335+
336+ Eventually (func (g Gomega ) {
337+ th .SimulateJobSuccess (barbicanTest .BarbicanDBSync )
338+ g .Expect (th .GetJob (barbicanTest .BarbicanDBSync ).Spec .Template .Spec .NodeSelector ).To (Equal (map [string ]string {"foo2" : "bar2" }))
339+ g .Expect (th .GetDeployment (barbicanTest .BarbicanAPI ).Spec .Template .Spec .NodeSelector ).To (Equal (map [string ]string {"foo2" : "bar2" }))
340+ }, timeout , interval ).Should (Succeed ())
341+ })
342+
343+ It ("removes nodeSelector from resource specs when cleared" , func () {
344+ Eventually (func (g Gomega ) {
345+ g .Expect (th .GetJob (barbicanTest .BarbicanDBSync ).Spec .Template .Spec .NodeSelector ).To (Equal (map [string ]string {"foo" : "bar" }))
346+ g .Expect (th .GetDeployment (barbicanTest .BarbicanAPI ).Spec .Template .Spec .NodeSelector ).To (Equal (map [string ]string {"foo" : "bar" }))
347+ }, timeout , interval ).Should (Succeed ())
348+
349+ Eventually (func (g Gomega ) {
350+ barbican := GetBarbican (barbicanName )
351+ emptyNodeSelector := map [string ]string {}
352+ barbican .Spec .NodeSelector = & emptyNodeSelector
353+ g .Expect (k8sClient .Update (ctx , barbican )).Should (Succeed ())
354+ }, timeout , interval ).Should (Succeed ())
355+
356+ Eventually (func (g Gomega ) {
357+ th .SimulateJobSuccess (barbicanTest .BarbicanDBSync )
358+ g .Expect (th .GetJob (barbicanTest .BarbicanDBSync ).Spec .Template .Spec .NodeSelector ).To (BeNil ())
359+ g .Expect (th .GetDeployment (barbicanTest .BarbicanAPI ).Spec .Template .Spec .NodeSelector ).To (BeNil ())
360+ }, timeout , interval ).Should (Succeed ())
361+ })
362+
363+ It ("removes nodeSelector from resource specs when nilled" , func () {
364+ Eventually (func (g Gomega ) {
365+ g .Expect (th .GetJob (barbicanTest .BarbicanDBSync ).Spec .Template .Spec .NodeSelector ).To (Equal (map [string ]string {"foo" : "bar" }))
366+ g .Expect (th .GetDeployment (barbicanTest .BarbicanAPI ).Spec .Template .Spec .NodeSelector ).To (Equal (map [string ]string {"foo" : "bar" }))
367+ }, timeout , interval ).Should (Succeed ())
368+
369+ Eventually (func (g Gomega ) {
370+ barbican := GetBarbican (barbicanName )
371+ barbican .Spec .NodeSelector = nil
372+ g .Expect (k8sClient .Update (ctx , barbican )).Should (Succeed ())
373+ }, timeout , interval ).Should (Succeed ())
374+
375+ Eventually (func (g Gomega ) {
376+ th .SimulateJobSuccess (barbicanTest .BarbicanDBSync )
377+ g .Expect (th .GetJob (barbicanTest .BarbicanDBSync ).Spec .Template .Spec .NodeSelector ).To (BeNil ())
378+ g .Expect (th .GetDeployment (barbicanTest .BarbicanAPI ).Spec .Template .Spec .NodeSelector ).To (BeNil ())
379+ }, timeout , interval ).Should (Succeed ())
380+ })
381+
382+ It ("allows nodeSelector service override" , func () {
383+ Eventually (func (g Gomega ) {
384+ g .Expect (th .GetJob (barbicanTest .BarbicanDBSync ).Spec .Template .Spec .NodeSelector ).To (Equal (map [string ]string {"foo" : "bar" }))
385+ g .Expect (th .GetDeployment (barbicanTest .BarbicanAPI ).Spec .Template .Spec .NodeSelector ).To (Equal (map [string ]string {"foo" : "bar" }))
386+ }, timeout , interval ).Should (Succeed ())
387+
388+ Eventually (func (g Gomega ) {
389+ barbican := GetBarbican (barbicanName )
390+ apiNodeSelector := map [string ]string {
391+ "foo" : "api" ,
392+ }
393+ barbican .Spec .BarbicanAPI .NodeSelector = & apiNodeSelector
394+ g .Expect (k8sClient .Update (ctx , barbican )).Should (Succeed ())
395+ }, timeout , interval ).Should (Succeed ())
396+
397+ Eventually (func (g Gomega ) {
398+ th .SimulateJobSuccess (barbicanTest .BarbicanDBSync )
399+ g .Expect (th .GetJob (barbicanTest .BarbicanDBSync ).Spec .Template .Spec .NodeSelector ).To (Equal (map [string ]string {"foo" : "bar" }))
400+ g .Expect (th .GetDeployment (barbicanTest .BarbicanAPI ).Spec .Template .Spec .NodeSelector ).To (Equal (map [string ]string {"foo" : "api" }))
401+ }, timeout , interval ).Should (Succeed ())
402+ })
403+
404+ It ("allows nodeSelector service override to empty" , func () {
405+ Eventually (func (g Gomega ) {
406+ g .Expect (th .GetJob (barbicanTest .BarbicanDBSync ).Spec .Template .Spec .NodeSelector ).To (Equal (map [string ]string {"foo" : "bar" }))
407+ g .Expect (th .GetDeployment (barbicanTest .BarbicanAPI ).Spec .Template .Spec .NodeSelector ).To (Equal (map [string ]string {"foo" : "bar" }))
408+ }, timeout , interval ).Should (Succeed ())
409+
410+ Eventually (func (g Gomega ) {
411+ barbican := GetBarbican (barbicanName )
412+ emptyNodeSelector := map [string ]string {}
413+ barbican .Spec .BarbicanAPI .NodeSelector = & emptyNodeSelector
414+ g .Expect (k8sClient .Update (ctx , barbican )).Should (Succeed ())
415+ }, timeout , interval ).Should (Succeed ())
416+
417+ Eventually (func (g Gomega ) {
418+ th .SimulateJobSuccess (barbicanTest .BarbicanDBSync )
419+ g .Expect (th .GetJob (barbicanTest .BarbicanDBSync ).Spec .Template .Spec .NodeSelector ).To (Equal (map [string ]string {"foo" : "bar" }))
420+ g .Expect (th .GetDeployment (barbicanTest .BarbicanAPI ).Spec .Template .Spec .NodeSelector ).To (BeNil ())
421+ }, timeout , interval ).Should (Succeed ())
422+ })
423+ })
424+
283425 // Run MariaDBAccount suite tests. these are pre-packaged ginkgo tests
284426 // that exercise standard account create / update patterns that should be
285427 // common to all controllers that ensure MariaDBAccount CRs.
0 commit comments