@@ -27,7 +27,7 @@ func TestResolveAllocationSubnet_DefaultsToImpSubnet(t *testing.T) {
2727 },
2828 }
2929
30- got , err := resolveAllocationSubnet (context .Background (), c , impNet )
30+ got , err := resolveAllocationSubnet (context .Background (), c , impNet , "" )
3131 if err != nil {
3232 t .Fatalf ("resolveAllocationSubnet: %v" , err )
3333 }
@@ -63,7 +63,7 @@ func TestResolveAllocationSubnet_UsesCiliumPoolCIDR(t *testing.T) {
6363 },
6464 }
6565
66- got , err := resolveAllocationSubnet (context .Background (), c , impNet )
66+ got , err := resolveAllocationSubnet (context .Background (), c , impNet , "" )
6767 if err != nil {
6868 t .Fatalf ("resolveAllocationSubnet: %v" , err )
6969 }
@@ -87,7 +87,7 @@ func TestResolveAllocationSubnet_CiliumWithOverrideCidr(t *testing.T) {
8787 }
8888 // When Cidr override is set, should use it without fetching pool from API.
8989 // Pass nil client to prove it doesn't touch the API.
90- subnet , err := resolveAllocationSubnet (context .Background (), nil , net )
90+ subnet , err := resolveAllocationSubnet (context .Background (), nil , net , "" )
9191 if err != nil {
9292 t .Fatalf ("resolveAllocationSubnet: %v" , err )
9393 }
@@ -96,6 +96,56 @@ func TestResolveAllocationSubnet_CiliumWithOverrideCidr(t *testing.T) {
9696 }
9797}
9898
99+ func TestResolveAllocationSubnet_UsesGroupCIDRFromStatus (t * testing.T ) {
100+ scheme := runtime .NewScheme ()
101+ if err := impdevv1alpha1 .AddToScheme (scheme ); err != nil {
102+ t .Fatalf ("scheme: %v" , err )
103+ }
104+ c := fake .NewClientBuilder ().WithScheme (scheme ).Build ()
105+
106+ impNet := & impdevv1alpha1.ImpNetwork {
107+ ObjectMeta : metav1.ObjectMeta {Name : "net1" , Namespace : "default" },
108+ Spec : impdevv1alpha1.ImpNetworkSpec {
109+ Subnet : "10.44.0.0/24" ,
110+ Groups : []impdevv1alpha1.NetworkGroupSpec {
111+ {Name : "workers" , ExpectedSize : 14 },
112+ },
113+ },
114+ }
115+ impNet .Status .GroupCIDRs = []impdevv1alpha1.GroupCIDR {
116+ {Name : "workers" , CIDR : "10.44.0.0/28" },
117+ }
118+
119+ got , err := resolveAllocationSubnet (context .Background (), c , impNet , "workers" )
120+ if err != nil {
121+ t .Fatalf ("resolveAllocationSubnet: %v" , err )
122+ }
123+ if got != "10.44.0.0/28" {
124+ t .Fatalf ("got %q, want %q" , got , "10.44.0.0/28" )
125+ }
126+ }
127+
128+ func TestResolveAllocationSubnet_GroupNotAllocatedYetReturnsError (t * testing.T ) {
129+ scheme := runtime .NewScheme ()
130+ if err := impdevv1alpha1 .AddToScheme (scheme ); err != nil {
131+ t .Fatalf ("scheme: %v" , err )
132+ }
133+ c := fake .NewClientBuilder ().WithScheme (scheme ).Build ()
134+
135+ impNet := & impdevv1alpha1.ImpNetwork {
136+ ObjectMeta : metav1.ObjectMeta {Name : "net1" , Namespace : "default" },
137+ Spec : impdevv1alpha1.ImpNetworkSpec {
138+ Subnet : "10.44.0.0/24" ,
139+ },
140+ // Status.GroupCIDRs is empty — controller hasn't reconciled yet.
141+ }
142+
143+ _ , err := resolveAllocationSubnet (context .Background (), c , impNet , "workers" )
144+ if err == nil {
145+ t .Fatal ("expected error for unallocated group CIDR" )
146+ }
147+ }
148+
99149func TestResolveAllocationSubnet_CiliumPoolMissingReturnsError (t * testing.T ) {
100150 scheme := runtime .NewScheme ()
101151 if err := impdevv1alpha1 .AddToScheme (scheme ); err != nil {
@@ -114,7 +164,7 @@ func TestResolveAllocationSubnet_CiliumPoolMissingReturnsError(t *testing.T) {
114164 },
115165 }
116166
117- _ , err := resolveAllocationSubnet (context .Background (), c , impNet )
167+ _ , err := resolveAllocationSubnet (context .Background (), c , impNet , "" )
118168 if err == nil {
119169 t .Fatal ("expected error for missing CiliumPodIPPool" )
120170 }
0 commit comments