@@ -2332,12 +2332,29 @@ func TestNodePortServicesIngressRules(t *testing.T) {
2332
2332
2333
2333
testCases := []struct {
2334
2334
name string
2335
- cidrBlocks [] string
2335
+ awsCluster * infrav1. AWSCluster
2336
2336
expectedIngresRules infrav1.IngressRules
2337
2337
}{
2338
2338
{
2339
- name : "default node ports services ingress rules, no node port cidr block provided" ,
2340
- cidrBlocks : nil ,
2339
+ name : "default node ports services ingress rules, no node port cidr block provided" ,
2340
+ awsCluster : & infrav1.AWSCluster {
2341
+ Spec : infrav1.AWSClusterSpec {
2342
+ ControlPlaneLoadBalancer : & infrav1.AWSLoadBalancerSpec {},
2343
+ NetworkSpec : infrav1.NetworkSpec {
2344
+ VPC : infrav1.VPCSpec {
2345
+ CidrBlock : "10.0.0.0/16" ,
2346
+ },
2347
+ },
2348
+ },
2349
+ Status : infrav1.AWSClusterStatus {
2350
+ Network : infrav1.NetworkStatus {
2351
+ SecurityGroups : map [infrav1.SecurityGroupRole ]infrav1.SecurityGroup {
2352
+ infrav1 .SecurityGroupControlPlane : {ID : "Id1" },
2353
+ infrav1 .SecurityGroupNode : {ID : "Id2" },
2354
+ },
2355
+ },
2356
+ },
2357
+ },
2341
2358
expectedIngresRules : infrav1.IngressRules {
2342
2359
{
2343
2360
Description : "Node Port Services" ,
@@ -2356,8 +2373,65 @@ func TestNodePortServicesIngressRules(t *testing.T) {
2356
2373
},
2357
2374
},
2358
2375
{
2359
- name : "node port cidr block provided, no default cidr block used for node port services ingress rule" ,
2360
- cidrBlocks : []string {"10.0.0.0/16" },
2376
+ name : "default node ports services ingress rules for IPv6, no node port cidr block provided" ,
2377
+ awsCluster : & infrav1.AWSCluster {
2378
+ Spec : infrav1.AWSClusterSpec {
2379
+ ControlPlaneLoadBalancer : & infrav1.AWSLoadBalancerSpec {},
2380
+ NetworkSpec : infrav1.NetworkSpec {
2381
+ VPC : infrav1.VPCSpec {
2382
+ CidrBlock : "10.0.0.0/16" ,
2383
+ IPv6 : & infrav1.IPv6 {},
2384
+ },
2385
+ },
2386
+ },
2387
+ Status : infrav1.AWSClusterStatus {
2388
+ Network : infrav1.NetworkStatus {
2389
+ SecurityGroups : map [infrav1.SecurityGroupRole ]infrav1.SecurityGroup {
2390
+ infrav1 .SecurityGroupControlPlane : {ID : "Id1" },
2391
+ infrav1 .SecurityGroupNode : {ID : "Id2" },
2392
+ },
2393
+ },
2394
+ },
2395
+ },
2396
+ expectedIngresRules : infrav1.IngressRules {
2397
+ {
2398
+ Description : "Node Port Services" ,
2399
+ Protocol : infrav1 .SecurityGroupProtocolTCP ,
2400
+ FromPort : 30000 ,
2401
+ ToPort : 32767 ,
2402
+ CidrBlocks : []string {services .AnyIPv4CidrBlock },
2403
+ IPv6CidrBlocks : []string {services .AnyIPv6CidrBlock },
2404
+ },
2405
+ {
2406
+ Description : "Kubelet API" ,
2407
+ Protocol : infrav1 .SecurityGroupProtocolTCP ,
2408
+ FromPort : 10250 ,
2409
+ ToPort : 10250 ,
2410
+ SourceSecurityGroupIDs : []string {"Id1" , "Id2" },
2411
+ },
2412
+ },
2413
+ },
2414
+ {
2415
+ name : "node port cidr block provided, no default cidr block used for node port services ingress rule" ,
2416
+ awsCluster : & infrav1.AWSCluster {
2417
+ Spec : infrav1.AWSClusterSpec {
2418
+ ControlPlaneLoadBalancer : & infrav1.AWSLoadBalancerSpec {},
2419
+ NetworkSpec : infrav1.NetworkSpec {
2420
+ VPC : infrav1.VPCSpec {
2421
+ CidrBlock : "10.0.0.0/16" ,
2422
+ },
2423
+ NodePortIngressRuleCidrBlocks : []string {"10.0.0.0/16" },
2424
+ },
2425
+ },
2426
+ Status : infrav1.AWSClusterStatus {
2427
+ Network : infrav1.NetworkStatus {
2428
+ SecurityGroups : map [infrav1.SecurityGroupRole ]infrav1.SecurityGroup {
2429
+ infrav1 .SecurityGroupControlPlane : {ID : "Id1" },
2430
+ infrav1 .SecurityGroupNode : {ID : "Id2" },
2431
+ },
2432
+ },
2433
+ },
2434
+ },
2361
2435
expectedIngresRules : infrav1.IngressRules {
2362
2436
{
2363
2437
Description : "Node Port Services" ,
@@ -2375,6 +2449,90 @@ func TestNodePortServicesIngressRules(t *testing.T) {
2375
2449
},
2376
2450
},
2377
2451
},
2452
+ {
2453
+ name : "node port cidr block provided for only IPv6, no default cidr block used for node port services ingress rule" ,
2454
+ awsCluster : & infrav1.AWSCluster {
2455
+ Spec : infrav1.AWSClusterSpec {
2456
+ ControlPlaneLoadBalancer : & infrav1.AWSLoadBalancerSpec {},
2457
+ NetworkSpec : infrav1.NetworkSpec {
2458
+ VPC : infrav1.VPCSpec {
2459
+ CidrBlock : "10.0.0.0/16" ,
2460
+ IPv6 : & infrav1.IPv6 {
2461
+ CidrBlock : "2001:1234:5678:9a40::/56" ,
2462
+ },
2463
+ },
2464
+ NodePortIngressRuleCidrBlocks : []string {"2001:1234:5678:9a40::/56" },
2465
+ },
2466
+ },
2467
+ Status : infrav1.AWSClusterStatus {
2468
+ Network : infrav1.NetworkStatus {
2469
+ SecurityGroups : map [infrav1.SecurityGroupRole ]infrav1.SecurityGroup {
2470
+ infrav1 .SecurityGroupControlPlane : {ID : "Id1" },
2471
+ infrav1 .SecurityGroupNode : {ID : "Id2" },
2472
+ },
2473
+ },
2474
+ },
2475
+ },
2476
+ expectedIngresRules : infrav1.IngressRules {
2477
+ {
2478
+ Description : "Node Port Services" ,
2479
+ Protocol : infrav1 .SecurityGroupProtocolTCP ,
2480
+ FromPort : 30000 ,
2481
+ ToPort : 32767 ,
2482
+ CidrBlocks : []string {services .AnyIPv4CidrBlock },
2483
+ IPv6CidrBlocks : []string {"2001:1234:5678:9a40::/56" },
2484
+ },
2485
+ {
2486
+ Description : "Kubelet API" ,
2487
+ Protocol : infrav1 .SecurityGroupProtocolTCP ,
2488
+ FromPort : 10250 ,
2489
+ ToPort : 10250 ,
2490
+ SourceSecurityGroupIDs : []string {"Id1" , "Id2" },
2491
+ },
2492
+ },
2493
+ },
2494
+ {
2495
+ name : "node port cidr block provided for both IPv4 and IPv6, no default cidr block used for node port services ingress rule" ,
2496
+ awsCluster : & infrav1.AWSCluster {
2497
+ Spec : infrav1.AWSClusterSpec {
2498
+ ControlPlaneLoadBalancer : & infrav1.AWSLoadBalancerSpec {},
2499
+ NetworkSpec : infrav1.NetworkSpec {
2500
+ VPC : infrav1.VPCSpec {
2501
+ CidrBlock : "10.0.0.0/16" ,
2502
+ IPv6 : & infrav1.IPv6 {
2503
+ CidrBlock : "2001:1234:5678:9a40::/56" ,
2504
+ },
2505
+ },
2506
+ NodePortIngressRuleCidrBlocks : []string {"10.0.0.0/16" , "2001:1234:5678:9a40::/56" },
2507
+ },
2508
+ },
2509
+ Status : infrav1.AWSClusterStatus {
2510
+ Network : infrav1.NetworkStatus {
2511
+ SecurityGroups : map [infrav1.SecurityGroupRole ]infrav1.SecurityGroup {
2512
+ infrav1 .SecurityGroupControlPlane : {ID : "Id1" },
2513
+ infrav1 .SecurityGroupNode : {ID : "Id2" },
2514
+ },
2515
+ },
2516
+ },
2517
+ },
2518
+ expectedIngresRules : infrav1.IngressRules {
2519
+ {
2520
+ Description : "Node Port Services" ,
2521
+ Protocol : infrav1 .SecurityGroupProtocolTCP ,
2522
+ FromPort : 30000 ,
2523
+ ToPort : 32767 ,
2524
+ CidrBlocks : []string {"10.0.0.0/16" },
2525
+ IPv6CidrBlocks : []string {"2001:1234:5678:9a40::/56" },
2526
+ },
2527
+ {
2528
+ Description : "Kubelet API" ,
2529
+ Protocol : infrav1 .SecurityGroupProtocolTCP ,
2530
+ FromPort : 10250 ,
2531
+ ToPort : 10250 ,
2532
+ SourceSecurityGroupIDs : []string {"Id1" , "Id2" },
2533
+ },
2534
+ },
2535
+ },
2378
2536
}
2379
2537
2380
2538
for _ , tc := range testCases {
@@ -2384,25 +2542,7 @@ func TestNodePortServicesIngressRules(t *testing.T) {
2384
2542
Cluster : & clusterv1.Cluster {
2385
2543
ObjectMeta : metav1.ObjectMeta {Name : "test-cluster" },
2386
2544
},
2387
- AWSCluster : & infrav1.AWSCluster {
2388
- Spec : infrav1.AWSClusterSpec {
2389
- ControlPlaneLoadBalancer : & infrav1.AWSLoadBalancerSpec {},
2390
- NetworkSpec : infrav1.NetworkSpec {
2391
- VPC : infrav1.VPCSpec {
2392
- CidrBlock : "10.0.0.0/16" ,
2393
- },
2394
- NodePortIngressRuleCidrBlocks : tc .cidrBlocks ,
2395
- },
2396
- },
2397
- Status : infrav1.AWSClusterStatus {
2398
- Network : infrav1.NetworkStatus {
2399
- SecurityGroups : map [infrav1.SecurityGroupRole ]infrav1.SecurityGroup {
2400
- infrav1 .SecurityGroupControlPlane : {ID : "Id1" },
2401
- infrav1 .SecurityGroupNode : {ID : "Id2" },
2402
- },
2403
- },
2404
- },
2405
- },
2545
+ AWSCluster : tc .awsCluster ,
2406
2546
})
2407
2547
if err != nil {
2408
2548
t .Fatalf ("Failed to create test context: %v" , err )
0 commit comments