@@ -59,6 +59,7 @@ func createNameSpaceReconciler(objs []client.Object) *NamespaceReconciler {
5959 EnforcementPoint : "vmc-enforcementpoint" ,
6060 UseAVILoadBalancer : false ,
6161 },
62+ K8sConfig : & config.K8sConfig {},
6263 }
6364
6465 service := & vpc.VPCService {
@@ -236,7 +237,7 @@ func TestNamespaceReconciler_Reconcile(t *testing.T) {
236237 })
237238 // Mock createDefaultSubnetSet to return nil (no error)
238239 patches .ApplyPrivateMethod (reflect .TypeOf (r ), "createDefaultSubnetSet" , func (_ * NamespaceReconciler , _ context.Context , _ string ,
239- _ int , _ [] v1alpha1.SharedSubnet , _ ctlcommon.NameSpaceType , _ bool ) error {
240+ _ * v1alpha1.VPCNetworkConfiguration , _ ctlcommon.NameSpaceType , _ v1alpha1. NetworkStackType ) error {
240241 return nil
241242 })
242243 patches .ApplyMethod (reflect .TypeOf (& vpc.VPCService {}), "GetNetworkStackFromNC" , func (_ * vpc.VPCService , _ * v1alpha1.VPCNetworkConfiguration ) (v1alpha1.NetworkStackType , error ) {
@@ -345,15 +346,18 @@ func TestGetAccessMode(t *testing.T) {
345346
346347func TestCreateDefaultSubnetSet (t * testing.T ) {
347348 tests := []struct {
348- name string
349- namespace string
350- defaultSubnetSize int
351- existingResources []client.Object
352- expectedError bool
353- networkStack v1alpha1.NetworkStackType
354- nameSpaceType ctlcommon.NameSpaceType
355- expectedSubnetSets int
356- setupMocks func (r * NamespaceReconciler ) * gomonkey.Patches
349+ name string
350+ namespace string
351+ defaultSubnetSize int
352+ defaultIPv6PrefixLength int
353+ existingResources []client.Object
354+ ipFamily string
355+ expectedError bool
356+ networkStack v1alpha1.NetworkStackType
357+ nameSpaceType ctlcommon.NameSpaceType
358+ expectedSubnetSets int
359+ expectedIPAddressType v1alpha1.IPAddressType
360+ setupMocks func (r * NamespaceReconciler ) * gomonkey.Patches
357361 }{
358362 {
359363 name : "Skip case - not create SubnetSet for NormalNs" ,
@@ -366,37 +370,43 @@ func TestCreateDefaultSubnetSet(t *testing.T) {
366370 setupMocks : func (r * NamespaceReconciler ) * gomonkey.Patches { return nil },
367371 },
368372 {
369- name : "Success case - create new SubnetSets for cpvm namespace" ,
370- namespace : "test-ns" ,
371- defaultSubnetSize : 8 ,
372- existingResources : []client.Object {},
373- expectedError : false ,
374- expectedSubnetSets : 1 , // VM
375- networkStack : v1alpha1 .FullStackVPC ,
376- nameSpaceType : ctlcommon .SystemNs ,
373+ name : "Success case - create new SubnetSets for cpvm namespace (dual-stack)" ,
374+ namespace : "test-ns" ,
375+ defaultSubnetSize : 8 ,
376+ defaultIPv6PrefixLength : 72 ,
377+ existingResources : []client.Object {},
378+ ipFamily : "DualStack" ,
379+ expectedError : false ,
380+ expectedSubnetSets : 1 , // VM
381+ networkStack : v1alpha1 .FullStackVPC ,
382+ nameSpaceType : ctlcommon .SystemNs ,
383+ expectedIPAddressType : v1alpha1 .IPAddressTypeIPv4IPv6 ,
377384 setupMocks : func (r * NamespaceReconciler ) * gomonkey.Patches {
378- patches := gomonkey .ApplyPrivateMethod (reflect .TypeOf (r ), "getSystemNsDefaultSize" , func (_ * NamespaceReconciler ) int {
379- return 8
385+ // Avoid NSXClient version checks that require a populated Cluster in unit tests.
386+ return gomonkey .ApplyMethod (reflect .TypeOf (r .SubnetService .NSXClient ), "NSXCheckVersion" , func (_ * nsx.Client , _ int ) bool {
387+ return true
380388 })
381- return patches
382389 },
383390 },
384391 {
385- name : "Success case - create new SubnetSets for system svc namespace" ,
386- namespace : "test-ns" ,
387- defaultSubnetSize : 24 ,
388- existingResources : []client.Object {},
389- expectedError : false ,
390- expectedSubnetSets : 1 , // Pod
391- networkStack : v1alpha1 .FullStackVPC ,
392- nameSpaceType : ctlcommon .SVServiceNs ,
393- setupMocks : func (r * NamespaceReconciler ) * gomonkey.Patches { return nil },
392+ name : "Success case - create new SubnetSets for system svc namespace (IPv4-only)" ,
393+ namespace : "test-ns" ,
394+ defaultSubnetSize : 24 ,
395+ existingResources : []client.Object {},
396+ ipFamily : "IPv4" ,
397+ expectedError : false ,
398+ expectedSubnetSets : 1 , // Pod
399+ networkStack : v1alpha1 .FullStackVPC ,
400+ nameSpaceType : ctlcommon .SVServiceNs ,
401+ expectedIPAddressType : v1alpha1 .IPAddressTypeIPv4 ,
402+ setupMocks : func (r * NamespaceReconciler ) * gomonkey.Patches { return nil },
394403 },
395404 }
396405
397406 for _ , tt := range tests {
398407 t .Run (tt .name , func (t * testing.T ) {
399408 r := createNameSpaceReconciler (tt .existingResources )
409+ r .NSXConfig .K8sConfig .IPFamily = tt .ipFamily
400410
401411 if tt .setupMocks != nil {
402412 patches := tt .setupMocks (r )
@@ -405,8 +415,14 @@ func TestCreateDefaultSubnetSet(t *testing.T) {
405415 }
406416 }
407417
418+ nc := & v1alpha1.VPCNetworkConfiguration {
419+ Spec : v1alpha1.VPCNetworkConfigurationSpec {
420+ DefaultSubnetSize : tt .defaultSubnetSize ,
421+ DefaultIPv6PrefixLength : tt .defaultIPv6PrefixLength ,
422+ },
423+ }
408424 // Call the function being tested
409- err := r .createDefaultSubnetSet (context .Background (), tt .namespace , tt . defaultSubnetSize , tt .nameSpaceType , tt .networkStack )
425+ err := r .createDefaultSubnetSet (context .Background (), tt .namespace , nc , tt .nameSpaceType , tt .networkStack )
410426
411427 // Check the result
412428 if tt .expectedError {
@@ -422,6 +438,7 @@ func TestCreateDefaultSubnetSet(t *testing.T) {
422438
423439 // Check that the SubnetSets have the correct properties
424440 if len (subnetSetList .Items ) > 0 {
441+ wantIPv6 := nc .Spec .DefaultIPv6PrefixLength
425442 for _ , subnetSet := range subnetSetList .Items {
426443 switch subnetSet .Name {
427444 case servicetypes .DefaultVMSubnetSet :
@@ -430,6 +447,8 @@ func TestCreateDefaultSubnetSet(t *testing.T) {
430447 assert .Equal (t , v1alpha1 .AccessMode (v1alpha1 .AccessModeProject ), subnetSet .Spec .AccessMode )
431448 }
432449 assert .Equal (t , tt .defaultSubnetSize , subnetSet .Spec .IPv4SubnetSize )
450+ assert .Equal (t , wantIPv6 , subnetSet .Spec .IPv6PrefixLength )
451+ assert .Equal (t , tt .expectedIPAddressType , subnetSet .Spec .IPAddressType )
433452 }
434453 }
435454 }
0 commit comments