@@ -2344,12 +2344,16 @@ func TestNodePortServicesIngressRules(t *testing.T) {
23442344
23452345 testCases := []struct {
23462346 name string
2347- cidrBlocks [] string
2347+ networkSpec infrav1. NetworkSpec
23482348 expectedIngresRules infrav1.IngressRules
23492349 }{
23502350 {
2351- name : "default node ports services ingress rules, no node port cidr block provided" ,
2352- cidrBlocks : nil ,
2351+ name : "default node ports services ingress rules, no node port cidr block provided" ,
2352+ networkSpec : infrav1.NetworkSpec {
2353+ VPC : infrav1.VPCSpec {
2354+ CidrBlock : "10.0.0.0/16" ,
2355+ },
2356+ },
23532357 expectedIngresRules : infrav1.IngressRules {
23542358 {
23552359 Description : "Node Port Services" ,
@@ -2368,8 +2372,39 @@ func TestNodePortServicesIngressRules(t *testing.T) {
23682372 },
23692373 },
23702374 {
2371- name : "node port cidr block provided, no default cidr block used for node port services ingress rule" ,
2372- cidrBlocks : []string {"10.0.0.0/16" },
2375+ name : "default node ports services ingress rules for IPv6, no node port cidr block provided" ,
2376+ networkSpec : infrav1.NetworkSpec {
2377+ VPC : infrav1.VPCSpec {
2378+ CidrBlock : "10.0.0.0/16" ,
2379+ IPv6 : & infrav1.IPv6 {},
2380+ },
2381+ },
2382+ expectedIngresRules : infrav1.IngressRules {
2383+ {
2384+ Description : "Node Port Services" ,
2385+ Protocol : infrav1 .SecurityGroupProtocolTCP ,
2386+ FromPort : 30000 ,
2387+ ToPort : 32767 ,
2388+ CidrBlocks : []string {services .AnyIPv4CidrBlock },
2389+ IPv6CidrBlocks : []string {services .AnyIPv6CidrBlock },
2390+ },
2391+ {
2392+ Description : "Kubelet API" ,
2393+ Protocol : infrav1 .SecurityGroupProtocolTCP ,
2394+ FromPort : 10250 ,
2395+ ToPort : 10250 ,
2396+ SourceSecurityGroupIDs : []string {"Id1" , "Id2" },
2397+ },
2398+ },
2399+ },
2400+ {
2401+ name : "node port cidr block provided, no default cidr block used for node port services ingress rule" ,
2402+ networkSpec : infrav1.NetworkSpec {
2403+ VPC : infrav1.VPCSpec {
2404+ CidrBlock : "10.0.0.0/16" ,
2405+ },
2406+ NodePortIngressRuleCidrBlocks : []string {"10.0.0.0/16" },
2407+ },
23732408 expectedIngresRules : infrav1.IngressRules {
23742409 {
23752410 Description : "Node Port Services" ,
@@ -2387,6 +2422,64 @@ func TestNodePortServicesIngressRules(t *testing.T) {
23872422 },
23882423 },
23892424 },
2425+ {
2426+ name : "node port cidr block provided for only IPv6, no default cidr block used for node port services ingress rule" ,
2427+ networkSpec : infrav1.NetworkSpec {
2428+ VPC : infrav1.VPCSpec {
2429+ CidrBlock : "10.0.0.0/16" ,
2430+ IPv6 : & infrav1.IPv6 {
2431+ CidrBlock : "2001:1234:5678:9a40::/56" ,
2432+ },
2433+ },
2434+ NodePortIngressRuleCidrBlocks : []string {"2001:1234:5678:9a40::/56" },
2435+ },
2436+ expectedIngresRules : infrav1.IngressRules {
2437+ {
2438+ Description : "Node Port Services" ,
2439+ Protocol : infrav1 .SecurityGroupProtocolTCP ,
2440+ FromPort : 30000 ,
2441+ ToPort : 32767 ,
2442+ CidrBlocks : []string {services .AnyIPv4CidrBlock },
2443+ IPv6CidrBlocks : []string {"2001:1234:5678:9a40::/56" },
2444+ },
2445+ {
2446+ Description : "Kubelet API" ,
2447+ Protocol : infrav1 .SecurityGroupProtocolTCP ,
2448+ FromPort : 10250 ,
2449+ ToPort : 10250 ,
2450+ SourceSecurityGroupIDs : []string {"Id1" , "Id2" },
2451+ },
2452+ },
2453+ },
2454+ {
2455+ name : "node port cidr block provided for both IPv4 and IPv6, no default cidr block used for node port services ingress rule" ,
2456+ networkSpec : infrav1.NetworkSpec {
2457+ VPC : infrav1.VPCSpec {
2458+ CidrBlock : "10.0.0.0/16" ,
2459+ IPv6 : & infrav1.IPv6 {
2460+ CidrBlock : "2001:1234:5678:9a40::/56" ,
2461+ },
2462+ },
2463+ NodePortIngressRuleCidrBlocks : []string {"10.0.0.0/16" , "2001:1234:5678:9a40::/56" },
2464+ },
2465+ expectedIngresRules : infrav1.IngressRules {
2466+ {
2467+ Description : "Node Port Services" ,
2468+ Protocol : infrav1 .SecurityGroupProtocolTCP ,
2469+ FromPort : 30000 ,
2470+ ToPort : 32767 ,
2471+ CidrBlocks : []string {"10.0.0.0/16" },
2472+ IPv6CidrBlocks : []string {"2001:1234:5678:9a40::/56" },
2473+ },
2474+ {
2475+ Description : "Kubelet API" ,
2476+ Protocol : infrav1 .SecurityGroupProtocolTCP ,
2477+ FromPort : 10250 ,
2478+ ToPort : 10250 ,
2479+ SourceSecurityGroupIDs : []string {"Id1" , "Id2" },
2480+ },
2481+ },
2482+ },
23902483 }
23912484
23922485 for _ , tc := range testCases {
@@ -2399,12 +2492,7 @@ func TestNodePortServicesIngressRules(t *testing.T) {
23992492 AWSCluster : & infrav1.AWSCluster {
24002493 Spec : infrav1.AWSClusterSpec {
24012494 ControlPlaneLoadBalancer : & infrav1.AWSLoadBalancerSpec {},
2402- NetworkSpec : infrav1.NetworkSpec {
2403- VPC : infrav1.VPCSpec {
2404- CidrBlock : "10.0.0.0/16" ,
2405- },
2406- NodePortIngressRuleCidrBlocks : tc .cidrBlocks ,
2407- },
2495+ NetworkSpec : tc .networkSpec ,
24082496 },
24092497 Status : infrav1.AWSClusterStatus {
24102498 Network : infrav1.NetworkStatus {
0 commit comments