@@ -362,29 +362,31 @@ var _ = Describe("IPAddressClaimReconciler", func() {
362
362
363
363
When ("the referenced global pool exists" , func () {
364
364
const poolName = "global-pool"
365
-
365
+ var secondNamespace string
366
366
BeforeEach (func () {
367
367
pool := v1alpha1.GlobalInClusterIPPool {
368
368
ObjectMeta : metav1.ObjectMeta { // global pool, no namespace
369
369
Name : poolName ,
370
370
},
371
371
Spec : v1alpha1.InClusterIPPoolSpec {
372
- First : "10.0.0.1 " ,
372
+ First : "10.0.0.2 " ,
373
373
Last : "10.0.0.254" ,
374
374
Prefix : 24 ,
375
- Gateway : "10.0.0.2 " ,
375
+ Gateway : "10.0.0.1 " ,
376
376
},
377
377
}
378
378
Expect (k8sClient .Create (context .Background (), & pool )).To (Succeed ())
379
379
Eventually (Get (& pool )).Should (Succeed ())
380
+ secondNamespace = createNamespace ()
380
381
})
381
382
382
383
AfterEach (func () {
383
384
deleteClusterScopedPool (poolName )
384
385
deleteClaim ("test" , namespace )
386
+ deleteClaim ("test-second-namespace" , secondNamespace )
385
387
})
386
388
387
- It ("should allocate an Address from the Pool" , func () {
389
+ It ("should allocate an Address from the Pool, no matter the claim's namespace " , func () {
388
390
claim := clusterv1.IPAddressClaim {
389
391
ObjectMeta : metav1.ObjectMeta {
390
392
Name : "test" ,
@@ -399,6 +401,20 @@ var _ = Describe("IPAddressClaimReconciler", func() {
399
401
},
400
402
}
401
403
404
+ claimFromSecondNamespace := clusterv1.IPAddressClaim {
405
+ ObjectMeta : metav1.ObjectMeta {
406
+ Name : "test-second-namespace" ,
407
+ Namespace : secondNamespace ,
408
+ },
409
+ Spec : clusterv1.IPAddressClaimSpec {
410
+ PoolRef : corev1.TypedLocalObjectReference {
411
+ APIGroup : pointer .String ("ipam.cluster.x-k8s.io" ),
412
+ Kind : "GlobalInClusterIPPool" ,
413
+ Name : poolName ,
414
+ },
415
+ },
416
+ }
417
+
402
418
expectedIPAddress := clusterv1.IPAddress {
403
419
ObjectMeta : metav1.ObjectMeta {
404
420
Name : "test" ,
@@ -430,25 +446,74 @@ var _ = Describe("IPAddressClaimReconciler", func() {
430
446
Kind : "GlobalInClusterIPPool" ,
431
447
Name : poolName ,
432
448
},
433
- Address : "10.0.0.1 " ,
449
+ Address : "10.0.0.2 " ,
434
450
Prefix : 24 ,
435
- Gateway : "10.0.0.2 " ,
451
+ Gateway : "10.0.0.1 " ,
436
452
},
437
453
}
438
454
455
+ expectedIPAddressInSecondNamespace := clusterv1.IPAddress {
456
+ ObjectMeta : metav1.ObjectMeta {
457
+ Name : "test-second-namespace" ,
458
+ Namespace : secondNamespace ,
459
+ Finalizers : []string {ProtectAddressFinalizer },
460
+ OwnerReferences : []metav1.OwnerReference {
461
+ {
462
+ APIVersion : "ipam.cluster.x-k8s.io/v1alpha1" ,
463
+ BlockOwnerDeletion : pointer .Bool (true ),
464
+ Controller : pointer .Bool (true ),
465
+ Kind : "IPAddressClaim" ,
466
+ Name : "test-second-namespace" ,
467
+ },
468
+ {
469
+ APIVersion : "ipam.cluster.x-k8s.io/v1alpha1" ,
470
+ BlockOwnerDeletion : pointer .Bool (true ),
471
+ Controller : pointer .Bool (false ),
472
+ Kind : "GlobalInClusterIPPool" ,
473
+ Name : poolName ,
474
+ },
475
+ },
476
+ },
477
+ Spec : clusterv1.IPAddressSpec {
478
+ ClaimRef : corev1.LocalObjectReference {
479
+ Name : "test-second-namespace" ,
480
+ },
481
+ PoolRef : corev1.TypedLocalObjectReference {
482
+ APIGroup : pointer .String ("ipam.cluster.x-k8s.io" ),
483
+ Kind : "GlobalInClusterIPPool" ,
484
+ Name : poolName ,
485
+ },
486
+ Address : "10.0.0.3" ,
487
+ Prefix : 24 ,
488
+ Gateway : "10.0.0.1" ,
489
+ },
490
+ }
439
491
Expect (k8sClient .Create (context .Background (), & claim )).To (Succeed ())
492
+ Expect (k8sClient .Create (context .Background (), & claimFromSecondNamespace )).To (Succeed ())
440
493
441
- address := clusterv1.IPAddress {
494
+ expectedAddress := clusterv1.IPAddress {
442
495
ObjectMeta : metav1.ObjectMeta {
443
496
Name : "test" ,
444
497
Namespace : namespace ,
445
498
},
446
499
}
447
500
448
- Eventually (Object (& address )).
501
+ Eventually (Object (& expectedAddress )).
449
502
WithTimeout (time .Second ).WithPolling (100 * time .Millisecond ).Should (
450
503
EqualObject (& expectedIPAddress , IgnoreAutogeneratedMetadata , IgnoreUIDsOnIPAddress ),
451
504
)
505
+
506
+ actualAddressFromSecondNamespace := clusterv1.IPAddress {
507
+ ObjectMeta : metav1.ObjectMeta {
508
+ Name : "test-second-namespace" ,
509
+ Namespace : secondNamespace ,
510
+ },
511
+ }
512
+
513
+ Eventually (Object (& actualAddressFromSecondNamespace )).
514
+ WithTimeout (time .Second ).WithPolling (100 * time .Millisecond ).Should (
515
+ EqualObject (& expectedIPAddressInSecondNamespace , IgnoreAutogeneratedMetadata , IgnoreUIDsOnIPAddress ),
516
+ )
452
517
})
453
518
})
454
519
0 commit comments