@@ -418,17 +418,6 @@ func TestInvalidScenarios(t *testing.T) {
418
418
},
419
419
expectedError : "provided address is not a valid IP, range, nor CIDR" ,
420
420
},
421
- {
422
- testcase : "omitting a prefix should not be allowed" ,
423
- spec : v1alpha2.InClusterIPPoolSpec {
424
- Addresses : []string {
425
- "10.0.0.25" ,
426
- "10.0.0.26" ,
427
- },
428
- Gateway : "10.0.0.1" ,
429
- },
430
- expectedError : "a valid prefix is required" ,
431
- },
432
421
{
433
422
testcase : "specifying an invalid prefix" ,
434
423
spec : v1alpha2.InClusterIPPoolSpec {
@@ -648,6 +637,63 @@ func TestInvalidScenarios(t *testing.T) {
648
637
}
649
638
}
650
639
640
+ func TestIPPool_Prefix (t * testing.T ) {
641
+ g := NewWithT (t )
642
+
643
+ scheme := runtime .NewScheme ()
644
+ g .Expect (ipamv1 .AddToScheme (scheme )).To (Succeed ())
645
+
646
+ namespacedPool := & v1alpha2.InClusterIPPool {
647
+ ObjectMeta : metav1.ObjectMeta {
648
+ Name : "my-pool" ,
649
+ },
650
+ Spec : v1alpha2.InClusterIPPoolSpec {
651
+ Addresses : []string {"10.0.0.10-10.0.0.20" },
652
+ Prefix : 0 ,
653
+ Gateway : "10.0.0.1" ,
654
+ },
655
+ }
656
+
657
+ globalPool := & v1alpha2.GlobalInClusterIPPool {
658
+ ObjectMeta : metav1.ObjectMeta {
659
+ Name : "my-pool" ,
660
+ },
661
+ Spec : v1alpha2.InClusterIPPoolSpec {
662
+ Addresses : []string {"10.0.0.10-10.0.0.20" },
663
+ Prefix : 0 ,
664
+ Gateway : "10.0.0.1" ,
665
+ },
666
+ }
667
+ emptyPrefixPool := & v1alpha2.InClusterIPPool {
668
+ ObjectMeta : metav1.ObjectMeta {
669
+ Name : "my-pool" ,
670
+ },
671
+ Spec : v1alpha2.InClusterIPPoolSpec {
672
+ Addresses : []string {"10.0.0.10-10.0.0.20" },
673
+ Gateway : "10.0.0.1" ,
674
+ },
675
+ }
676
+
677
+ ips := []client.Object {
678
+ createIP ("my-ip" , "10.0.0.10" , namespacedPool ),
679
+ createIP ("my-ip-2" , "10.0.0.10" , globalPool ),
680
+ }
681
+
682
+ fakeClient := fake .NewClientBuilder ().
683
+ WithScheme (scheme ).
684
+ WithObjects (ips ... ).
685
+ WithIndex (& ipamv1.IPAddress {}, index .IPAddressPoolRefCombinedField , index .IPAddressByCombinedPoolRef ).
686
+ Build ()
687
+
688
+ webhook := InClusterIPPool {
689
+ Client : fakeClient ,
690
+ }
691
+
692
+ g .Expect (webhook .validate (& v1alpha2.InClusterIPPool {}, namespacedPool )).Error ().To (BeNil (), "should allow /0 prefix InClusterIPPool" )
693
+ g .Expect (webhook .validate (& v1alpha2.GlobalInClusterIPPool {}, globalPool )).Error ().To (BeNil (), "should allow /0 prefix GlobalInClusterIPPool" )
694
+ g .Expect (webhook .validate (& v1alpha2.InClusterIPPool {}, emptyPrefixPool )).Error ().To (BeNil (), "should allow empty prefix InClusterIPPool" )
695
+ }
696
+
651
697
func runInvalidScenarioTests (t * testing.T , tt invalidScenarioTest , pool types.GenericInClusterPool , webhook InClusterIPPool ) {
652
698
t .Helper ()
653
699
t .Run (tt .testcase , func (t * testing.T ) {
0 commit comments